aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe
diff options
context:
space:
mode:
authorGravatar jcater <jcater@google.com>2018-02-15 21:10:22 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-15 21:11:33 -0800
commitb653624e1e50cd0028305dddfddec4b73ec51f5a (patch)
tree1d63feef68c644de0f379721d9335deba3b83c4a /src/main/java/com/google/devtools/build/lib/skyframe
parent8c4c5eb324ead15bcf4476c1179dcffcd1caecf9 (diff)
Remove BuildConfiguration and PlatformInfo from the
RegisteredExecutionPlatformsFunction. PiperOrigin-RevId: 185947540
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java104
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java57
2 files changed, 63 insertions, 98 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 8e2030273b..df5bb86027 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,22 +16,15 @@ 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. */
@@ -42,7 +35,13 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
public SkyValue compute(SkyKey skyKey, Environment env)
throws SkyFunctionException, InterruptedException {
- BuildConfiguration configuration = (BuildConfiguration) skyKey.argument();
+ BuildConfigurationValue buildConfigurationValue =
+ (BuildConfigurationValue)
+ env.getValue(((RegisteredExecutionPlatformsValue.Key) skyKey).getConfigurationKey());
+ if (env.valuesMissing()) {
+ return null;
+ }
+ BuildConfiguration configuration = buildConfigurationValue.getConfiguration();
ImmutableList.Builder<Label> registeredExecutionPlatformLabels = new ImmutableList.Builder<>();
@@ -61,14 +60,14 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
registeredExecutionPlatformLabels.addAll(workspaceExecutionPlatforms);
// Load the configured target for each, and get the declared execution platforms providers.
- ImmutableList<PlatformInfo> registeredExecutionPlatforms =
+ ImmutableList<ConfiguredTargetKey> registeredExecutionPlatformKeys =
configureRegisteredExecutionPlatforms(
- env, configuration, registeredExecutionPlatformLabels.build());
+ configuration, registeredExecutionPlatformLabels.build());
if (env.valuesMissing()) {
return null;
}
- return RegisteredExecutionPlatformsValue.create(registeredExecutionPlatforms);
+ return RegisteredExecutionPlatformsValue.create(registeredExecutionPlatformKeys);
}
/**
@@ -90,47 +89,15 @@ public class RegisteredExecutionPlatformsFunction implements SkyFunction {
return externalPackage.getRegisteredExecutionPlatformLabels();
}
- private ImmutableList<PlatformInfo> configureRegisteredExecutionPlatforms(
- Environment env, BuildConfiguration configuration, List<Label> labels)
- throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
- ImmutableList<SkyKey> keys =
+ private ImmutableList<ConfiguredTargetKey> configureRegisteredExecutionPlatforms(
+ BuildConfiguration configuration, List<Label> labels) {
+ ImmutableList<ConfiguredTargetKey> keys =
labels
.stream()
.map(label -> ConfiguredTargetKey.of(label, configuration))
.collect(ImmutableList.toImmutableList());
- Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
- env.getValuesOrThrow(keys, ConfiguredValueCreationException.class);
- ImmutableList.Builder<PlatformInfo> platforms = new ImmutableList.Builder<>();
- 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);
- }
- platforms.add(platformInfo);
- } catch (ConfiguredValueCreationException e) {
- throw new RegisteredExecutionPlatformsFunctionException(
- new InvalidExecutionPlatformLabelException(platformLabel, e), Transience.PERSISTENT);
- }
- }
-
- if (valuesMissing) {
- return null;
- }
- return platforms.build();
+ return keys;
}
@Nullable
@@ -138,47 +105,4 @@ 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.
- */
- public static final class InvalidExecutionPlatformLabelException extends Exception {
-
- private final Label invalidLabel;
-
- public InvalidExecutionPlatformLabelException(Label invalidLabel) {
- super(
- String.format(
- "invalid registered execution platform '%s': "
- + "target does not provide the PlatformInfo provider",
- invalidLabel));
- this.invalidLabel = invalidLabel;
- }
-
- public 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}.
- */
- public static class RegisteredExecutionPlatformsFunctionException extends SkyFunctionException {
-
- public RegisteredExecutionPlatformsFunctionException(
- InvalidExecutionPlatformLabelException cause, Transience transience) {
- super(cause, transience);
- }
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
index e242ff6ce9..03d4e92923 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
@@ -16,11 +16,13 @@ package com.google.devtools.build.lib.skyframe;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
-import com.google.devtools.build.skyframe.LegacySkyKey;
+import com.google.common.collect.Interner;
+import com.google.devtools.build.lib.concurrent.BlazeInterners;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
+import java.util.Objects;
/**
* A value which represents every execution platform known to Bazel and available to run actions.
@@ -29,15 +31,54 @@ import com.google.devtools.build.skyframe.SkyValue;
public abstract class RegisteredExecutionPlatformsValue implements SkyValue {
/** Returns the {@link SkyKey} for {@link RegisteredExecutionPlatformsValue}s. */
- public static SkyKey key(BuildConfiguration configuration) {
- return LegacySkyKey.create(SkyFunctions.REGISTERED_EXECUTION_PLATFORMS, configuration);
+ public static SkyKey key(BuildConfigurationValue.Key configurationKey) {
+ return Key.of(configurationKey);
+ }
+
+ @AutoCodec
+ static class Key implements SkyKey {
+ private static final Interner<Key> interners = BlazeInterners.newWeakInterner();
+ private final BuildConfigurationValue.Key configurationKey;
+
+ private Key(BuildConfigurationValue.Key configurationKey) {
+ this.configurationKey = configurationKey;
+ }
+
+ @AutoCodec.Instantiator
+ @AutoCodec.VisibleForSerialization
+ static Key of(BuildConfigurationValue.Key configurationKey) {
+ return interners.intern(new Key(configurationKey));
+ }
+
+ @Override
+ public SkyFunctionName functionName() {
+ return SkyFunctions.REGISTERED_EXECUTION_PLATFORMS;
+ }
+
+ BuildConfigurationValue.Key getConfigurationKey() {
+ return configurationKey;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Key)) {
+ return false;
+ }
+ Key that = (Key) obj;
+ return Objects.equals(this.configurationKey, that.configurationKey);
+ }
+
+ @Override
+ public int hashCode() {
+ return configurationKey.hashCode();
+ }
}
static RegisteredExecutionPlatformsValue create(
- Iterable<PlatformInfo> registeredExecutionPlatforms) {
+ Iterable<ConfiguredTargetKey> registeredExecutionPlatformKeys) {
return new AutoValue_RegisteredExecutionPlatformsValue(
- ImmutableList.copyOf(registeredExecutionPlatforms));
+ ImmutableList.copyOf(registeredExecutionPlatformKeys));
}
- public abstract ImmutableList<PlatformInfo> registeredExecutionPlatforms();
+ public abstract ImmutableList<ConfiguredTargetKey> registeredExecutionPlatformKeys();
}