diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java index 0b1b15d770b06d..9c5bbe8641ee56 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java @@ -32,7 +32,6 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; -import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.skyframe.PlatformLookupUtil.InvalidPlatformException; import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidToolchainLabelException; import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionValue.SingleToolchainResolutionKey; @@ -90,6 +89,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) // Find the right one. return resolveConstraints( key.toolchainType(), + key.toolchainTypeInfo(), key.availableExecutionPlatformKeys(), key.targetPlatformKey(), toolchains.registeredToolchains(), @@ -105,6 +105,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) @Nullable private static SingleToolchainResolutionValue resolveConstraints( ToolchainTypeRequirement toolchainType, + ToolchainTypeInfo toolchainTypeInfo, List availableExecutionPlatformKeys, ConfiguredTargetKey targetPlatformKey, ImmutableList toolchains, @@ -136,7 +137,6 @@ private static SingleToolchainResolutionValue resolveConstraints( // check whether a platform has already been seen during processing. Set platformKeysSeen = new HashSet<>(); ImmutableMap.Builder builder = ImmutableMap.builder(); - ToolchainTypeInfo toolchainTypeInfo = null; // Pre-filter for the correct toolchain type. This simplifies the loop and makes debugging // toolchain resolution much, much easier. @@ -202,20 +202,18 @@ private static SingleToolchainResolutionValue resolveConstraints( targetPlatform.label(), executionPlatformKey.getLabel(), toolchain.toolchainLabel()); - toolchainTypeInfo = toolchain.toolchainType(); builder.put(executionPlatformKey, toolchain.toolchainLabel()); platformKeysSeen.add(executionPlatformKey); } } ImmutableMap resolvedToolchainLabels = builder.buildOrThrow(); - if (toolchainType == null || resolvedToolchainLabels.isEmpty()) { + if (resolvedToolchainLabels.isEmpty()) { debugMessage( eventHandler, " Type %s: target platform %s: No toolchains found.", toolchainType.toolchainType(), targetPlatform.label()); - throw new ToolchainResolutionFunctionException(new NoToolchainFoundException(toolchainType)); } return SingleToolchainResolutionValue.create(toolchainTypeInfo, resolvedToolchainLabels); @@ -296,30 +294,10 @@ private static boolean checkConstraints( return mismatchSettingsWithDefault.isEmpty(); } - /** Used to indicate that a toolchain was not found for the current request. */ - public static final class NoToolchainFoundException extends NoSuchThingException { - private final ToolchainTypeRequirement missingToolchainType; - - public NoToolchainFoundException(ToolchainTypeRequirement missingToolchainType) { - super( - String.format( - "no matching toolchain found for %s", missingToolchainType.toolchainType())); - this.missingToolchainType = missingToolchainType; - } - - public ToolchainTypeRequirement missingToolchainType() { - return missingToolchainType; - } - } - /** * Used to indicate errors during the computation of an {@link SingleToolchainResolutionValue}. */ private static final class ToolchainResolutionFunctionException extends SkyFunctionException { - ToolchainResolutionFunctionException(NoToolchainFoundException e) { - super(e, Transience.PERSISTENT); - } - ToolchainResolutionFunctionException(InvalidToolchainLabelException e) { super(e, Transience.PERSISTENT); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionValue.java index a19c27e81cf49e..a9718ede5e8298 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionValue.java @@ -37,21 +37,29 @@ public abstract class SingleToolchainResolutionValue implements SkyValue { public static SingleToolchainResolutionKey key( BuildConfigurationKey configurationKey, ToolchainTypeRequirement toolchainType, + ToolchainTypeInfo toolchainTypeInfo, ConfiguredTargetKey targetPlatformKey, List availableExecutionPlatformKeys) { return key( - configurationKey, toolchainType, targetPlatformKey, availableExecutionPlatformKeys, false); + configurationKey, + toolchainType, + toolchainTypeInfo, + targetPlatformKey, + availableExecutionPlatformKeys, + false); } public static SingleToolchainResolutionKey key( BuildConfigurationKey configurationKey, ToolchainTypeRequirement toolchainType, + ToolchainTypeInfo toolchainTypeInfo, ConfiguredTargetKey targetPlatformKey, List availableExecutionPlatformKeys, boolean debugTarget) { return SingleToolchainResolutionKey.create( configurationKey, toolchainType, + toolchainTypeInfo, targetPlatformKey, availableExecutionPlatformKeys, debugTarget); @@ -70,6 +78,8 @@ public SkyFunctionName functionName() { public abstract ToolchainTypeRequirement toolchainType(); + public abstract ToolchainTypeInfo toolchainTypeInfo(); + abstract ConfiguredTargetKey targetPlatformKey(); abstract ImmutableList availableExecutionPlatformKeys(); @@ -79,12 +89,14 @@ public SkyFunctionName functionName() { static SingleToolchainResolutionKey create( BuildConfigurationKey configurationKey, ToolchainTypeRequirement toolchainType, + ToolchainTypeInfo toolchainTypeInfo, ConfiguredTargetKey targetPlatformKey, List availableExecutionPlatformKeys, boolean debugTarget) { return new AutoValue_SingleToolchainResolutionValue_SingleToolchainResolutionKey( configurationKey, toolchainType, + toolchainTypeInfo, targetPlatformKey, ImmutableList.copyOf(availableExecutionPlatformKeys), debugTarget); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java index ab1edb29567567..e2cdeef7c22d05 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java @@ -13,7 +13,6 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; -import static com.google.common.collect.ImmutableList.builder; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static java.util.stream.Collectors.joining; @@ -40,13 +39,12 @@ import com.google.devtools.build.lib.skyframe.PlatformLookupUtil.InvalidPlatformException; import com.google.devtools.build.lib.skyframe.RegisteredExecutionPlatformsFunction.InvalidExecutionPlatformLabelException; import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidToolchainLabelException; -import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionFunction.NoToolchainFoundException; import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionValue.SingleToolchainResolutionKey; import com.google.devtools.build.lib.skyframe.ToolchainTypeLookupUtil.InvalidToolchainTypeException; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; import com.google.devtools.build.skyframe.SkyKey; -import com.google.devtools.build.skyframe.SkyframeIterableResult; +import com.google.devtools.build.skyframe.SkyframeLookupResult; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -92,15 +90,15 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env) // Load the configured target for the toolchain types to ensure that they are valid and // resolve aliases. ImmutableMap resolvedToolchainTypeInfos = - loadToolchainTypes( + loadToolchainTypeInfos( env, configuration, key.toolchainTypes().stream() .map(ToolchainTypeRequirement::toolchainType) .collect(toImmutableSet())); builder.setRequestedLabelToToolchainType(resolvedToolchainTypeInfos); - ImmutableSet resolvedToolchainTypes = - loadToolchainTypeRequirements(resolvedToolchainTypeInfos, key.toolchainTypes()); + ImmutableSet resolvedToolchainTypes = + loadToolchainTypes(resolvedToolchainTypeInfos, key.toolchainTypes()); // Create keys for all platforms that will be used, and validate them early. PlatformKeys platformKeys = @@ -152,11 +150,24 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env) } } + @AutoValue + abstract static class ToolchainType { + abstract ToolchainTypeRequirement toolchainTypeRequirement(); + + abstract ToolchainTypeInfo toolchainTypeInfo(); + + static ToolchainType create( + ToolchainTypeRequirement toolchainTypeRequirement, ToolchainTypeInfo toolchainTypeInfo) { + return new AutoValue_ToolchainResolutionFunction_ToolchainType( + toolchainTypeRequirement, toolchainTypeInfo); + } + } + /** * Returns a map from the requested toolchain type Label (after any alias chains) to the {@link * ToolchainTypeInfo} provider. */ - private static ImmutableMap loadToolchainTypes( + private static ImmutableMap loadToolchainTypeInfos( Environment environment, BuildConfigurationValue configuration, ImmutableSet