From 5ee389c261c98854af9ed6a8142541d49b32cf74 Mon Sep 17 00:00:00 2001 From: John Cater Date: Wed, 30 Aug 2017 20:07:32 +0200 Subject: Add check that the exec and target platform labels actually provide a PlatformInfo provider. Fixes #3631. Change-Id: I78ed8905e18e3c11c01d6e30512c10491a5ba0f1 PiperOrigin-RevId: 167019469 --- .../devtools/build/lib/skyframe/ToolchainUtil.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/main/java/com/google/devtools') 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 925c854c67..0f2a35238e 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 @@ -38,6 +38,7 @@ import com.google.devtools.build.skyframe.ValueOrException4; import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; /** * Common code to create a {@link ToolchainContext} given a set of required toolchain type labels. @@ -48,6 +49,7 @@ public class ToolchainUtil { * Returns a new {@link ToolchainContext}, with the correct toolchain labels based on the results * of the {@link ToolchainResolutionFunction}. */ + @Nullable public static ToolchainContext createToolchainContext( Environment env, String targetDescription, @@ -56,6 +58,9 @@ public class ToolchainUtil { throws ToolchainContextException, InterruptedException { ImmutableBiMap resolvedLabels = resolveToolchainLabels(env, requiredToolchains, configuration); + if (resolvedLabels == null) { + return null; + } ToolchainContext toolchainContext = ToolchainContext.create(targetDescription, requiredToolchains, resolvedLabels); return toolchainContext; @@ -76,6 +81,7 @@ public class ToolchainUtil { } } + @Nullable private static PlatformDescriptors loadPlatformDescriptors( Environment env, BuildConfiguration configuration) throws InterruptedException, ToolchainContextException { @@ -108,12 +114,22 @@ public class ToolchainUtil { 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)); + } + return PlatformDescriptors.create(execPlatform, targetPlatform); } catch (ConfiguredValueCreationException e) { throw new ToolchainContextException(e); } } + @Nullable private static ImmutableBiMap resolveToolchainLabels( Environment env, List