summaryrefslogtreecommitdiff
path: root/java/dex_test.go
diff options
context:
space:
mode:
author Sam Delmerico <delmerico@google.com> 2023-10-31 17:27:02 +0000
committer Sam Delmerico <delmerico@google.com> 2023-10-31 18:59:04 +0000
commitc8e040c70fcaa9531c4123df6f12dd229c6d4ba0 (patch)
tree37db4b1ef6675026ebd5de5670baa9ab7c709a17 /java/dex_test.go
parent82f0f7eca194357145d2dc8beb3efa6b7d9c7383 (diff)
transitive r8 flags for installable {android,java}_libraries
Only android_apps were actually applying transitive proguard flags files to their r8 invocation. This CL ensures that this also occurs for installable android_libraries and java_libraries. Bug: 302342049 Test: go test ./java Change-Id: Ie94d688d04367ee3d39e7e760fb3003df5829951
Diffstat (limited to 'java/dex_test.go')
-rw-r--r--java/dex_test.go134
1 files changed, 86 insertions, 48 deletions
diff --git a/java/dex_test.go b/java/dex_test.go
index ec1ef1516..1ecdae0c5 100644
--- a/java/dex_test.go
+++ b/java/dex_test.go
@@ -385,13 +385,53 @@ func TestProguardFlagsInheritanceStatic(t *testing.T) {
func TestProguardFlagsInheritance(t *testing.T) {
directDepFlagsFileName := "direct_dep.flags"
transitiveDepFlagsFileName := "transitive_dep.flags"
- bp := `
- android_app {
- name: "app",
- static_libs: ["androidlib"], // this must be static_libs to initate dexing
- platform_apis: true,
- }
+ topLevelModules := []struct {
+ name string
+ definition string
+ }{
+ {
+ name: "android_app",
+ definition: `
+ android_app {
+ name: "app",
+ static_libs: ["androidlib"], // this must be static_libs to initate dexing
+ platform_apis: true,
+ }
+ `,
+ },
+ {
+ name: "android_library",
+ definition: `
+ android_library {
+ name: "app",
+ static_libs: ["androidlib"], // this must be static_libs to initate dexing
+ installable: true,
+ optimize: {
+ enabled: true,
+ shrink: true,
+ },
+ }
+ `,
+ },
+ {
+ name: "java_library",
+ definition: `
+ java_library {
+ name: "app",
+ static_libs: ["androidlib"], // this must be static_libs to initate dexing
+ srcs: ["Foo.java"],
+ installable: true,
+ optimize: {
+ enabled: true,
+ shrink: true,
+ },
+ }
+ `,
+ },
+ }
+
+ bp := `
android_library {
name: "androidlib",
static_libs: ["app_dep"],
@@ -558,43 +598,46 @@ func TestProguardFlagsInheritance(t *testing.T) {
},
}
- for _, tc := range testcases {
- t.Run(tc.name, func(t *testing.T) {
- result := android.GroupFixturePreparers(
- PrepareForTestWithJavaDefaultModules,
- android.FixtureMergeMockFs(android.MockFS{
- directDepFlagsFileName: nil,
- transitiveDepFlagsFileName: nil,
- }),
- ).RunTestWithBp(t,
- fmt.Sprintf(
- bp,
- tc.depType,
- tc.transitiveDepType,
- tc.depExportsFlagsFiles,
- tc.transitiveDepExportsFlagsFiles,
- ),
- )
- appR8 := result.ModuleForTests("app", "android_common").Rule("r8")
-
- shouldHaveDepFlags := android.InList(directDepFlagsFileName, tc.expectedFlagsFiles)
- if shouldHaveDepFlags {
- android.AssertStringDoesContain(t, "expected deps's proguard flags",
- appR8.Args["r8Flags"], directDepFlagsFileName)
- } else {
- android.AssertStringDoesNotContain(t, "app did not expect deps's proguard flags",
- appR8.Args["r8Flags"], directDepFlagsFileName)
- }
-
- shouldHaveTransitiveDepFlags := android.InList(transitiveDepFlagsFileName, tc.expectedFlagsFiles)
- if shouldHaveTransitiveDepFlags {
- android.AssertStringDoesContain(t, "expected transitive deps's proguard flags",
- appR8.Args["r8Flags"], transitiveDepFlagsFileName)
- } else {
- android.AssertStringDoesNotContain(t, "app did not expect transitive deps's proguard flags",
- appR8.Args["r8Flags"], transitiveDepFlagsFileName)
- }
- })
+ for _, topLevelModuleDef := range topLevelModules {
+ for _, tc := range testcases {
+ t.Run(topLevelModuleDef.name+"-"+tc.name, func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ android.FixtureMergeMockFs(android.MockFS{
+ directDepFlagsFileName: nil,
+ transitiveDepFlagsFileName: nil,
+ }),
+ ).RunTestWithBp(t,
+ topLevelModuleDef.definition+
+ fmt.Sprintf(
+ bp,
+ tc.depType,
+ tc.transitiveDepType,
+ tc.depExportsFlagsFiles,
+ tc.transitiveDepExportsFlagsFiles,
+ ),
+ )
+ appR8 := result.ModuleForTests("app", "android_common").Rule("r8")
+
+ shouldHaveDepFlags := android.InList(directDepFlagsFileName, tc.expectedFlagsFiles)
+ if shouldHaveDepFlags {
+ android.AssertStringDoesContain(t, "expected deps's proguard flags",
+ appR8.Args["r8Flags"], directDepFlagsFileName)
+ } else {
+ android.AssertStringDoesNotContain(t, "app did not expect deps's proguard flags",
+ appR8.Args["r8Flags"], directDepFlagsFileName)
+ }
+
+ shouldHaveTransitiveDepFlags := android.InList(transitiveDepFlagsFileName, tc.expectedFlagsFiles)
+ if shouldHaveTransitiveDepFlags {
+ android.AssertStringDoesContain(t, "expected transitive deps's proguard flags",
+ appR8.Args["r8Flags"], transitiveDepFlagsFileName)
+ } else {
+ android.AssertStringDoesNotContain(t, "app did not expect transitive deps's proguard flags",
+ appR8.Args["r8Flags"], transitiveDepFlagsFileName)
+ }
+ })
+ }
}
}
@@ -606,11 +649,6 @@ func TestProguardFlagsInheritanceAppImport(t *testing.T) {
platform_apis: true,
}
- android_library {
- name: "androidlib",
- static_libs: ["aarimport"],
- }
-
android_library_import {
name: "aarimport",
aars: ["import.aar"],