Skip to content

Commit

Permalink
Add codec for ConfiguredTargetKey and remove stray LegacySkyKey const…
Browse files Browse the repository at this point in the history
…ructors that took ConfiguredTargetKey.

PiperOrigin-RevId: 183519981
  • Loading branch information
janakdr authored and Copybara-Service committed Jan 27, 2018
1 parent 12f8274 commit 4da310b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
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.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
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;

Expand All @@ -31,6 +36,8 @@
* action of an artifact.
*/
public class ConfiguredTargetKey extends ActionLookupKey {
public static final ObjectCodec<ConfiguredTargetKey> CODEC = Codec.INSTANCE;

private final Label label;
@Nullable private final BuildConfigurationValue.Key configurationKey;

Expand Down Expand Up @@ -192,4 +199,37 @@ private KeyAndHost(@Nullable BuildConfigurationValue.Key key, boolean isHost) {
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(ConfiguredTargetKey obj, CodedOutputStream codedOut)
throws SerializationException, IOException {
Label.CODEC.serialize(obj.label, codedOut);
if (obj.configurationKey == null) {
codedOut.writeBoolNoTag(false);
} else {
codedOut.writeBoolNoTag(true);
BuildConfigurationValue.Key.CODEC.serialize(obj.configurationKey, codedOut);
}
codedOut.writeBoolNoTag(obj.isHostConfiguration());
}

@Override
public ConfiguredTargetKey deserialize(CodedInputStream codedIn)
throws SerializationException, IOException {
return of(
Label.CODEC.deserialize(codedIn),
codedIn.readBool() ? BuildConfigurationValue.Key.CODEC.deserialize(codedIn) : null,
codedIn.readBool());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
Expand Down Expand Up @@ -92,11 +91,7 @@ private ImmutableList<PlatformInfo> configureRegisteredExecutionPlatforms(
ImmutableList<SkyKey> keys =
labels
.stream()
.map(
label ->
LegacySkyKey.create(
SkyFunctions.CONFIGURED_TARGET,
ConfiguredTargetKey.of(label, configuration)))
.map(label -> ConfiguredTargetKey.of(label, configuration))
.collect(ImmutableList.toImmutableList());

Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
Expand Down Expand Up @@ -102,11 +101,7 @@ private ImmutableList<DeclaredToolchainInfo> configureRegisteredToolchains(
ImmutableList<SkyKey> keys =
labels
.stream()
.map(
label ->
LegacySkyKey.create(
SkyFunctions.CONFIGURED_TARGET,
ConfiguredTargetKey.of(label, configuration)))
.map(label -> ConfiguredTargetKey.of(label, configuration))
.collect(ImmutableList.toImmutableList());

Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.devtools.build.lib.skyframe.ToolchainResolutionFunction.NoToolchainFoundException;
import com.google.devtools.build.lib.skyframe.ToolchainResolutionValue.ToolchainResolutionKey;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.skyframe.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.ValueOrException;
Expand Down Expand Up @@ -141,14 +140,8 @@ private static PlatformDescriptors loadPlatformDescriptors(
Label executionPlatformLabel = platformConfiguration.getExecutionPlatform();
Label targetPlatformLabel = platformConfiguration.getTargetPlatforms().get(0);

SkyKey executionPlatformKey =
LegacySkyKey.create(
SkyFunctions.CONFIGURED_TARGET,
ConfiguredTargetKey.of(executionPlatformLabel, configuration));
SkyKey targetPlatformKey =
LegacySkyKey.create(
SkyFunctions.CONFIGURED_TARGET,
ConfiguredTargetKey.of(targetPlatformLabel, configuration));
SkyKey executionPlatformKey = ConfiguredTargetKey.of(executionPlatformLabel, configuration);
SkyKey targetPlatformKey = ConfiguredTargetKey.of(targetPlatformLabel, configuration);

Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values =
env.getValuesOrThrow(
Expand Down

0 comments on commit 4da310b

Please sign in to comment.