aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-09-25 10:58:41 -0400
committerGravatar John Cater <jcater@google.com>2017-09-25 12:02:51 -0400
commit77112c6ee7cc98e3e2732e54bee3f45efc5179bf (patch)
treea94b8810f4dd79357dac70bcbb11ad96dba64ad5 /src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java
parent66ab13fad654881ed3caccde7c9e0422b222e32e (diff)
Update RegisteredToolchainsFunction and ToolchainUtil to check values for errors even if not all values are present.
Fixes #3751. Change-Id: I92fd7527384800beca80b9daac58f3a7760268b2 PiperOrigin-RevId: 169907526
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ToolchainUtil.java72
1 files changed, 50 insertions, 22 deletions
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 13e055b5aa..84c0e256e9 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
@@ -82,6 +82,32 @@ public class ToolchainUtil {
}
}
+ /**
+ * Returns the {@link PlatformInfo} provider from the {@link ConfiguredTarget} in the {@link
+ * ValueOrException}, or {@code null} if the {@link ConfiguredTarget} is not present. If the
+ * {@link ConfiguredTarget} does not have a {@link PlatformInfo} provider, a {@link
+ * InvalidPlatformException} is thrown, wrapped in a {@link ToolchainContextException}.
+ */
+ @Nullable
+ private static PlatformInfo findPlatformInfo(
+ ValueOrException<ConfiguredValueCreationException> valueOrException, String platformType)
+ throws ConfiguredValueCreationException, ToolchainContextException {
+
+ ConfiguredTargetValue ctv = (ConfiguredTargetValue) valueOrException.get();
+ if (ctv == null) {
+ return null;
+ }
+
+ ConfiguredTarget configuredTarget = ctv.getConfiguredTarget();
+ PlatformInfo platformInfo = PlatformProviderUtils.platform(configuredTarget);
+ if (platformInfo == null) {
+ throw new ToolchainContextException(
+ new InvalidPlatformException(platformType, configuredTarget));
+ }
+
+ return platformInfo;
+ }
+
@Nullable
private static PlatformDescriptors loadPlatformDescriptors(
Environment env, BuildConfiguration configuration)
@@ -104,24 +130,15 @@ public class ToolchainUtil {
env.getValuesOrThrow(
ImmutableList.of(executionPlatformKey, targetPlatformKey),
ConfiguredValueCreationException.class);
- if (env.valuesMissing()) {
- return null;
- }
+ boolean valuesMissing = env.valuesMissing();
try {
- ConfiguredTarget executionPlatformTarget =
- ((ConfiguredTargetValue) values.get(executionPlatformKey).get()).getConfiguredTarget();
- ConfiguredTarget targetPlatformTarget =
- ((ConfiguredTargetValue) values.get(targetPlatformKey).get()).getConfiguredTarget();
- PlatformInfo execPlatform = PlatformProviderUtils.platform(executionPlatformTarget);
- PlatformInfo targetPlatform = PlatformProviderUtils.platform(targetPlatformTarget);
-
- if (execPlatform == null) {
- throw new ToolchainContextException(
- new InvalidPlatformException("execution platform", executionPlatformTarget));
- }
- if (targetPlatform == null) {
- throw new ToolchainContextException(
- new InvalidPlatformException("target platform", targetPlatformTarget));
+ PlatformInfo execPlatform =
+ findPlatformInfo(values.get(executionPlatformKey), "execution platform");
+ PlatformInfo targetPlatform =
+ findPlatformInfo(values.get(targetPlatformKey), "target platform");
+
+ if (valuesMissing) {
+ return null;
}
return PlatformDescriptors.create(execPlatform, targetPlatform);
@@ -166,9 +183,7 @@ public class ToolchainUtil {
ConfiguredValueCreationException.class,
InvalidToolchainLabelException.class,
EvalException.class);
- if (env.valuesMissing()) {
- return null;
- }
+ boolean valuesMissing = false;
// Load the toolchains.
ImmutableBiMap.Builder<Label, Label> builder = new ImmutableBiMap.Builder<>();
@@ -182,8 +197,17 @@ public class ToolchainUtil {
try {
Label requiredToolchainType =
((ToolchainResolutionKey) entry.getKey().argument()).toolchainType();
- Label toolchainLabel = ((ToolchainResolutionValue) entry.getValue().get()).toolchainLabel();
- builder.put(requiredToolchainType, toolchainLabel);
+ ValueOrException4<
+ NoToolchainFoundException, ConfiguredValueCreationException,
+ InvalidToolchainLabelException, EvalException>
+ valueOrException = entry.getValue();
+ if (valueOrException.get() == null) {
+ valuesMissing = true;
+ } else {
+ Label toolchainLabel =
+ ((ToolchainResolutionValue) valueOrException.get()).toolchainLabel();
+ builder.put(requiredToolchainType, toolchainLabel);
+ }
} catch (NoToolchainFoundException e) {
// Save the missing type and continue looping to check for more.
missingToolchains.add(e.missingToolchainType());
@@ -196,6 +220,10 @@ public class ToolchainUtil {
}
}
+ if (valuesMissing) {
+ return null;
+ }
+
if (!missingToolchains.isEmpty()) {
throw new ToolchainContextException(new UnresolvedToolchainsException(missingToolchains));
}