aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2017-05-26 11:37:28 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-05-26 13:25:58 +0200
commita47780541536764cf56d09f78a988d6155689c7f (patch)
tree3ec1afd6b557ac27a6bd827fcdcee51865fef69f /src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
parent1fd27bc4d97533031401c54aa05eb75b13c6874b (diff)
Use FeatureConfiguration to compute value of CC_FLAGS make variable
This cl introduces new action_config type for Crosstool named 'generic'. This can be used to set the value of CC_FLAGS make variable using much more expressive mechanism (action_configs + features) than previous make_variable Crosstool messages. This has been requested by the C++ LPT. However, as FeatureConfiguration needs RuleContext, CC_FLAGS cannot be computed using configuration only anymore. Also, FeatureConfiguration is C++ rules specific class, and Bazel build-base cannot depend on it. Therefore we cannot use FeatureConfiguration for ExtraActions, for example. Because it cannot be made perfect, this cl is not updating all the possible places that expand make variables but limits the scope to: * genrule (the only widely used rule that often expands make variables) * *_test (CC_FLAGS is used by Tensorflow in the 'args' attribute) * cc_rules (people sometimes set 'copts' to something like: "-DCC_STRING=\\\"$(CC)\\\" -DCC_FLAGS_STRING=\"$(CC_FLAGS)\"" The long term plan is to use Skylark C++ API to get C++ command lines, so CC_FLAGS together with this inconsistent solution will be removed. RELNOTES: CC_FLAGS can be defined using 'generic' action_config in CROSSTOOL PiperOrigin-RevId: 157202883
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.java19
1 files changed, 15 insertions, 4 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 96ba0a6892..f1952e897d 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
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.MiddlemanFactory;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.FileProvider;
+import com.google.devtools.build.lib.analysis.MakeVariableSupplier;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleContext;
@@ -37,6 +38,7 @@ 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;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
+import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Linkstamp;
import com.google.devtools.build.lib.rules.cpp.CppCompilationContext.Builder;
import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
@@ -136,17 +138,22 @@ public class CppHelper {
!ruleContext.getFeatures().contains("no_copts_tokenization");
List<String> tokens = new ArrayList<>();
+ ImmutableList<? extends MakeVariableSupplier> makeVariableSuppliers =
+ ImmutableList.of(new CcFlagsSupplier(ruleContext));
for (String token : input) {
try {
// Legacy behavior: tokenize all items.
if (tokenization) {
- ruleContext.tokenizeAndExpandMakeVars(tokens, attributeName, token);
+ ruleContext.tokenizeAndExpandMakeVars(
+ tokens, attributeName, token, makeVariableSuppliers);
} else {
- String exp = ruleContext.expandSingleMakeVariable(attributeName, token);
+ String exp =
+ ruleContext.expandSingleMakeVariable(attributeName, token, makeVariableSuppliers);
if (exp != null) {
ShellUtils.tokenize(tokens, exp);
} else {
- tokens.add(ruleContext.expandMakeVariables(attributeName, token));
+ tokens.add(
+ ruleContext.expandMakeVariables(attributeName, token, makeVariableSuppliers));
}
}
} catch (ShellUtils.TokenizationException e) {
@@ -178,7 +185,11 @@ public class CppHelper {
ruleContext.attributeError(attrName, "could not resolve label '" + attrValue + "'");
}
} else {
- ruleContext.tokenizeAndExpandMakeVars(values, attrName, attrValue);
+ ruleContext.tokenizeAndExpandMakeVars(
+ values,
+ attrName,
+ attrValue,
+ ImmutableList.of(new CcFlagsSupplier(ruleContext)));
}
}