Skip to content

Commit

Permalink
Add --incompatible_remove_exec_tools to control whether genrule has…
Browse files Browse the repository at this point in the history
… an `exec_tools` attribute.

Part of #19132.

PiperOrigin-RevId: 552496824
Change-Id: I2a09c390da89a44506afae55319aa393ed292c62
  • Loading branch information
katre authored and copybara-github committed Jul 31, 2023
1 parent ff83807 commit dd6393a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ public static class Options extends FragmentOptions {
help = "If enabled, visibility checking also applies to toolchain implementations.")
public boolean checkVisibilityForToolchains;

@Option(
name = "incompatible_remove_exec_tools",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help = "If enabled, use of genrule's exec_tools attribute will cause an error..")
public boolean removeExecTools;

@Override
public FragmentOptions getExec() {
Options exec = (Options) getDefault();
exec.checkVisibilityForToolchains = checkVisibilityForToolchains;
exec.removeExecTools = removeExecTools;

return exec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/bazel:bazel_configuration",
"//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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.devtools.build.lib.analysis.CommandHelper;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.bazel.BazelConfiguration;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.genrule.GenRuleBase;

Expand All @@ -36,9 +38,18 @@ protected boolean isStampingEnabled(RuleContext ruleContext) {
// projects are migrated.
@Override
protected CommandHelper.Builder commandHelperBuilder(RuleContext ruleContext) {
BazelConfiguration.Options bazelOptions =
ruleContext.getConfiguration().getOptions().get(BazelConfiguration.Options.class);

if (bazelOptions.removeExecTools
&& ruleContext.attributes().has("exec_tools", BuildType.LABEL_LIST)
&& !ruleContext.attributes().get("exec_tools", BuildType.LABEL_LIST).isEmpty()) {
ruleContext.attributeError(
"exec_tools", "genrule.exec_tools has been removed, use tools instead");
}

return CommandHelper.builder(ruleContext)
.addToolDependencies("tools")
// TODO(https://github.com/bazelbuild/bazel/issues/19132): Add an actual incompatible flag.
.addToolDependencies("exec_tools")
.addToolDependencies("toolchains");
}
Expand Down

0 comments on commit dd6393a

Please sign in to comment.