aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar plf <plf@google.com>2018-07-20 05:46:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-20 05:47:58 -0700
commitbad2693b421bdeb60f988d258cb0edbd7082d25b (patch)
treeef3529d7b1b8f2c82824ba27dcd90ad5b5a41ae4 /src/main/java/com/google/devtools/build/lib/rules/cpp
parentcb7ed1693f4da77c85f0873adbac522deb9ea60f (diff)
C++: Removes logic for linkopts expansion.
RELNOTES[INC]:Labels in C++ rules' linkopts attribute are not expanded anymore unless they are wrapped, e.g: $(location //foo:bar) PiperOrigin-RevId: 205385711
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java71
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java9
3 files changed, 2 insertions, 82 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index 82a4ae7176..b809ed5d30 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -974,10 +974,6 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
return cppOptions.useInterfaceSharedObjects;
}
- public boolean getExpandLinkoptsLabels() {
- return cppOptions.expandLinkoptsLabels;
- }
-
public boolean getEnableCcSkylarkApi() {
return cppOptions.enableCcSkylarkApi;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index ce5eef15f5..eca2691bb8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -34,7 +34,6 @@ import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.Expander;
-import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleContext;
@@ -52,7 +51,6 @@ import com.google.devtools.build.lib.analysis.config.InvalidConfigurationExcepti
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
@@ -96,9 +94,6 @@ public class CppHelper {
CppFileTypes.CPP_HEADER,
CppFileTypes.CPP_SOURCE);
- private static final ImmutableList<String> LINKOPTS_PREREQUISITE_LABEL_KINDS =
- ImmutableList.of("deps", "srcs");
-
/** Base label of the c++ toolchain category. */
public static final String TOOLCHAIN_TYPE_LABEL = "//tools/cpp:toolchain_type";
@@ -189,28 +184,13 @@ public class CppHelper {
return ImmutableList.copyOf(expandMakeVariables(ruleContext, "copts", unexpanded));
}
- /**
- * Expands attribute value either using label expansion
- * (if attemptLabelExpansion == {@code true} and it does not look like make
- * variable or flag) or tokenizes and expands make variables.
- */
+ /** Tokenizes and expands make variables. */
public static List<String> expandLinkopts(
RuleContext ruleContext, String attrName, Iterable<String> values) {
List<String> result = new ArrayList<>();
Expander expander = ruleContext.getExpander().withDataExecLocations();
for (String value : values) {
- if (ruleContext.getFragment(CppConfiguration.class).getExpandLinkoptsLabels()
- && isLinkoptLabel(value)) {
- if (!expandLabel(ruleContext, result, value)) {
- ruleContext.attributeError(attrName, "could not resolve label '" + value + "'");
- }
- } else {
- expander
- .tokenizeAndExpandMakeVars(
- result,
- attrName,
- value);
- }
+ expander.tokenizeAndExpandMakeVars(result, attrName, value);
}
return result;
}
@@ -277,53 +257,6 @@ public class CppHelper {
}
/**
- * Determines if a linkopt can be a label. Linkopts come in 2 varieties:
- * literals -- flags like -Xl and makefile vars like $(LD) -- and labels,
- * which we should expand into filenames.
- *
- * @param linkopt the link option to test.
- * @return true if the linkopt is not a flag (starting with "-") or a makefile
- * variable (starting with "$");
- */
- private static boolean isLinkoptLabel(String linkopt) {
- return !linkopt.startsWith("$") && !linkopt.startsWith("-");
- }
-
- /**
- * Expands a label against the target's deps, adding the expanded path strings
- * to the linkopts.
- *
- * @param linkopts the linkopts to add the expanded label to
- * @param labelName the name of the label to expand
- * @return true if the label was expanded successfully, false otherwise
- */
- private static boolean expandLabel(
- RuleContext ruleContext, List<String> linkopts, String labelName) {
- try {
- Label label =
- ruleContext
- .getLabel()
- .getRelativeWithRemapping(
- labelName, ruleContext.getRule().getPackage().getRepositoryMapping());
- for (String prereqKind : LINKOPTS_PREREQUISITE_LABEL_KINDS) {
- for (TransitiveInfoCollection target : ruleContext
- .getPrerequisitesIf(prereqKind, Mode.TARGET, FileProvider.class)) {
- if (target.getLabel().equals(label)) {
- for (Artifact artifact : target.getProvider(FileProvider.class).getFilesToBuild()) {
- linkopts.add(artifact.getExecPathString());
- }
- return true;
- }
- }
- }
- } catch (LabelSyntaxException e) {
- // Quietly ignore and fall through.
- }
- linkopts.add(labelName);
- return false;
- }
-
- /**
* Return {@link FdoSupportProvider} using default cc_toolchain attribute name.
*
* <p>Be careful to provide explicit attribute name if the rule doesn't store cc_toolchain under
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
index b5616f0890..49a11a16f4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
@@ -773,15 +773,6 @@ public class CppOptions extends FragmentOptions {
public boolean useLLVMCoverageMapFormat;
@Option(
- name = "experimental_expand_linkopts_labels",
- defaultValue = "true",
- documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
- effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
- metadataTags = {OptionMetadataTag.EXPERIMENTAL},
- help = "If true, entries in linkopts that are not preceded by - or $ will be expanded.")
- public boolean expandLinkoptsLabels;
-
- @Option(
name = "incompatible_enable_legacy_cpp_toolchain_skylark_api",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,