Skip to content

Commit

Permalink
Make genrule.exec_tools only exist in Bazel.
Browse files Browse the repository at this point in the history
This is a step towards removing it entirely, see #19132.

Next step is to add an actual incompatible flag if possible.

RELNOTES: The `genrule` attribute `exec_tools` will be removed in a future Bazel release. Please follow directions at #19132 to migrate away from it.
PiperOrigin-RevId: 552469827
Change-Id: Ica480e1113a1b8aeae31ad0713c41660416248b6
  • Loading branch information
katre authored and copybara-github committed Jul 31, 2023
1 parent cbbe54b commit 425e2d7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/rules/genrule",
"//src/main/java/com/google/devtools/build/lib/util:filetype",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.build.lib.bazel.rules.genrule;

import com.google.devtools.build.lib.analysis.CommandHelper;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.genrule.GenRuleBase;
Expand All @@ -30,4 +31,15 @@ protected boolean isStampingEnabled(RuleContext ruleContext) {
}
return ruleContext.attributes().get("stamp", Type.BOOLEAN);
}

// TODO(https://github.com/bazelbuild/bazel/issues/19132): Remove this override once downstream
// projects are migrated.
@Override
protected CommandHelper.Builder commandHelperBuilder(RuleContext ruleContext) {
return CommandHelper.builder(ruleContext)
.addToolDependencies("tools")
// TODO(https://github.com/bazelbuild/bazel/issues/19132): Add an actual incompatible flag.
.addToolDependencies("exec_tools")
.addToolDependencies("toolchains");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.Type.BOOLEAN;

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.packages.RuleClass;
import com.google.devtools.build.lib.rules.genrule.GenRuleBaseRule;
import com.google.devtools.build.lib.util.FileTypeSet;

/**
* Rule definition for genrule for Bazel.
Expand All @@ -44,6 +46,23 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.cfg(ExecutionTransitionFactory.createFactory())
.value(env.getToolsLabel(GENRULE_SETUP_LABEL)))

// TODO(https://github.com/bazelbuild/bazel/issues/19132): Remove this once downstream
// projects are migrated.
/* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(exec_tools) -->
<b>Deprecated. Use <a href="#genrule.tools"><code>tools</code></a> instead.</b>
<p>
There was a period of time when <code>exec_tools</code> and <code>tools</code> behaved
differently, but they are now equivalent and the Blaze team will be migrating all uses of
<code>exec_tools</code> to <code>tools</code>.
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("exec_tools", LABEL_LIST)
.cfg(ExecutionTransitionFactory.createFactory())
.allowedFileTypes(FileTypeSet.ANY_FILE)
.dontCheckConstraints())

// TODO(bazel-team): stamping doesn't seem to work. Fix it or remove attribute.
.add(attr("stamp", BOOLEAN).value(false))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ public String toString() {
protected CommandHelper.Builder commandHelperBuilder(RuleContext ruleContext) {
return CommandHelper.builder(ruleContext)
.addToolDependencies("tools")
.addToolDependencies("exec_tools")
.addToolDependencies("toolchains");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,6 @@ public RuleClass build(
.cfg(ExecutionTransitionFactory.createFactory())
.allowedFileTypes(FileTypeSet.ANY_FILE))

/* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(exec_tools) -->
<b>Deprecated. Use <a href="#genrule.tools"><code>tools</code></a> instead.</b>
<p>
There was a period of time when <code>exec_tools</code> and <code>tools</code> behaved
differently, but they are now equivalent and the Blaze team will be migrating all uses of
<code>exec_tools</code> to <code>tools</code>.
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("exec_tools", LABEL_LIST)
.cfg(ExecutionTransitionFactory.createFactory())
.allowedFileTypes(FileTypeSet.ANY_FILE)
.dontCheckConstraints())

/* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(outs) -->
A list of files generated by this rule.
<p>
Expand Down

0 comments on commit 425e2d7

Please sign in to comment.