aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar cpeyser <cpeyser@google.com>2017-09-11 16:58:58 +0200
committerGravatar Philipp Wollermann <philwo@google.com>2017-09-12 14:04:02 +0200
commitb38e3af9114ff91906cd1109fba9bddca86db185 (patch)
treeebc72ce1a8474dd3ba2b00271f70ce4728cd1876
parentb1d34be6d1aac24a91733d0b2d1a3202b1a564d4 (diff)
Toolchain providers are propagated in the ToolchainContext instance made
available from BuildViewTestCase#getRuleContext PiperOrigin-RevId: 168231020
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BuildView.java39
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java10
7 files changed, 55 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index d8007c1917..b797532931 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -1056,9 +1056,12 @@ public class BuildView {
throws EvalException, InvalidConfigurationException,
InterruptedException, InconsistentAspectOrderException {
return skyframeExecutor.getConfiguredTargets(
- eventHandler, ct.getConfiguration(),
+ eventHandler,
+ ct.getConfiguration(),
ImmutableSet.copyOf(
- getDirectPrerequisiteDependenciesForTesting(eventHandler, ct, configurations).values()),
+ getDirectPrerequisiteDependenciesForTesting(
+ eventHandler, ct, configurations, /*toolchainContext=*/ null)
+ .values()),
false);
}
@@ -1066,9 +1069,10 @@ public class BuildView {
public OrderedSetMultimap<Attribute, Dependency> getDirectPrerequisiteDependenciesForTesting(
final ExtendedEventHandler eventHandler,
final ConfiguredTarget ct,
- BuildConfigurationCollection configurations)
+ BuildConfigurationCollection configurations,
+ ToolchainContext toolchainContext)
throws EvalException, InvalidConfigurationException, InterruptedException,
- InconsistentAspectOrderException {
+ InconsistentAspectOrderException {
if (!(ct.getTarget() instanceof Rule)) {
return OrderedSetMultimap.create();
}
@@ -1128,8 +1132,11 @@ public class BuildView {
TargetAndConfiguration ctgNode =
new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
return dependencyResolver.dependentNodeMap(
- ctgNode, configurations.getHostConfiguration(), /*aspect=*/ null,
- getConfigurableAttributeKeysForTesting(eventHandler, ctgNode));
+ ctgNode,
+ configurations.getHostConfiguration(),
+ /*aspect=*/ null,
+ getConfigurableAttributeKeysForTesting(eventHandler, ctgNode),
+ toolchainContext);
}
/**
@@ -1160,11 +1167,13 @@ public class BuildView {
private OrderedSetMultimap<Attribute, ConfiguredTarget> getPrerequisiteMapForTesting(
final ExtendedEventHandler eventHandler,
ConfiguredTarget target,
- BuildConfigurationCollection configurations)
- throws EvalException, InvalidConfigurationException,
- InterruptedException, InconsistentAspectOrderException {
+ BuildConfigurationCollection configurations,
+ ToolchainContext toolchainContext)
+ throws EvalException, InvalidConfigurationException, InterruptedException,
+ InconsistentAspectOrderException {
OrderedSetMultimap<Attribute, Dependency> depNodeNames =
- getDirectPrerequisiteDependenciesForTesting(eventHandler, target, configurations);
+ getDirectPrerequisiteDependenciesForTesting(
+ eventHandler, target, configurations, toolchainContext);
ImmutableMultimap<Dependency, ConfiguredTarget> cts = skyframeExecutor.getConfiguredTargetMap(
eventHandler,
@@ -1258,6 +1267,9 @@ public class BuildView {
ToolchainContext toolchainContext =
skyframeExecutor.getToolchainContextForTesting(
requiredToolchains, targetConfig, eventHandler);
+ OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap =
+ getPrerequisiteMapForTesting(eventHandler, target, configurations, toolchainContext);
+ toolchainContext.resolveToolchains(prerequisiteMap);
return new RuleContext.Builder(
env,
@@ -1270,7 +1282,8 @@ public class BuildView {
.setVisibility(
NestedSetBuilder.<PackageSpecification>create(
Order.STABLE_ORDER, PackageSpecification.everything()))
- .setPrerequisites(getPrerequisiteMapForTesting(eventHandler, target, configurations))
+ .setPrerequisites(
+ getPrerequisiteMapForTesting(eventHandler, target, configurations, toolchainContext))
.setConfigConditions(ImmutableMap.<Label, ConfigMatchingProvider>of())
.setUniversalFragment(ruleClassProvider.getUniversalFragment())
.setToolchainContext(toolchainContext)
@@ -1290,7 +1303,9 @@ public class BuildView {
throws EvalException, InvalidConfigurationException, InterruptedException,
InconsistentAspectOrderException {
Collection<ConfiguredTarget> configuredTargets =
- getPrerequisiteMapForTesting(eventHandler, dependentTarget, configurations).values();
+ getPrerequisiteMapForTesting(
+ eventHandler, dependentTarget, configurations, /*toolchainContext=*/ null)
+ .values();
for (ConfiguredTarget ct : configuredTargets) {
if (ct.getLabel().equals(desiredTarget)) {
return ct;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
index e2380261a8..28ee44deac 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
@@ -91,13 +91,15 @@ public abstract class DependencyResolver {
* This is needed to support {@link LateBoundDefault#useHostConfiguration()}.
* @param aspect the aspect applied to this target (if any)
* @param configConditions resolver for config_setting labels
+ * @param toolchainContext {@link ToolchainContext} for this target
* @return a mapping of each attribute in this rule or aspects to its dependent nodes
*/
public final OrderedSetMultimap<Attribute, Dependency> dependentNodeMap(
TargetAndConfiguration node,
BuildConfiguration hostConfig,
@Nullable Aspect aspect,
- ImmutableMap<Label, ConfigMatchingProvider> configConditions)
+ ImmutableMap<Label, ConfigMatchingProvider> configConditions,
+ ToolchainContext toolchainContext)
throws EvalException, InvalidConfigurationException, InterruptedException,
InconsistentAspectOrderException {
NestedSetBuilder<Label> rootCauses = NestedSetBuilder.<Label>stableOrder();
@@ -107,7 +109,7 @@ public abstract class DependencyResolver {
hostConfig,
aspect != null ? ImmutableList.of(aspect) : ImmutableList.<Aspect>of(),
configConditions,
- /*toolchainContext=*/ null,
+ toolchainContext,
rootCauses);
if (!rootCauses.isEmpty()) {
throw new IllegalStateException(rootCauses.build().iterator().next().toString());
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
index 7327c53da7..1f33e86450 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
@@ -162,7 +162,7 @@ public class ToolchainContext {
}
/** Tracks the mapping from toolchain type label to {@link ToolchainInfo} provider. */
- private class ResolvedToolchainProviders implements SkylarkValue, SkylarkIndexable {
+ public class ResolvedToolchainProviders implements SkylarkValue, SkylarkIndexable {
private final ImmutableMap<Label, ToolchainInfo> toolchains;
@@ -226,6 +226,11 @@ public class ToolchainContext {
return toolchains.get(toolchainType);
}
+ /** Returns the toolchain for the given type */
+ public ToolchainInfo getForToolchainType(Label toolchainType) {
+ return toolchains.get(toolchainType);
+ }
+
@Override
public boolean containsKey(Object key, Location loc) throws EvalException {
Label toolchainType = transformKey(key, loc);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
index b064b5b6ed..0a6d6af9c8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
@@ -107,7 +107,11 @@ public class PostConfiguredTargetFunction implements SkyFunction {
// can never fail.
deps =
resolver.dependentNodeMap(
- ctgValue, hostConfiguration, /*aspect=*/ null, configConditions);
+ ctgValue,
+ hostConfiguration,
+ /*aspect=*/ null,
+ configConditions,
+ /*toolchainContext=*/ null);
if (ct.getConfiguration() != null) {
deps = ConfiguredTargetFunction.getDynamicConfigurations(env, ctgValue, deps,
hostConfiguration, ruleClassProvider);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
index 83bcdad904..00130f8282 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
@@ -390,7 +390,7 @@ public class BuildViewTest extends BuildViewTestBase {
update("//package:top");
ConfiguredTarget top = getConfiguredTarget("//package:top", getTargetConfiguration());
Iterable<Dependency> targets = getView().getDirectPrerequisiteDependenciesForTesting(
- reporter, top, getBuildConfigurationCollection()).values();
+ reporter, top, getBuildConfigurationCollection(), /*toolchainContext=*/ null).values();
Dependency innerDependency =
Dependency.withTransitionAndAspects(
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
index 3d29927842..1444837448 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
@@ -109,7 +109,8 @@ public class DependencyResolverTest extends AnalysisTestCase {
new TargetAndConfiguration(target, getTargetConfiguration()),
getHostConfiguration(),
aspect != null ? Aspect.forNative(aspect) : null,
- ImmutableMap.<Label, ConfigMatchingProvider>of());
+ ImmutableMap.<Label, ConfigMatchingProvider>of(),
+ /*toolchainContext=*/ null);
}
@SafeVarargs
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
index 1eeec40c78..d5b345d3d1 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RuleContextTest.java
@@ -17,6 +17,8 @@ package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.ToolchainContext.ResolvedToolchainProviders;
+import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
import org.junit.Test;
@@ -36,5 +38,13 @@ public class RuleContextTest extends ToolchainTestCase {
RuleContext ruleContext = getRuleContext(getConfiguredTarget("//x"));
assertThat(ruleContext.getToolchainContext().getResolvedToolchainLabels())
.contains(Label.parseAbsolute("//toolchain:test_toolchain_1"));
+
+ ResolvedToolchainProviders resolvedToolchainProviders =
+ (ResolvedToolchainProviders)
+ ruleContext.getToolchainContext().getResolvedToolchainProviders();
+ ToolchainInfo toolchain =
+ resolvedToolchainProviders.getForToolchainType(
+ Label.parseAbsolute("//toolchain:test_toolchain"));
+ assertThat(toolchain.getValue("data")).isEqualTo("foo");
}
}