diff options
author | Colin Cross <ccross@android.com> | 2018-05-22 11:11:52 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-05-24 14:53:58 -0700 |
commit | ae5caf554cb01b2bc73130dfe99c9f5a475b03d9 (patch) | |
tree | 71fd459d64024e74738697d546a4509a8f2ded21 /bpfix/bpfix | |
parent | e467f44f9bbfbb969fe867b8a1b2e68f017ac485 (diff) | |
download | build_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.tar.gz build_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.tar.bz2 build_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.zip |
Add support for android_test modules
android_test module are APKs that can be run as tests, either
as standalone unit tests or as instrumentation tests for another
APK.
Test: m checkbuild
Change-Id: I16661701637e4048fd99442029c3e195ebf373a4
Diffstat (limited to 'bpfix/bpfix')
-rw-r--r-- | bpfix/bpfix/bpfix.go | 101 |
1 files changed, 96 insertions, 5 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 1cd04090..05be3bd5 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -67,6 +67,10 @@ var fixSteps = []fixStep{ fix: rewriteIncorrectAndroidmkAndroidLibraries, }, { + name: "rewriteTestModuleTypes", + fix: rewriteTestModuleTypes, + }, + { name: "mergeMatchingModuleProperties", fix: runPatchListMod(mergeMatchingModuleProperties), }, @@ -256,6 +260,46 @@ func rewriteIncorrectAndroidmkAndroidLibraries(f *Fixer) error { return nil } +// rewriteTestModuleTypes looks for modules that are identifiable as tests but for which Make doesn't have a separate +// module class, and moves them to the appropriate Soong module type. +func rewriteTestModuleTypes(f *Fixer) error { + for _, def := range f.tree.Defs { + mod, ok := def.(*parser.Module) + if !ok { + continue + } + + if !strings.HasPrefix(mod.Type, "java_") && !strings.HasPrefix(mod.Type, "android_") { + continue + } + + hasInstrumentationFor := hasNonEmptyLiteralStringProperty(mod, "instrumentation_for") + tags, _ := getLiteralListPropertyValue(mod, "tags") + + var hasTestsTag bool + for _, tag := range tags { + if tag == "tests" { + hasTestsTag = true + } + } + + isTest := hasInstrumentationFor || hasTestsTag + + if isTest { + switch mod.Type { + case "android_app": + mod.Type = "android_test" + case "java_library": + mod.Type = "java_test" + case "java_library_host": + mod.Type = "java_test_host" + } + } + } + + return nil +} + func runPatchListMod(modFunc func(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error) func(*Fixer) error { return func(f *Fixer) error { // Make sure all the offsets are accurate @@ -383,26 +427,34 @@ func removeTags(mod *parser.Module, buf []byte, patchlist *parser.PatchList) err // force installation for -eng builds. ` case "tests": - if strings.Contains(mod.Type, "cc_test") || strings.Contains(mod.Type, "cc_library_static") { + switch { + case strings.Contains(mod.Type, "cc_test"), + strings.Contains(mod.Type, "cc_library_static"), + strings.Contains(mod.Type, "java_test"), + mod.Type == "android_test": continue - } else if strings.Contains(mod.Type, "cc_lib") { + case strings.Contains(mod.Type, "cc_lib"): replaceStr += `// WARNING: Module tags are not supported in Soong. // To make a shared library only for tests, use the "cc_test_library" module // type. If you don't use gtest, set "gtest: false". ` - } else if strings.Contains(mod.Type, "cc_bin") { + case strings.Contains(mod.Type, "cc_bin"): replaceStr += `// WARNING: Module tags are not supported in Soong. // For native test binaries, use the "cc_test" module type. Some differences: // - If you don't use gtest, set "gtest: false" // - Binaries will be installed into /data/nativetest[64]/<name>/<name> // - Both 32 & 64 bit versions will be built (as appropriate) ` - } else if strings.Contains(mod.Type, "java_lib") { + case strings.Contains(mod.Type, "java_lib"): replaceStr += `// WARNING: Module tags are not supported in Soong. // For JUnit or similar tests, use the "java_test" module type. A dependency on // Junit will be added by default, if it is using some other runner, set "junit: false". ` - } else { + case mod.Type == "android_app": + replaceStr += `// WARNING: Module tags are not supported in Soong. + // For JUnit or instrumentataion app tests, use the "android_test" module type. + ` + default: replaceStr += `// WARNING: Module tags are not supported in Soong. // In most cases, tests are now identified by their module type: // cc_test, java_test, python_test @@ -552,6 +604,11 @@ func hasNonEmptyLiteralListProperty(mod *parser.Module, name string) bool { return found && len(list.Values) > 0 } +func hasNonEmptyLiteralStringProperty(mod *parser.Module, name string) bool { + s, found := getLiteralStringPropertyValue(mod, name) + return found && len(s) > 0 +} + func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, found bool) { prop, ok := mod.GetProperty(name) if !ok { @@ -561,6 +618,40 @@ func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, return list, ok } +func getLiteralListPropertyValue(mod *parser.Module, name string) (list []string, found bool) { + listValue, ok := getLiteralListProperty(mod, name) + if !ok { + return nil, false + } + for _, v := range listValue.Values { + stringValue, ok := v.(*parser.String) + if !ok { + return nil, false + } + list = append(list, stringValue.Value) + } + + return list, true +} + +func getLiteralStringProperty(mod *parser.Module, name string) (s *parser.String, found bool) { + prop, ok := mod.GetProperty(name) + if !ok { + return nil, false + } + s, ok = prop.Value.(*parser.String) + return s, ok +} + +func getLiteralStringPropertyValue(mod *parser.Module, name string) (s string, found bool) { + stringValue, ok := getLiteralStringProperty(mod, name) + if !ok { + return "", false + } + + return stringValue.Value, true +} + func propertyIndex(props []*parser.Property, propertyName string) int { for i, prop := range props { if prop.Name == propertyName { |