aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2018-02-22 16:31:37 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-22 16:33:47 -0800
commitb2a9e786e880a7afb942951c45ff0851e2a9cb52 (patch)
tree63be08c57bd525fd62da1752afdc9130d9928bac /src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
parentfe29c724742662ca41d66450cd70e42fd9e58fa2 (diff)
Re-enable loading the PlatformInfo providers in
RegisteredExecutionPlatformsFunction, so that errors can be handled as early as possible. Change-Id: I2c73a9202d6bb02e04a32c18c4986e1e204aa9d5 PiperOrigin-RevId: 186694303
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java88
1 files changed, 86 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index df5bb86027..d7e6e21bae 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -16,15 +16,22 @@ package com.google.devtools.build.lib.skyframe;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
+import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Package;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
+import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
+import com.google.devtools.build.skyframe.ValueOrException;
import java.util.List;
+import java.util.Map;
import javax.annotation.Nullable;
/** {@link SkyFunction} that returns all registered execution platforms available. */
@@ -62,7 +69,7 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
// Load the configured target for each, and get the declared execution platforms providers.
ImmutableList<ConfiguredTargetKey> registeredExecutionPlatformKeys =
configureRegisteredExecutionPlatforms(
- configuration, registeredExecutionPlatformLabels.build());
+ env, configuration, registeredExecutionPlatformLabels.build());
if (env.valuesMissing()) {
return null;
}
@@ -90,13 +97,47 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
}
private ImmutableList<ConfiguredTargetKey> configureRegisteredExecutionPlatforms(
- BuildConfiguration configuration, List<Label> labels) {
+ Environment env, BuildConfiguration configuration, List<Label> labels)
+ throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
ImmutableList<ConfiguredTargetKey> keys =
labels
.stream()
.map(label -> ConfiguredTargetKey.of(label, configuration))
.collect(ImmutableList.toImmutableList());
+ // Load the actual configured targets and ensure that they have real, valid PlatformInfo
+ // instances. These are loaded later during toolchain resolution (see
+ // ToolchainUtil#getPlatformInfo), so this is work that needs to be done anyway, but here we can
+ // fail fast on an error.
+ Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
+ env.getValuesOrThrow(keys, ConfiguredValueCreationException.class);
+ boolean valuesMissing = false;
+ for (SkyKey key : keys) {
+ ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key.argument();
+ Label platformLabel = configuredTargetKey.getLabel();
+ try {
+ ValueOrException<ConfiguredValueCreationException> valueOrException = values.get(key);
+ if (valueOrException.get() == null) {
+ valuesMissing = true;
+ continue;
+ }
+ ConfiguredTarget target =
+ ((ConfiguredTargetValue) valueOrException.get()).getConfiguredTarget();
+ PlatformInfo platformInfo = PlatformProviderUtils.platform(target);
+
+ if (platformInfo == null) {
+ throw new RegisteredExecutionPlatformsFunctionException(
+ new InvalidExecutionPlatformLabelException(platformLabel), Transience.PERSISTENT);
+ }
+ } catch (ConfiguredValueCreationException e) {
+ throw new RegisteredExecutionPlatformsFunctionException(
+ new InvalidExecutionPlatformLabelException(platformLabel, e), Transience.PERSISTENT);
+ }
+ }
+
+ if (valuesMissing) {
+ return null;
+ }
return keys;
}
@@ -105,4 +146,47 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
public String extractTag(SkyKey skyKey) {
return null;
}
+
+ /**
+ * Used to indicate that the given {@link Label} represents a {@link ConfiguredTarget} which is
+ * not a valid {@link PlatformInfo} provider.
+ */
+ static final class InvalidExecutionPlatformLabelException extends Exception {
+
+ private final Label invalidLabel;
+
+ private InvalidExecutionPlatformLabelException(Label invalidLabel) {
+ super(
+ String.format(
+ "invalid registered execution platform '%s': "
+ + "target does not provide the PlatformInfo provider",
+ invalidLabel));
+ this.invalidLabel = invalidLabel;
+ }
+
+ private InvalidExecutionPlatformLabelException(
+ Label invalidLabel, ConfiguredValueCreationException e) {
+ super(
+ String.format(
+ "invalid registered execution platform '%s': %s", invalidLabel, e.getMessage()),
+ e);
+ this.invalidLabel = invalidLabel;
+ }
+
+ public Label getInvalidLabel() {
+ return invalidLabel;
+ }
+ }
+
+ /**
+ * Used to declare all the exception types that can be wrapped in the exception thrown by {@link
+ * #compute}.
+ */
+ private static class RegisteredExecutionPlatformsFunctionException extends SkyFunctionException {
+
+ private RegisteredExecutionPlatformsFunctionException(
+ InvalidExecutionPlatformLabelException cause, Transience transience) {
+ super(cause, transience);
+ }
+ }
}