Merge "rewrite android_app to android_test in mk2bp" am: 36a0e33bad

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2056410

Change-Id: I8b174b2951b276bea3dbc6dc2f82f67e6518215f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yuntao Xu
2022-04-07 18:17:47 +00:00
committed by Automerger Merge Worker
3 changed files with 50 additions and 8 deletions

View File

@@ -1688,6 +1688,21 @@ android_app {
name: "foo", name: "foo",
privileged: true privileged: true
} }
`,
},
{
desc: "convert android_app to android_test when having test_suites",
in: `
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_COMPATIBILITY_SUITE := bar
include $(BUILD_PACKAGE)
`,
expected: `
android_test {
name: "foo",
test_suites: ["bar"],
}
`, `,
}, },
} }

View File

@@ -449,6 +449,7 @@ func rewriteTestModuleTypes(f *Fixer) error {
} }
hasInstrumentationFor := hasNonEmptyLiteralStringProperty(mod, "instrumentation_for") hasInstrumentationFor := hasNonEmptyLiteralStringProperty(mod, "instrumentation_for")
hasTestSuites := hasNonEmptyLiteralListProperty(mod, "test_suites")
tags, _ := getLiteralListPropertyValue(mod, "tags") tags, _ := getLiteralListPropertyValue(mod, "tags")
var hasTestsTag bool var hasTestsTag bool
@@ -458,7 +459,7 @@ func rewriteTestModuleTypes(f *Fixer) error {
} }
} }
isTest := hasInstrumentationFor || hasTestsTag isTest := hasInstrumentationFor || hasTestsTag || hasTestSuites
if isTest { if isTest {
switch mod.Type { switch mod.Type {
@@ -470,13 +471,7 @@ func rewriteTestModuleTypes(f *Fixer) error {
mod.Type = "java_test" mod.Type = "java_test"
case "java_library_host": case "java_library_host":
mod.Type = "java_test_host" mod.Type = "java_test_host"
} case "cc_binary":
}
// when a cc_binary module has a nonempty test_suites field, modify the type to cc_test
if mod.Type == "cc_binary" {
hasTestSuites := hasNonEmptyLiteralListProperty(mod, "test_suites")
if hasTestSuites {
mod.Type = "cc_test" mod.Type = "cc_test"
} }
} }

View File

@@ -1436,6 +1436,38 @@ func TestRewriteTestModuleTypes(t *testing.T) {
} }
`, `,
}, },
{
name: "android_app with android_test",
in: `
android_app {
name: "foo",
srcs: ["srcs"],
test_suites: ["test_suite1"],
}
`,
out: `
android_test {
name: "foo",
srcs: ["srcs"],
test_suites: ["test_suite1"],
}
`,
},
{
name: "android_app without test_suites",
in: `
android_app {
name: "foo",
srcs: ["srcs"],
}
`,
out: `
android_app {
name: "foo",
srcs: ["srcs"],
}
`,
},
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {