diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index a28cf49bc..71eb19b60 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -803,6 +803,11 @@ var moduleTypes = map[string]string{ "BUILD_HOST_JAVA_LIBRARY": "java_library_host", "BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik", "BUILD_PACKAGE": "android_app", + + "BUILD_CTS_SUPPORT_PACKAGE": "cts_support_package", // will be rewritten to android_test by bpfix + "BUILD_CTS_PACKAGE": "cts_package", // will be rewritten to android_test by bpfix + "BUILD_CTS_TARGET_JAVA_LIBRARY": "cts_target_java_library", // will be rewritten to java_library by bpfix + "BUILD_CTS_HOST_JAVA_LIBRARY": "cts_host_java_library", // will be rewritten to java_library_host by bpfix } var prebuiltTypes = map[string]string{ diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index c750f220c..9874cb2c6 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -750,6 +750,61 @@ cc_library_shared { keep_symbols: true, } } +`, + }, + { + desc: "BUILD_CTS_SUPPORT_PACKAGE", + in: ` +include $(CLEAR_VARS) +LOCAL_PACKAGE_NAME := FooTest +LOCAL_COMPATIBILITY_SUITE := cts +include $(BUILD_CTS_SUPPORT_PACKAGE) +`, + expected: ` +android_test { + name: "FooTest", + defaults: ["cts_support_defaults"], + test_suites: ["cts"], +} +`, + }, + { + desc: "BUILD_CTS_PACKAGE", + in: ` +include $(CLEAR_VARS) +LOCAL_PACKAGE_NAME := FooTest +LOCAL_COMPATIBILITY_SUITE := cts +include $(BUILD_CTS_PACKAGE) +`, + expected: ` +android_test { + name: "FooTest", + defaults: ["cts_defaults"], + test_suites: ["cts"], +} +`, + }, + { + desc: "BUILD_CTS_*_JAVA_LIBRARY", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE := foolib +include $(BUILD_CTS_TARGET_JAVA_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := foolib-host +include $(BUILD_CTS_HOST_JAVA_LIBRARY) +`, + expected: ` +java_library { + name: "foolib", + defaults: ["cts_defaults"], +} + +java_library_host { + name: "foolib-host", + defaults: ["cts_defaults"], +} `, }, } diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index a4723fb2d..6a7551761 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -62,6 +62,10 @@ var fixSteps = []fixStep{ name: "rewriteIncorrectAndroidmkPrebuilts", fix: rewriteIncorrectAndroidmkPrebuilts, }, + { + name: "rewriteCtsModuleTypes", + fix: rewriteCtsModuleTypes, + }, { name: "rewriteIncorrectAndroidmkAndroidLibraries", fix: rewriteIncorrectAndroidmkAndroidLibraries, @@ -237,6 +241,52 @@ func rewriteIncorrectAndroidmkPrebuilts(f *Fixer) error { return nil } +func rewriteCtsModuleTypes(f *Fixer) error { + for _, def := range f.tree.Defs { + mod, ok := def.(*parser.Module) + if !ok { + continue + } + + if mod.Type != "cts_support_package" && mod.Type != "cts_package" && + mod.Type != "cts_target_java_library" && + mod.Type != "cts_host_java_library" { + + continue + } + + var defStr string + switch mod.Type { + case "cts_support_package": + mod.Type = "android_test" + defStr = "cts_support_defaults" + case "cts_package": + mod.Type = "android_test" + defStr = "cts_defaults" + case "cts_target_java_library": + mod.Type = "java_library" + defStr = "cts_defaults" + case "cts_host_java_library": + mod.Type = "java_library_host" + defStr = "cts_defaults" + } + + defaults := &parser.Property{ + Name: "defaults", + Value: &parser.List{ + Values: []parser.Expression{ + &parser.String{ + Value: defStr, + }, + }, + }, + } + mod.Properties = append(mod.Properties, defaults) + } + + return nil +} + func rewriteIncorrectAndroidmkAndroidLibraries(f *Fixer) error { for _, def := range f.tree.Defs { mod, ok := def.(*parser.Module) diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go index 0469faf6a..5224ee3a6 100644 --- a/bpfix/bpfix/bpfix_test.go +++ b/bpfix/bpfix/bpfix_test.go @@ -621,3 +621,74 @@ func TestRewritePrebuilts(t *testing.T) { }) } } + +func TestRewriteCtsModuleTypes(t *testing.T) { + tests := []struct { + name string + in string + out string + }{ + { + name: "cts_support_package", + in: ` + cts_support_package { + name: "foo", + } + `, + out: ` + android_test { + name: "foo", + defaults: ["cts_support_defaults"], + } + `, + }, + { + name: "cts_package", + in: ` + cts_package { + name: "foo", + } + `, + out: ` + android_test { + name: "foo", + defaults: ["cts_defaults"], + } + `, + }, + { + name: "cts_target_java_library", + in: ` + cts_target_java_library { + name: "foo", + } + `, + out: ` + java_library { + name: "foo", + defaults: ["cts_defaults"], + } + `, + }, + { + name: "cts_host_java_library", + in: ` + cts_host_java_library { + name: "foo", + } + `, + out: ` + java_library_host { + name: "foo", + defaults: ["cts_defaults"], + } + `, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + runPass(t, test.in, test.out, rewriteCtsModuleTypes) + }) + } +}