aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/genrule
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/genrule
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/genrule')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
index 5f0432ac4a..f35627b6eb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.MakeVariableExpander.ExpansionException;
+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;
@@ -40,6 +41,7 @@ import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.rules.AliasProvider;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier;
import com.google.devtools.build.lib.rules.cpp.CcToolchain;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.java.JavaHelper;
@@ -56,7 +58,7 @@ import java.util.regex.Pattern;
public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
private static final Pattern CROSSTOOL_MAKE_VARIABLE =
- Pattern.compile("\\$\\((CC|AR|NM|OBJCOPY|STRIP|GCOVTOOL|CC_FLAGS)\\)");
+ Pattern.compile("\\$\\((CC|CC_FLAGS|AR|NM|OBJCOPY|STRIP|GCOVTOOL)\\)");
private static final Pattern JDK_MAKE_VARIABLE =
Pattern.compile("\\$\\((JAVABASE|JAVA)\\)");
@@ -278,7 +280,11 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
*/
protected CommandResolverContext createCommandResolverContext(RuleContext ruleContext,
NestedSet<Artifact> resolvedSrcs, NestedSet<Artifact> filesToBuild) {
- return new CommandResolverContext(ruleContext, resolvedSrcs, filesToBuild);
+ return new CommandResolverContext(
+ ruleContext,
+ resolvedSrcs,
+ filesToBuild,
+ ImmutableList.of(new CcFlagsSupplier(ruleContext)));
}
/**
@@ -297,11 +303,13 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
public CommandResolverContext(
RuleContext ruleContext,
NestedSet<Artifact> resolvedSrcs,
- NestedSet<Artifact> filesToBuild) {
+ NestedSet<Artifact> filesToBuild,
+ Iterable<? extends MakeVariableSupplier> makeVariableSuppliers) {
super(
ruleContext.getMakeVariables(makeVariableAttributes),
ruleContext.getRule().getPackage(),
- ruleContext.getConfiguration());
+ ruleContext.getConfiguration(),
+ makeVariableSuppliers);
this.ruleContext = ruleContext;
this.resolvedSrcs = resolvedSrcs;
this.filesToBuild = filesToBuild;
@@ -312,16 +320,16 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
}
@Override
- public String lookupMakeVariable(String name) throws ExpansionException {
- if (name.equals("SRCS")) {
+ public String lookupMakeVariable(String variableName) throws ExpansionException {
+ if (variableName.equals("SRCS")) {
return Artifact.joinExecPaths(" ", resolvedSrcs);
- } else if (name.equals("<")) {
+ } else if (variableName.equals("<")) {
return expandSingletonArtifact(resolvedSrcs, "$<", "input file");
- } else if (name.equals("OUTS")) {
+ } else if (variableName.equals("OUTS")) {
return Artifact.joinExecPaths(" ", filesToBuild);
- } else if (name.equals("@")) {
+ } else if (variableName.equals("@")) {
return expandSingletonArtifact(filesToBuild, "$@", "output file");
- } else if (name.equals("@D")) {
+ } else if (variableName.equals("@D")) {
// The output directory. If there is only one filename in outs,
// this expands to the directory containing that file. If there are
// multiple filenames, this variable instead expands to the
@@ -348,14 +356,14 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
ruleContext.getRule().getLabel().getPackageIdentifier().getSourceRoot();
return dir.getRelative(relPath).getPathString();
}
- } else if (JDK_MAKE_VARIABLE.matcher("$(" + name + ")").find()) {
+ } else if (JDK_MAKE_VARIABLE.matcher("$(" + variableName + ")").find()) {
return new ConfigurationMakeVariableContext(
ruleContext.getMakeVariables(makeVariableAttributes),
ruleContext.getTarget().getPackage(),
ruleContext.getHostConfiguration())
- .lookupMakeVariable(name);
+ .lookupMakeVariable(variableName);
} else {
- return super.lookupMakeVariable(name);
+ return super.lookupMakeVariable(variableName);
}
}