diff options
author | 2018-02-13 15:37:30 -0800 | |
---|---|---|
committer | 2018-02-13 15:38:43 -0800 | |
commit | 649d2b12c647d74c6df846adff802b615119ac12 (patch) | |
tree | ddc09603cd6adad9cb1e6d2296563624fe88544c /src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java | |
parent | ecc4edc6f513ce87ac73cb8c778a26c45dfe9a5e (diff) |
@AutoCodec AspectValue$AspectKey.
Also make AspectKey#toString a little more informative.
PiperOrigin-RevId: 185600069
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java index cf12d6220d..0186315117 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java @@ -35,16 +35,10 @@ import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.skyframe.BuildConfigurationValue.Key; import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey.KeyAndHost; -import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext; -import com.google.devtools.build.lib.skyframe.serialization.ImmutableListCodec; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; -import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; -import com.google.devtools.build.lib.skyframe.serialization.SerializationException; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.syntax.SkylarkImport; import com.google.devtools.build.skyframe.SkyFunctionName; -import com.google.protobuf.CodedInputStream; -import com.google.protobuf.CodedOutputStream; -import java.io.IOException; import java.util.List; import javax.annotation.Nullable; @@ -61,8 +55,9 @@ public final class AspectValue extends ActionLookupValue { } /** A base class for a key representing an aspect applied to a particular target. */ + @AutoCodec public static class AspectKey extends AspectValueKey { - public static final ObjectCodec<AspectKey> CODEC = new AspectKeyCodec(); + public static final ObjectCodec<AspectKey> CODEC = new AspectValue_AspectKey_AutoCodec(); private final Label label; private final ImmutableList<AspectKey> baseKeys; private final BuildConfigurationValue.Key aspectConfigurationKey; @@ -83,6 +78,31 @@ public final class AspectValue extends ActionLookupValue { this.aspectDescriptor = aspectDescriptor; } + @AutoCodec.VisibleForSerialization + @AutoCodec.Instantiator + static AspectKey createAspectKey( + Label label, + ConfiguredTargetKey baseConfiguredTargetKey, + ImmutableList<AspectKey> baseKeys, + AspectDescriptor aspectDescriptor, + BuildConfigurationValue.Key aspectConfigurationKey, + boolean aspectConfigurationIsHost) { + return aspectKeyInterner.intern( + aspectConfigurationIsHost + ? new HostAspectKey( + label, + aspectConfigurationKey, + baseConfiguredTargetKey, + baseKeys, + aspectDescriptor) + : new AspectKey( + label, + aspectConfigurationKey, + baseConfiguredTargetKey, + baseKeys, + aspectDescriptor)); + } + @Override public SkyFunctionName functionName() { return SkyFunctions.ASPECT; @@ -108,7 +128,7 @@ public final class AspectValue extends ActionLookupValue { } @Nullable - public ImmutableList<AspectKey> getBaseKeys() { + ImmutableList<AspectKey> getBaseKeys() { return baseKeys; } @@ -123,6 +143,8 @@ public final class AspectValue extends ActionLookupValue { } } + // Note that this does not factor into equality/hash-code computations because its value is + // already encoded in the aspectConfigurationKey, albeit in an opaque way. protected boolean aspectConfigurationIsHost() { return false; } @@ -223,13 +245,14 @@ public final class AspectValue extends ActionLookupValue { public String toString() { return (baseKeys == null ? label : baseKeys.toString()) + "#" - + aspectDescriptor.getAspectClass().getName() + + aspectDescriptor + " " + aspectConfigurationKey + " " + baseConfiguredTargetKey + " " - + aspectDescriptor.getParameters(); + + aspectDescriptor.getParameters() + + (aspectConfigurationIsHost() ? " (host)" : ""); } AspectKey withLabel(Label label) { @@ -270,38 +293,6 @@ public final class AspectValue extends ActionLookupValue { } } - private static class AspectKeyCodec implements ObjectCodec<AspectKey> { - private final ImmutableListCodec<AspectKey> listCodec = new ImmutableListCodec<>(this); - - @Override - public Class<AspectKey> getEncodedClass() { - return AspectKey.class; - } - - @Override - public void serialize(SerializationContext context, AspectKey obj, CodedOutputStream codedOut) - throws SerializationException, IOException { - Label.CODEC.serialize(context, obj.label, codedOut); - ConfiguredTargetKey.CODEC.serialize(context, obj.baseConfiguredTargetKey, codedOut); - listCodec.serialize(context, obj.baseKeys, codedOut); - AspectDescriptor.CODEC.serialize(context, obj.aspectDescriptor, codedOut); - Key.CODEC.serialize(context, obj.aspectConfigurationKey, codedOut); - codedOut.writeBoolNoTag(obj.aspectConfigurationIsHost()); - } - - @Override - public AspectKey deserialize(DeserializationContext context, CodedInputStream codedIn) - throws SerializationException, IOException { - return createAspectKey( - Label.CODEC.deserialize(context, codedIn), - ConfiguredTargetKey.CODEC.deserialize(context, codedIn), - listCodec.deserialize(context, codedIn), - AspectDescriptor.CODEC.deserialize(context, codedIn), - Key.CODEC.deserialize(context, codedIn), - codedIn.readBool()); - } - } - /** * The key for a skylark aspect. */ @@ -404,7 +395,7 @@ public final class AspectValue extends ActionLookupValue { } AspectKey toAspectKey(AspectClass aspectClass) { - return createAspectKey( + return AspectKey.createAspectKey( targetLabel, baseConfiguredTargetKey, ImmutableList.of(), @@ -531,7 +522,7 @@ public final class AspectValue extends ActionLookupValue { AspectDescriptor aspectDescriptor, BuildConfiguration aspectConfiguration) { KeyAndHost aspectKeyAndHost = ConfiguredTargetKey.keyFromConfiguration(aspectConfiguration); - return createAspectKey( + return AspectKey.createAspectKey( label, ConfiguredTargetKey.of(label, baseConfiguration), baseKeys, @@ -548,7 +539,7 @@ public final class AspectValue extends ActionLookupValue { AspectDescriptor aspectDescriptor, BuildConfiguration aspectConfiguration) { KeyAndHost aspectKeyAndHost = ConfiguredTargetKey.keyFromConfiguration(aspectConfiguration); - return createAspectKey( + return AspectKey.createAspectKey( label, ConfiguredTargetKey.of(label, baseConfiguration), ImmutableList.of(), @@ -557,21 +548,6 @@ public final class AspectValue extends ActionLookupValue { aspectKeyAndHost.isHost); } - private static AspectKey createAspectKey( - Label label, - ConfiguredTargetKey configuredTargetKey, - ImmutableList<AspectKey> aspectKeys, - AspectDescriptor aspectDescriptor, - BuildConfigurationValue.Key aspectConfigurationKey, - boolean aspectConfigurationIsHost) { - return aspectKeyInterner.intern( - aspectConfigurationIsHost - ? new HostAspectKey( - label, aspectConfigurationKey, configuredTargetKey, aspectKeys, aspectDescriptor) - : new AspectKey( - label, aspectConfigurationKey, configuredTargetKey, aspectKeys, aspectDescriptor)); - } - private static final Interner<SkylarkAspectLoadingKey> skylarkAspectKeyInterner = BlazeInterners.newWeakInterner(); |