aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-11-22 09:15:12 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-22 09:17:03 -0800
commit73fd99795e1eba495394bad99d42b6bb8010e85a (patch)
tree532de919932819042eb2a0bc2cf7994641b56fb7
parent96e244dc211ef3277f154f1f03bd0c87347d522a (diff)
Add platform data into to the ToolchainContext unconditionally.
Part of #4128. Change-Id: I1e043e7290912de5b246dbb8748cb2ad865ce38c PiperOrigin-RevId: 176664440
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java31
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java38
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ToolchainUtilTest.java8
3 files changed, 63 insertions, 14 deletions
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 2334c6fc71..de1fc37773 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
@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
@@ -53,14 +54,24 @@ import javax.annotation.Nullable;
public class ToolchainContext {
public static ToolchainContext create(
String targetDescription,
+ PlatformInfo executionPlatform,
+ PlatformInfo targetPlatform,
Set<Label> requiredToolchains,
ImmutableBiMap<Label, Label> resolvedLabels) {
- ToolchainContext toolchainContext =
- new ToolchainContext(
- targetDescription, requiredToolchains, new ResolvedToolchainLabels(resolvedLabels));
- return toolchainContext;
+ return new ToolchainContext(
+ targetDescription,
+ executionPlatform,
+ targetPlatform,
+ requiredToolchains,
+ new ResolvedToolchainLabels(resolvedLabels));
}
+ /** The {@link PlatformInfo} describing where these toolchains can be executed. */
+ private final PlatformInfo executionPlatform;
+
+ /** The {@link PlatformInfo} describing the outputs of these toolchains. */
+ private final PlatformInfo targetPlatform;
+
/** Description of the target the toolchain context applies to, for use in error messages. */
private final String targetDescription;
@@ -75,15 +86,27 @@ public class ToolchainContext {
private ToolchainContext(
String targetDescription,
+ PlatformInfo executionPlatform,
+ PlatformInfo targetPlatform,
Set<Label> requiredToolchains,
ResolvedToolchainLabels resolvedToolchainLabels) {
this.targetDescription = targetDescription;
+ this.executionPlatform = executionPlatform;
+ this.targetPlatform = targetPlatform;
this.requiredToolchains = ImmutableList.copyOf(requiredToolchains);
this.resolvedToolchainLabels = resolvedToolchainLabels;
this.resolvedToolchainProviders =
new ResolvedToolchainProviders(ImmutableMap.<Label, ToolchainInfo>of());
}
+ public PlatformInfo getExecutionPlatform() {
+ return executionPlatform;
+ }
+
+ public PlatformInfo getTargetPlatform() {
+ return targetPlatform;
+ }
+
public ImmutableList<Label> getRequiredToolchains() {
return requiredToolchains;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
index ca311c8989..a47e373906 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
@@ -55,15 +55,36 @@ public class ToolchainUtil {
Environment env,
String targetDescription,
Set<Label> requiredToolchains,
- BuildConfiguration configuration)
+ @Nullable BuildConfiguration configuration)
throws ToolchainContextException, InterruptedException {
+
+ // In some cases this is called with a missing configuration, so we skip toolchain context.
+ if (configuration == null) {
+ return null;
+ }
+
+ // TODO(katre): Load several possible execution platforms, and select one based on available
+ // toolchains.
+
+ // Load the execution and target platforms for the current configuration.
+ PlatformDescriptors platforms = loadPlatformDescriptors(env, configuration);
+ if (platforms == null) {
+ return null;
+ }
+
ImmutableBiMap<Label, Label> resolvedLabels =
- resolveToolchainLabels(env, requiredToolchains, configuration);
+ resolveToolchainLabels(env, requiredToolchains, configuration, platforms);
if (resolvedLabels == null) {
return null;
}
+
ToolchainContext toolchainContext =
- ToolchainContext.create(targetDescription, requiredToolchains, resolvedLabels);
+ ToolchainContext.create(
+ targetDescription,
+ platforms.execPlatform(),
+ platforms.targetPlatform(),
+ requiredToolchains,
+ resolvedLabels);
return toolchainContext;
}
@@ -152,7 +173,10 @@ public class ToolchainUtil {
@Nullable
private static ImmutableBiMap<Label, Label> resolveToolchainLabels(
- Environment env, Set<Label> requiredToolchains, BuildConfiguration configuration)
+ Environment env,
+ Set<Label> requiredToolchains,
+ BuildConfiguration configuration,
+ PlatformDescriptors platforms)
throws InterruptedException, ToolchainContextException {
// If there are no required toolchains, bail out early.
@@ -160,12 +184,6 @@ public class ToolchainUtil {
return ImmutableBiMap.of();
}
- // Load the execution and target platforms for the current configuration.
- PlatformDescriptors platforms = loadPlatformDescriptors(env, configuration);
- if (platforms == null) {
- return null;
- }
-
// Find the toolchains for the required toolchain types.
List<SkyKey> registeredToolchainKeys = new ArrayList<>();
for (Label toolchainType : requiredToolchains) {
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainUtilTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainUtilTest.java
index 4a9866fc6b..40f6aad215 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainUtilTest.java
@@ -87,6 +87,14 @@ public class ToolchainUtilTest extends ToolchainTestCase {
assertThat(toolchainContext.getRequiredToolchains()).containsExactly(testToolchainType);
assertThat(toolchainContext.getResolvedToolchainLabels())
.containsExactly(Label.parseAbsoluteUnchecked("//toolchain:test_toolchain_1"));
+
+ assertThat(toolchainContext.getExecutionPlatform()).isNotNull();
+ assertThat(toolchainContext.getExecutionPlatform().label())
+ .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:linux"));
+
+ assertThat(toolchainContext.getTargetPlatform()).isNotNull();
+ assertThat(toolchainContext.getTargetPlatform().label())
+ .isEqualTo(Label.parseAbsoluteUnchecked("//platforms:mac"));
}
@Test