aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigProtoCodecRegisterer.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/serialization/JavaSerializableCodec.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java16
3 files changed, 35 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigProtoCodecRegisterer.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigProtoCodecRegisterer.java
index bad9dc0319..1e5c2fcbb5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigProtoCodecRegisterer.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigProtoCodecRegisterer.java
@@ -26,6 +26,16 @@ class CrosstoolConfigProtoCodecRegisterer implements CodecRegisterer<MessageLite
new MessageLiteCodec(CrosstoolConfig.CrosstoolRelease::newBuilder),
new MessageLiteCodec(CrosstoolConfig.CToolchain::newBuilder),
new MessageLiteCodec(CrosstoolConfig.CToolchain.OptionalFlag::newBuilder),
- new MessageLiteCodec(CrosstoolConfig.CToolchain.Tool::newBuilder));
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.FlagGroup::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.VariableWithValue::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.EnvEntry::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.FeatureSet::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.WithFeatureSet::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.FlagSet::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.EnvSet::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.Feature::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.Tool::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.ArtifactNamePattern::newBuilder),
+ new MessageLiteCodec(CrosstoolConfig.CToolchain.ActionConfig::newBuilder));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/JavaSerializableCodec.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/JavaSerializableCodec.java
index 487feab4a1..8e304e53c8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/JavaSerializableCodec.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/JavaSerializableCodec.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.skyframe.serialization;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
+import com.google.protobuf.MessageLite;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.NotSerializableException;
@@ -27,6 +28,10 @@ import java.nio.ByteBuffer;
/** Naive ObjectCodec using Java native Serialization. Not performant, but a good fallback */
class JavaSerializableCodec implements ObjectCodec<Object> {
+ private boolean isBlacklistedForJavaSerialization(Class<?> clazz) {
+ return MessageLite.class.isAssignableFrom(clazz);
+ }
+
@Override
public Class<Object> getEncodedClass() {
return Object.class;
@@ -35,6 +40,10 @@ class JavaSerializableCodec implements ObjectCodec<Object> {
@Override
public void serialize(SerializationContext context, Object obj, CodedOutputStream codedOut)
throws SerializationException, IOException {
+ if (isBlacklistedForJavaSerialization(obj.getClass())) {
+ throw new SerializationException(
+ "Java serialization is not permitted for class " + obj.getClass());
+ }
ByteString.Output out = ByteString.newOutput();
ObjectOutputStream objOut = new ObjectOutputStream(out);
try {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
index 01a50fc72b..5cdc60419b 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
@@ -37,6 +38,8 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.Str
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StructureBuilder;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValueBuilder;
+import com.google.devtools.build.lib.skyframe.serialization.AutoRegistry;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecs;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.lib.testutil.TestUtils;
@@ -118,7 +121,7 @@ public class CcToolchainFeaturesTest extends FoundationTestCase {
}
@Test
- public void testCodec() throws Exception {
+ public void testFeatureConfigurationCodec() throws Exception {
FeatureConfiguration emptyConfiguration =
buildFeatures("").getFeatureConfiguration(ImmutableSet.of());
FeatureConfiguration emptyFeatures =
@@ -162,6 +165,17 @@ public class CcToolchainFeaturesTest extends FoundationTestCase {
}
@Test
+ public void testCrosstoolProtoCanBeSerialized() throws Exception {
+ ObjectCodecs objectCodecs =
+ new ObjectCodecs(AutoRegistry.get().getBuilder().build(), ImmutableMap.of());
+ objectCodecs.serialize(CToolchain.WithFeatureSet.getDefaultInstance());
+ objectCodecs.serialize(CToolchain.VariableWithValue.getDefaultInstance());
+ objectCodecs.serialize(CToolchain.FlagGroup.getDefaultInstance());
+ objectCodecs.serialize(CToolchain.FlagSet.getDefaultInstance());
+ objectCodecs.serialize(CToolchain.EnvSet.getDefaultInstance());
+ }
+
+ @Test
public void testUnconditionalFeature() throws Exception {
assertThat(buildFeatures("").getFeatureConfiguration(ImmutableSet.of("a")).isEnabled("a"))
.isFalse();