diff options
author | 2018-02-13 12:53:31 -0800 | |
---|---|---|
committer | 2018-02-13 12:55:25 -0800 | |
commit | 1b78769afd36b979a1e29116f5878551bdd29ddd (patch) | |
tree | 0278d35461b479230221d1a901bb40485bf71f79 /src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java | |
parent | 6f9416ed9f966a153a3cb85b25104af059f4eb0a (diff) |
Add ability to use getter in AutoCodecProcessor when field for instantiator parameter isn't present. Allows us to handle cases where the class type encodes the parameter value. This also gives a compile-time check that field is present before blindly using it in codec.
Lets us get rid of a non-AutoCodec class.
PiperOrigin-RevId: 185573686
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java index 5cdf67cd31..33d29d3461 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java @@ -22,14 +22,9 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.BlazeInterners; -import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext; 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.skyframe.SkyFunctionName; -import com.google.protobuf.CodedInputStream; -import com.google.protobuf.CodedOutputStream; -import java.io.IOException; import java.util.Objects; import javax.annotation.Nullable; @@ -37,8 +32,9 @@ import javax.annotation.Nullable; * A (Label, Configuration key) pair. Note that this pair may be used to look up the generating * action of an artifact. */ +@AutoCodec public class ConfiguredTargetKey extends ActionLookupKey { - public static final ObjectCodec<ConfiguredTargetKey> CODEC = Codec.INSTANCE; + public static final ObjectCodec<ConfiguredTargetKey> CODEC = new ConfiguredTargetKey_AutoCodec(); private final Label label; @Nullable private final BuildConfigurationValue.Key configurationKey; @@ -70,6 +66,7 @@ public class ConfiguredTargetKey extends ActionLookupKey { return of(label, keyAndHost.key, keyAndHost.isHost); } + @AutoCodec.Instantiator static ConfiguredTargetKey of( Label label, @Nullable BuildConfigurationValue.Key configurationKey, @@ -201,40 +198,4 @@ public class ConfiguredTargetKey extends ActionLookupKey { this.isHost = isHost; } } - - private static final class Codec implements ObjectCodec<ConfiguredTargetKey> { - private static final Codec INSTANCE = new Codec(); - - private Codec() {} - - @Override - public Class<ConfiguredTargetKey> getEncodedClass() { - return ConfiguredTargetKey.class; - } - - @Override - public void serialize( - SerializationContext context, ConfiguredTargetKey obj, CodedOutputStream codedOut) - throws SerializationException, IOException { - Label.CODEC.serialize(context, obj.label, codedOut); - if (obj.configurationKey == null) { - codedOut.writeBoolNoTag(false); - } else { - codedOut.writeBoolNoTag(true); - BuildConfigurationValue.Key.CODEC.serialize(context, obj.configurationKey, codedOut); - } - codedOut.writeBoolNoTag(obj.isHostConfiguration()); - } - - @Override - public ConfiguredTargetKey deserialize(DeserializationContext context, CodedInputStream codedIn) - throws SerializationException, IOException { - return of( - Label.CODEC.deserialize(context, codedIn), - codedIn.readBool() - ? BuildConfigurationValue.Key.CODEC.deserialize(context, codedIn) - : null, - codedIn.readBool()); - } - } } |