Skip to content

Commit

Permalink
Rename the ToolchainProvider to a more accurate name (and free up the…
Browse files Browse the repository at this point in the history
… name for the new ToolchainProvider).

Change-Id: I3537e1ed924c598707759c4a7040d5ba00de559c

PiperOrigin-RevId: 151853764
  • Loading branch information
katre authored and hlopko committed Apr 3, 2017
1 parent ba03c11 commit be5f25c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -40,8 +38,8 @@ public static ImmutableMap<String, String> getToolchainMakeVariables(
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -292,8 +292,10 @@ protected static class CommandResolverContext extends ConfigurationMakeVariableC

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,9 +85,10 @@ public RuleClass build(
//<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
Expand All @@ -104,12 +105,13 @@ public RuleClass build(
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.
Expand Down Expand Up @@ -179,8 +181,11 @@ are always generated into a predictable location (available via <code>$(@D)</cod
</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>
Expand Down Expand Up @@ -224,29 +229,31 @@ are always generated into a predictable location (available via <code>$(@D)</cod
</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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ToolchainTypeTest extends BuildViewTestCase {
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");
}
}

0 comments on commit be5f25c

Please sign in to comment.