Skip to content

Commit

Permalink
Add an exec_tools attribute for genrule, which allows specifying tool…
Browse files Browse the repository at this point in the history
…s that should be configured with the execution transition, instead of the host transition.

Note that this attribute is for migration from host to execution configurations, and will eventually be deprecated and removed once that migration is complete.

PiperOrigin-RevId: 251867407
  • Loading branch information
katre authored and copybara-github committed Jun 6, 2019
1 parent 3f629eb commit d97392f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public String toString() {
protected CommandHelper.Builder commandHelperBuilder(RuleContext ruleContext) {
return CommandHelper.builder(ruleContext)
.addHostToolDependencies("tools")
.addToolDependencies("exec_tools")
.addHostToolDependencies("toolchains");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.HostTransition;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeMap;
Expand Down Expand Up @@ -84,6 +85,29 @@ public RuleClass build(
attr("tools", LABEL_LIST)
.cfg(HostTransition.createFactory())
.allowedFileTypes(FileTypeSet.ANY_FILE))

/* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(exec_tools) -->
A list of <i>tool</i> dependencies for this rule. This behaves exactly like the
<a href="#genrule.tools"><code>tools</code></a> attribute, except that these dependencies
will be configured for the rule's execution platform instead of the host configuration.
This means that dependencies in <code>exec_tools</code> are not subject to the same
limitations as dependencies in <code>tools</code>. In particular, they are not required to
use the host configuration for their own transitive dependencies. See
<a href="#genrule.tools"><code>tools</code></a> for further details.
<p>
Note that eventually the host configuration will be replaced by the execution
configuration. When that happens, this attribute will be deprecated in favor of
<code>tools</code>. Until then, this attribute allows users to selectively migrate
dependencies to the execution configuration.
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("exec_tools", LABEL_LIST)
.cfg(new ExecutionTransitionFactory())
.allowedFileTypes(FileTypeSet.ANY_FILE)
.dontCheckConstraints())

/* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(outs) -->
A list of files generated by this rule.
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,4 +614,24 @@ public void testDuplicateLocalFlags() throws Exception {
getConfiguredTarget("//foo:g");
assertNoEvents();
}

@Test
public void testExecToolsAreExecConfiguration() throws Exception {
scratch.file(
"config/BUILD",
"genrule(name='src', outs=['src.out'], cmd=':')",
"genrule(name='exec_tool', outs=['exec_tool.out'], cmd=':')",
"genrule(name='config', ",
" srcs=[':src'], exec_tools=[':exec_tool'], outs=['out'],",
" cmd='$(location :exec_tool)')");

ConfiguredTarget parentTarget = getConfiguredTarget("//config");

// Cannot use getDirectPrerequisites, as this re-configures that target incorrectly.
Artifact out = Iterables.getFirst(getFilesToBuild(parentTarget), null);
assertThat(getGeneratingAction(out).getTools()).hasSize(1);
Artifact execTool = getOnlyElement(getGeneratingAction(out).getTools());
// This is the output dir fragment for the execution transition.
assertThat(execTool.getExecPathString()).contains("-exec-");
}
}

0 comments on commit d97392f

Please sign in to comment.