Restructure proto test dependencies This groups all proto dependencies in third_party/proto and splits the existing third_party/proto dependency into third_party/proto/test/proto2 and third_party/proto/test/proto3. This is in preparation for adding third_party/proto/test/edition2023 and third_party/proto/runtime/edition2023. Change-Id: I761f1d0af0b6ecef327f9aa406f30385747da548
diff --git a/.gitignore b/.gitignore index bb6648e..8114ef4 100644 --- a/.gitignore +++ b/.gitignore
@@ -273,10 +273,12 @@ third_party/proguard/* third_party/proguardsettings.tar.gz third_party/proguardsettings/ -third_party/proto.tar.gz -third_party/proto/ -third_party/protobuf-lite.tar.gz -third_party/protobuf-lite/ +third_party/proto/runtime/legacy +third_party/proto/runtime/legacy.tar.gz +third_party/proto/test/proto2 +third_party/proto/test/proto2.tar.gz +third_party/proto/test/proto3 +third_party/proto/test/proto3.tar.gz third_party/r8 third_party/r8.tar.gz third_party/r8-releases/2.0.74
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt index bdbd79e..2620a18 100644 --- a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt +++ b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
@@ -614,15 +614,20 @@ Paths.get("third_party", "proguardsettings").toFile(), Paths.get("third_party", "proguardsettings.tar.gz.sha1").toFile(), DependencyType.X20) - val proto = ThirdPartyDependency( - "proto", - Paths.get("third_party", "proto").toFile(), - Paths.get("third_party", "proto.tar.gz.sha1").toFile(), + val protoRuntimeLegacy = ThirdPartyDependency( + "protoRuntimeLegacy", + Paths.get("third_party", "proto", "runtime", "legacy").toFile(), + Paths.get("third_party", "proto", "runtime", "legacy.tar.gz.sha1").toFile(), DependencyType.X20) - val protobufLite = ThirdPartyDependency( - "protobuf-lite", - Paths.get("third_party", "protobuf-lite").toFile(), - Paths.get("third_party", "protobuf-lite.tar.gz.sha1").toFile(), + val protoTestProto2 = ThirdPartyDependency( + "protoTestProto2", + Paths.get("third_party", "proto", "test", "proto2").toFile(), + Paths.get("third_party", "proto", "test", "proto2.tar.gz.sha1").toFile(), + DependencyType.X20) + val protoTestProto3 = ThirdPartyDependency( + "protoTestProto3", + Paths.get("third_party", "proto", "test", "proto3").toFile(), + Paths.get("third_party", "proto", "test", "proto3.tar.gz.sha1").toFile(), DependencyType.X20) val r8 = ThirdPartyDependency( "r8",
diff --git a/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderOnlyReferencedFromDynamicMethodTest.java b/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderOnlyReferencedFromDynamicMethodTest.java index 53e5b8a..ed6f6fd 100644 --- a/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderOnlyReferencedFromDynamicMethodTest.java +++ b/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderOnlyReferencedFromDynamicMethodTest.java
@@ -14,38 +14,31 @@ import com.android.tools.r8.TestParametersCollection; import com.android.tools.r8.utils.codeinspector.ClassSubject; import com.android.tools.r8.utils.codeinspector.CodeInspector; -import com.google.common.collect.ImmutableList; -import java.nio.file.Path; -import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class Proto2BuilderOnlyReferencedFromDynamicMethodTest extends ProtoShrinkingTestBase { private static final String MAIN = "proto2.BuilderOnlyReferencedFromDynamicMethodTestClass"; - private static List<Path> PROGRAM_FILES = - ImmutableList.of(PROTO2_EXAMPLES_JAR, PROTO2_PROTO_JAR, PROTOBUF_LITE_JAR); + @Parameter(0) + public TestParameters parameters; - private final TestParameters parameters; - - @Parameterized.Parameters(name = "{0}") + @Parameters(name = "{0}") public static TestParametersCollection data() { return getTestParameters().withDefaultDexRuntime().withAllApiLevels().build(); } - public Proto2BuilderOnlyReferencedFromDynamicMethodTest(TestParameters parameters) { - this.parameters = parameters; - } - @Test public void test() throws Exception { testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto2TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule(MAIN) - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) .allowAccessModification() .allowDiagnosticMessages() .allowUnusedDontWarnPatterns()
diff --git a/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderShrinkingTest.java b/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderShrinkingTest.java index c786a4b..abedac8 100644 --- a/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderShrinkingTest.java +++ b/src/test/java/com/android/tools/r8/internal/proto/Proto2BuilderShrinkingTest.java
@@ -20,7 +20,6 @@ import com.android.tools.r8.utils.codeinspector.InstructionSubject; import com.android.tools.r8.utils.codeinspector.MethodSubject; import com.google.common.collect.ImmutableList; -import java.nio.file.Path; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -71,9 +70,6 @@ private static final String METHOD_TO_INVOKE_ENUM = "com.google.protobuf.GeneratedMessageLite$MethodToInvoke"; - private static List<Path> PROGRAM_FILES = - ImmutableList.of(PROTO2_EXAMPLES_JAR, PROTO2_PROTO_JAR, PROTOBUF_LITE_JAR); - @Parameter(0) public MainClassesConfig config; @@ -91,9 +87,9 @@ public void test() throws Exception { R8TestCompileResult result = testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto2TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRules(config.getMainClasses()) - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) .allowAccessModification() .allowDiagnosticMessages() .allowUnusedDontWarnPatterns()
diff --git a/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java b/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java index 270116a..462515f 100644 --- a/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java +++ b/src/test/java/com/android/tools/r8/internal/proto/Proto2ShrinkingTest.java
@@ -21,11 +21,12 @@ import com.android.tools.r8.utils.codeinspector.analysis.ProtoApplicationStats; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import java.nio.file.Path; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class Proto2ShrinkingTest extends ProtoShrinkingTestBase { @@ -50,14 +51,16 @@ private static final String USES_ONLY_REPEATED_FIELDS = "com.android.tools.r8.proto2.Shrinking$UsesOnlyRepeatedFields"; - private static List<Path> PROGRAM_FILES = - ImmutableList.of(PROTO2_EXAMPLES_JAR, PROTO2_PROTO_JAR, PROTOBUF_LITE_JAR); + @Parameter(0) + public boolean allowAccessModification; - private final boolean allowAccessModification; - private final boolean enableMinification; - private final TestParameters parameters; + @Parameter(1) + public boolean enableMinification; - @Parameterized.Parameters(name = "{2}, allow access modification: {0}, enable minification: {1}") + @Parameter(2) + public TestParameters parameters; + + @Parameters(name = "{2}, allow access modification: {0}, enable minification: {1}") public static List<Object[]> data() { return buildParameters( BooleanUtils.values(), @@ -65,21 +68,13 @@ getTestParameters().withDefaultDexRuntime().withAllApiLevels().build()); } - public Proto2ShrinkingTest( - boolean allowAccessModification, boolean enableMinification, TestParameters parameters) { - this.allowAccessModification = allowAccessModification; - this.enableMinification = enableMinification; - this.parameters = parameters; - } - @Test public void test() throws Exception { - CodeInspector inputInspector = new CodeInspector(PROGRAM_FILES); R8TestRunResult result = testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto2TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule("proto2.TestClass") - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) // TODO(b/173340579): This rule should not be needed to allow shrinking of // PartiallyUsed$Enum. .addNoHorizontalClassMergingRule(PARTIALLY_USED + "$Enum$1") @@ -97,6 +92,7 @@ .apply(this::inspectWarningMessages) .inspect( outputInspector -> { + CodeInspector inputInspector = getProto2TestSourcesInspector(); verifyMapAndRequiredFieldsAreKept(inputInspector, outputInspector); verifyUnusedExtensionsAreRemoved(inputInspector, outputInspector); verifyUnusedFieldsAreRemoved(inputInspector, outputInspector); @@ -133,7 +129,8 @@ "10"); DexItemFactory dexItemFactory = new DexItemFactory(); - ProtoApplicationStats original = new ProtoApplicationStats(dexItemFactory, inputInspector); + ProtoApplicationStats original = + new ProtoApplicationStats(dexItemFactory, getProto2TestSourcesInspector()); ProtoApplicationStats actual = new ProtoApplicationStats(dexItemFactory, result.inspector(), original); @@ -375,9 +372,9 @@ @Test public void testNoRewriting() throws Exception { testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto2TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule("proto2.TestClass") - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) // Retain all protos. .addKeepRules(keepAllProtosRule()) // Retain the signature of dynamicMethod() and newMessageInfo(). @@ -395,16 +392,15 @@ .apply(this::inspectWarningMessages) .inspect( inspector -> - assertRewrittenProtoSchemasMatch(new CodeInspector(PROGRAM_FILES), inspector)); + assertRewrittenProtoSchemasMatch(getProto2TestSourcesInspector(), inspector)); } @Test public void testTwoExtensionRegistrys() throws Exception { - CodeInspector inputInspector = new CodeInspector(PROGRAM_FILES); testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto2TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule("proto2.TestClass") - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) .addKeepRules(findLiteExtensionByNumberInDuplicateCalledRule()) // TODO(b/173340579): This rule should not be needed to allow shrinking of // PartiallyUsed$Enum. @@ -422,6 +418,7 @@ .apply(this::inspectWarningMessages) .inspect( outputInspector -> { + CodeInspector inputInspector = getProto2TestSourcesInspector(); verifyUnusedExtensionsAreRemoved(inputInspector, outputInspector); verifyUnusedExtensionsAreRemoved( inputInspector,
diff --git a/src/test/java/com/android/tools/r8/internal/proto/Proto3ShrinkingTest.java b/src/test/java/com/android/tools/r8/internal/proto/Proto3ShrinkingTest.java index b390c77..49fdd08 100644 --- a/src/test/java/com/android/tools/r8/internal/proto/Proto3ShrinkingTest.java +++ b/src/test/java/com/android/tools/r8/internal/proto/Proto3ShrinkingTest.java
@@ -16,8 +16,6 @@ import com.android.tools.r8.utils.BooleanUtils; import com.android.tools.r8.utils.codeinspector.ClassSubject; import com.android.tools.r8.utils.codeinspector.CodeInspector; -import com.google.common.collect.ImmutableList; -import java.nio.file.Path; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,9 +27,6 @@ private static final String PARTIALLY_USED = "com.android.tools.r8.proto3.Shrinking$PartiallyUsed"; - private static List<Path> PROGRAM_FILES = - ImmutableList.of(PROTO3_EXAMPLES_JAR, PROTO3_PROTO_JAR, PROTOBUF_LITE_JAR); - private final boolean allowAccessModification; private final boolean enableMinification; private final TestParameters parameters; @@ -53,11 +48,10 @@ @Test public void test() throws Exception { - CodeInspector inputInspector = new CodeInspector(PROGRAM_FILES); testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto3TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule("proto3.TestClass") - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) .allowAccessModification(allowAccessModification) .allowDiagnosticMessages() .allowUnusedDontWarnPatterns() @@ -71,6 +65,7 @@ .assertAllWarningMessagesMatch(equalTo("Resource 'META-INF/MANIFEST.MF' already exists.")) .inspect( outputInspector -> { + CodeInspector inputInspector = getProto3TestSourcesInspector(); verifyUnusedFieldsAreRemoved(inputInspector, outputInspector); }) .run(parameters.getRuntime(), "proto3.TestClass") @@ -100,9 +95,9 @@ @Test public void testNoRewriting() throws Exception { testForR8(parameters.getBackend()) - .addProgramFiles(PROGRAM_FILES) + .apply(this::addProto3TestSources) + .apply(this::addLegacyRuntime) .addKeepMainRule("proto3.TestClass") - .addKeepRuleFiles(PROTOBUF_LITE_PROGUARD_RULES) // Retain all protos. .addKeepRules(keepAllProtosRule()) // Retain the signature of dynamicMethod() and newMessageInfo(). @@ -123,6 +118,6 @@ containsString("required for default or static interface methods desugaring"))) .inspect( inspector -> - assertRewrittenProtoSchemasMatch(new CodeInspector(PROGRAM_FILES), inspector)); + assertRewrittenProtoSchemasMatch(getProto3TestSourcesInspector(), inspector)); } }
diff --git a/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java b/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java index f0db90b..cd21b9f 100644 --- a/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java +++ b/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java
@@ -11,9 +11,10 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.startsWith; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import com.android.tools.r8.R8TestBuilder; import com.android.tools.r8.R8TestCompileResult; import com.android.tools.r8.TestBase; import com.android.tools.r8.ToolHelper; @@ -27,43 +28,24 @@ import com.android.tools.r8.utils.codeinspector.CodeInspector; import com.android.tools.r8.utils.codeinspector.FoundClassSubject; import com.android.tools.r8.utils.codeinspector.FoundMethodSubject; +import com.google.common.collect.ImmutableList; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collection; import java.util.HashMap; import java.util.Map; public abstract class ProtoShrinkingTestBase extends TestBase { - public static final Path PROTOBUF_LITE_JAR = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "protobuf-lite/libprotobuf_lite.jar"); - - public static final Path PROTOBUF_LITE_PROGUARD_RULES = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "protobuf-lite/lite_proguard.pgcfg"); - - // Test classes for proto2. Use a checked in version of the built examples. - public static final Path PROTO2_EXAMPLES_JAR = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "proto", "examplesProto2.jar"); - - // Proto definitions used by test classes for proto2. - public static final Path PROTO2_PROTO_JAR = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "proto", "examplesGeneratedProto2.jar"); - - // Test classes for proto3. - public static final Path PROTO3_EXAMPLES_JAR = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "proto", "examplesProto3.jar"); - - // Proto definitions used by test classes for proto3. - public static final Path PROTO3_PROTO_JAR = - Paths.get(ToolHelper.THIRD_PARTY_DIR, "proto", "examplesGeneratedProto3.jar"); - public static void assertRewrittenProtoSchemasMatch( CodeInspector expectedInspector, CodeInspector actualInspector) throws Exception { Map<String, IntList> actualInfos = getInfoValues(actualInspector); // Ensure that this cannot fail silently. - assertTrue(actualInfos.size() > 0); + assertFalse(actualInfos.isEmpty()); Map<String, IntList> expectedInfos = getInfoValues(expectedInspector); for (Map.Entry<String, IntList> entry : actualInfos.entrySet()) { @@ -75,6 +57,47 @@ } } + void addLegacyRuntime(R8TestBuilder<?> testBuilder) { + Path runtimeDir = Paths.get(ToolHelper.PROTO_RUNTIME_DIR, "legacy"); + addRuntime(testBuilder, runtimeDir); + } + + private void addRuntime(R8TestBuilder<?> testBuilder, Path runtimeDir) { + testBuilder + .addProgramFiles(runtimeDir.resolve("libprotobuf_lite.jar")) + .addKeepRuleFiles(runtimeDir.resolve("lite_proguard.pgcfg")); + } + + void addProto2TestSources(R8TestBuilder<?> testBuilder) { + testBuilder.addProgramFiles(getProto2TestSources()); + } + + void addProto3TestSources(R8TestBuilder<?> testBuilder) { + testBuilder.addProgramFiles(getProto3TestSources()); + } + + private Collection<Path> getProto2TestSources() { + Path testDir = Paths.get(ToolHelper.PROTO_TEST_DIR, "proto2"); + return getTestSources(testDir); + } + + private Collection<Path> getProto3TestSources() { + Path testDir = Paths.get(ToolHelper.PROTO_TEST_DIR, "proto3"); + return getTestSources(testDir); + } + + private Collection<Path> getTestSources(Path testDir) { + return ImmutableList.of(testDir.resolve("proto.jar"), testDir.resolve("test.jar")); + } + + CodeInspector getProto2TestSourcesInspector() throws IOException { + return new CodeInspector(getProto2TestSources()); + } + + CodeInspector getProto3TestSourcesInspector() throws IOException { + return new CodeInspector(getProto3TestSources()); + } + static String findLiteExtensionByNumberInDuplicateCalledRule() { return StringUtils.lines( "-keep class com.google.protobuf.proto2_registryGeneratedExtensionRegistryLiteDuplicate {",
diff --git a/src/test/testbase/java/com/android/tools/r8/ToolHelper.java b/src/test/testbase/java/com/android/tools/r8/ToolHelper.java index b8eb897..8fd3b6b 100644 --- a/src/test/testbase/java/com/android/tools/r8/ToolHelper.java +++ b/src/test/testbase/java/com/android/tools/r8/ToolHelper.java
@@ -186,6 +186,9 @@ public static final String LIBS_DIR = BUILD_DIR + "libs/"; public static final String THIRD_PARTY_DIR = getProjectRoot() + "third_party/"; public static final String DEPENDENCIES = THIRD_PARTY_DIR + "dependencies/"; + public static final String PROTO_DIR = THIRD_PARTY_DIR + "proto/"; + public static final String PROTO_RUNTIME_DIR = PROTO_DIR + "runtime/"; + public static final String PROTO_TEST_DIR = PROTO_DIR + "test/"; public static final String TOOLS_DIR = getProjectRoot() + "tools/"; public static final String TESTS_DIR = getProjectRoot() + "src/test/"; public static final String ART_TESTS_ROOT = getProjectRoot() + "tests/";
diff --git a/third_party/proto.tar.gz.sha1 b/third_party/proto.tar.gz.sha1 deleted file mode 100644 index 5d43e3e..0000000 --- a/third_party/proto.tar.gz.sha1 +++ /dev/null
@@ -1 +0,0 @@ -c8330e345ab2a6d0ef90f0b3232e03e072d5a234 \ No newline at end of file
diff --git a/third_party/proto/runtime/legacy.tar.gz.sha1 b/third_party/proto/runtime/legacy.tar.gz.sha1 new file mode 100644 index 0000000..297987d --- /dev/null +++ b/third_party/proto/runtime/legacy.tar.gz.sha1
@@ -0,0 +1 @@ +798c2243e9aca81f1e2ee19392a0fef65122faed \ No newline at end of file
diff --git a/third_party/proto/test/proto2.tar.gz.sha1 b/third_party/proto/test/proto2.tar.gz.sha1 new file mode 100644 index 0000000..50f5c12 --- /dev/null +++ b/third_party/proto/test/proto2.tar.gz.sha1
@@ -0,0 +1 @@ +1c5e343395ba01cc37b9ec264b2af75f58bd08bc \ No newline at end of file
diff --git a/third_party/proto/test/proto3.tar.gz.sha1 b/third_party/proto/test/proto3.tar.gz.sha1 new file mode 100644 index 0000000..815a03a --- /dev/null +++ b/third_party/proto/test/proto3.tar.gz.sha1
@@ -0,0 +1 @@ +4540501e8fbd15b555db561168595d73f39328a9 \ No newline at end of file
diff --git a/third_party/protobuf-lite.tar.gz.sha1 b/third_party/protobuf-lite.tar.gz.sha1 deleted file mode 100644 index 77f4e56..0000000 --- a/third_party/protobuf-lite.tar.gz.sha1 +++ /dev/null
@@ -1 +0,0 @@ -047e2914d6898dc764803e7709eda60f7de1ecfa \ No newline at end of file