Rename the ToolchainProvider to a more accurate name (and free up the name for the new ToolchainProvider). Change-Id: I3537e1ed924c598707759c4a7040d5ba00de559c PiperOrigin-RevId: 151853764
diff --git a/src/main/java/com/google/devtools/build/lib/rules/ToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/MakeVariableProvider.java similarity index 84% rename from src/main/java/com/google/devtools/build/lib/rules/ToolchainProvider.java rename to src/main/java/com/google/devtools/build/lib/rules/MakeVariableProvider.java index e25ee2b..1c56c20 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/ToolchainProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/MakeVariableProvider.java
@@ -21,14 +21,12 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import java.util.TreeMap; -/** - * A toolchain, determined from the current platform. - */ +/** Provides access to make variables from the current fragments. */ @Immutable -public final class ToolchainProvider implements TransitiveInfoProvider { +public final class MakeVariableProvider implements TransitiveInfoProvider { private final ImmutableMap<String, String> makeVariables; - public ToolchainProvider(ImmutableMap<String, String> makeVariables) { + public MakeVariableProvider(ImmutableMap<String, String> makeVariables) { this.makeVariables = makeVariables; } @@ -40,8 +38,8 @@ RuleContext ruleContext, String attributeName) { // Cannot be an ImmutableMap.Builder because we want to support duplicate keys TreeMap<String, String> result = new TreeMap<>(); - for (ToolchainProvider provider : - ruleContext.getPrerequisites(attributeName, Mode.TARGET, ToolchainProvider.class)) { + for (MakeVariableProvider provider : + ruleContext.getPrerequisites(attributeName, Mode.TARGET, MakeVariableProvider.class)) { result.putAll(provider.getMakeVariables()); }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/ToolchainType.java b/src/main/java/com/google/devtools/build/lib/rules/ToolchainType.java index a752db0..fbb1b4b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/ToolchainType.java +++ b/src/main/java/com/google/devtools/build/lib/rules/ToolchainType.java
@@ -61,7 +61,7 @@ // out the lookup rule -> toolchain rule mapping. For now, it only provides Make variables that // come from BuildConfiguration so no need to ask Skyframe. return new RuleConfiguredTargetBuilder(ruleContext) - .addProvider(new ToolchainProvider(ImmutableMap.copyOf(makeVariables))) + .addProvider(new MakeVariableProvider(ImmutableMap.copyOf(makeVariables))) .addProvider(RunfilesProvider.simple(Runfiles.EMPTY)) .build(); }
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 8a2983b..407a45c 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
@@ -39,8 +39,8 @@ 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.MakeVariableProvider; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.rules.ToolchainProvider; import com.google.devtools.build.lib.rules.cpp.CppHelper; import com.google.devtools.build.lib.rules.java.JavaHelper; import com.google.devtools.build.lib.syntax.Type; @@ -292,8 +292,10 @@ public CommandResolverContext(RuleContext ruleContext, NestedSet<Artifact> resolvedSrcs, NestedSet<Artifact> filesToBuild) { - super(ruleContext.getRule().getPackage(), ruleContext.getConfiguration(), - ToolchainProvider.getToolchainMakeVariables(ruleContext, "toolchains")); + super( + ruleContext.getRule().getPackage(), + ruleContext.getConfiguration(), + MakeVariableProvider.getToolchainMakeVariables(ruleContext, "toolchains")); this.ruleContext = ruleContext; this.resolvedSrcs = resolvedSrcs; this.filesToBuild = filesToBuild;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java index 59d1c59..544a03d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java
@@ -34,7 +34,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; -import com.google.devtools.build.lib.rules.ToolchainProvider; +import com.google.devtools.build.lib.rules.MakeVariableProvider; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import com.google.devtools.build.lib.rules.cpp.CppRuleClasses; import com.google.devtools.build.lib.syntax.Type; @@ -85,9 +85,10 @@ //<code>srcs</code>. </p> <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("srcs", LABEL_LIST) - .direct_compile_time_input() - .allowedFileTypes(FileTypeSet.ANY_FILE)) + .add( + attr("srcs", LABEL_LIST) + .direct_compile_time_input() + .allowedFileTypes(FileTypeSet.ANY_FILE)) /* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(tools) --> A list of <i>tool</i> dependencies for this rule. See the definition of @@ -104,12 +105,13 @@ list, not in <code>srcs</code>, to ensure they are built in the correct configuration. </p> <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("tools", LABEL_LIST).cfg(HOST) - .allowedFileTypes(FileTypeSet.ANY_FILE)) - .add(attr("toolchains", LABEL_LIST) - .allowedFileTypes(FileTypeSet.NO_FILE) - .mandatoryNativeProviders(ImmutableList.<Class<? extends TransitiveInfoProvider>>of( - ToolchainProvider.class))) + .add(attr("tools", LABEL_LIST).cfg(HOST).allowedFileTypes(FileTypeSet.ANY_FILE)) + .add( + attr("toolchains", LABEL_LIST) + .allowedFileTypes(FileTypeSet.NO_FILE) + .mandatoryNativeProviders( + ImmutableList.<Class<? extends TransitiveInfoProvider>>of( + MakeVariableProvider.class))) /* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(outs) --> A list of files generated by this rule. @@ -179,8 +181,11 @@ </p> <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ // TODO(bazel-team): find a location to document genfiles/binfiles, link to them from here. - .add(attr("output_to_bindir", BOOLEAN).value(false) - .nonconfigurable("policy decision: no reason for this to depend on the configuration")) + .add( + attr("output_to_bindir", BOOLEAN) + .value(false) + .nonconfigurable( + "policy decision: no reason for this to depend on the configuration")) /* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(local) --> <p> @@ -224,29 +229,31 @@ </p> <p>Declaring data dependencies for the generated executable is not supported.</p> <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("executable", BOOLEAN).value(false).nonconfigurable( - "Used in computed default for $is_executable, which is itself non-configurable (and " - + " thus expects its dependencies to be non-configurable), because $is_executable" - + " is called from RunCommand.isExecutable, which has no configuration context")) - - .add(attr("$is_executable", BOOLEAN) - .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target") - .value( - new Attribute.ComputedDefault() { - @Override - public Object getDefault(AttributeMap rule) { - return (rule.get("outs", BuildType.OUTPUT_LIST).size() == 1) - && rule.get("executable", BOOLEAN); - } - })) + .add( + attr("executable", BOOLEAN) + .value(false) + .nonconfigurable( + "Used in computed default for $is_executable, which is itself non-configurable" + + " (and thus expects its dependencies to be non-configurable), because" + + " $is_executable is called from RunCommand.isExecutable, which has no" + + " configuration context")) + .add( + attr("$is_executable", BOOLEAN) + .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target") + .value( + new Attribute.ComputedDefault() { + @Override + public Object getDefault(AttributeMap rule) { + return (rule.get("outs", BuildType.OUTPUT_LIST).size() == 1) + && rule.get("executable", BOOLEAN); + } + })) // This is a misfeature, so don't document it. We would like to get rid of it, but that // would require a cleanup of existing rules. .add(attr("heuristic_label_expansion", BOOLEAN).value(false)) - .removeAttribute("data") .removeAttribute("deps") - .build(); }
diff --git a/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java b/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java index ce939a8..e9cbf36 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java
@@ -27,7 +27,7 @@ public void testSmoke() throws Exception { ConfiguredTarget cc = getConfiguredTarget(getRuleClassProvider().getToolsRepository() + "//tools/cpp:toolchain_type"); - assertThat(cc.getProvider(ToolchainProvider.class).getMakeVariables()) + assertThat(cc.getProvider(MakeVariableProvider.class).getMakeVariables()) .containsKey("TARGET_CPU"); } }