Skip to content

Commit

Permalink
Add codec for JavaToolchainTool.
Browse files Browse the repository at this point in the history
The commandLineCache needs to be re-initialized on deserialization.

PiperOrigin-RevId: 567619611
Change-Id: I97c373693322a390be156a7e9043479ed5684356
  • Loading branch information
aoeui authored and copybara-github committed Sep 22, 2023
1 parent c6c1d96 commit 8a46515
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
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.util.Pair;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.errorprone.annotations.Keep;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import javax.annotation.Nullable;

/** An executable tool that is part of {@code java_toolchain}. */
Expand Down Expand Up @@ -156,4 +164,28 @@ void addInputs(JavaToolchainProvider toolchain, NestedSetBuilder<Artifact> input
inputs.add(executable).addTransitive(toolchain.getJavaRuntime().javaBaseInputs());
}
}

@Keep // Accessed reflectively.
private static class Codec implements ObjectCodec<JavaToolchainTool> {
@Override
public Class<JavaToolchainTool> getEncodedClass() {
return JavaToolchainTool.class;
}

@Override
public void serialize(
SerializationContext context, JavaToolchainTool obj, CodedOutputStream codedOut)
throws SerializationException, IOException {
context.serialize(obj.tool(), codedOut);
context.serialize(obj.data(), codedOut);
context.serialize(obj.jvmOpts(), codedOut);
}

@Override
public JavaToolchainTool deserialize(DeserializationContext context, CodedInputStream codedIn)
throws SerializationException, IOException {
return create(
context.deserialize(codedIn), context.deserialize(codedIn), context.deserialize(codedIn));
}
}
}

0 comments on commit 8a46515

Please sign in to comment.