aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java36
1 files changed, 14 insertions, 22 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 ecd7e71d34..dc1ff59a8a 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
@@ -141,17 +141,22 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
return null;
}
- String baseCommand = commandHelper.resolveCommandAndHeuristicallyExpandLabels(
- ruleContext.attributes().get("cmd", Type.STRING),
- "cmd",
- ruleContext.attributes().get("heuristic_label_expansion", Type.BOOLEAN));
+ String baseCommand = ruleContext.attributes().get("cmd", Type.STRING);
+ // Expand template variables and functions.
+ String command = ruleContext
+ .getExpander(new CommandResolverContext(ruleContext, resolvedSrcs, filesToBuild))
+ .withExecLocations(commandHelper.getLabelMap())
+ .expand("cmd", baseCommand);
- // Adds the genrule environment setup script before the actual shell command
- String command = String.format("source %s; %s",
- ruleContext.getPrerequisiteArtifact("$genrule_setup", Mode.HOST).getExecPath(),
- baseCommand);
+ // Heuristically expand things that look like labels.
+ if (ruleContext.attributes().get("heuristic_label_expansion", Type.BOOLEAN)) {
+ command = commandHelper.expandLabelsHeuristically(command);
+ }
- command = resolveCommand(command, ruleContext, resolvedSrcs, filesToBuild);
+ // Add the genrule environment setup script before the actual shell command.
+ command = String.format("source %s; %s",
+ ruleContext.getPrerequisiteArtifact("$genrule_setup", Mode.HOST).getExecPath(),
+ command);
String messageAttr = ruleContext.attributes().get("message", Type.STRING);
String message = messageAttr.isEmpty() ? "Executing genrule" : messageAttr;
@@ -249,19 +254,6 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
}
/**
- * Resolves any variables, including make and genrule-specific variables, in the command and
- * returns the expanded command.
- *
- * <p>GenRule implementations may override this method to perform additional expansions.
- */
- protected String resolveCommand(String command, final RuleContext ruleContext,
- final NestedSet<Artifact> resolvedSrcs, final NestedSet<Artifact> filesToBuild) {
- return ruleContext
- .getExpander(new CommandResolverContext(ruleContext, resolvedSrcs, filesToBuild))
- .expand("cmd", command);
- }
-
- /**
* Implementation of {@link ConfigurationMakeVariableContext} used to expand variables in a
* genrule command string.
*/