aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java71
1 files changed, 2 insertions, 69 deletions
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