diff options
-rw-r--r-- | android/module.go | 2 | ||||
-rw-r--r-- | androidmk/cmd/androidmk/androidmk_test.go | 38 | ||||
-rw-r--r-- | bpfix/bpfix/bpfix.go | 75 | ||||
-rw-r--r-- | cc/cc.go | 8 |
4 files changed, 112 insertions, 11 deletions
diff --git a/android/module.go b/android/module.go index 4797c0c2..fba19179 100644 --- a/android/module.go +++ b/android/module.go @@ -191,8 +191,6 @@ type nameProperties struct { } type commonProperties struct { - Tags []string - // emit build rules for this module Enabled *bool `android:"arch_variant"` diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 37e2427c..a54a4d2f 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -331,7 +331,7 @@ cc_library_shared { `, }, { - desc: "Keep LOCAL_MODULE_TAGS non-optional", + desc: "Warn for LOCAL_MODULE_TAGS non-optional", in: ` include $(CLEAR_VARS) LOCAL_MODULE_TAGS := debug @@ -340,7 +340,41 @@ include $(BUILD_SHARED_LIBRARY) expected: ` cc_library_shared { - tags: ["debug"], + // WARNING: Module tags are not supported in Soong. + // Add this module to PRODUCT_PACKAGES_DEBUG in your product file if you want to + // force installation for -userdebug and -eng builds. +} +`, + }, + { + desc: "Custom warning for LOCAL_MODULE_TAGS tests", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := debug tests +include $(BUILD_SHARED_LIBRARY) +`, + + expected: ` +cc_library_shared { + // WARNING: Module tags are not supported in Soong. + // Add this module to PRODUCT_PACKAGES_DEBUG in your product file if you want to + // force installation for -userdebug and -eng builds. + // 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". +} +`, + }, + { + desc: "Ignore LOCAL_MODULE_TAGS tests for cc_test", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := tests +include $(BUILD_NATIVE_TEST) +`, + + expected: ` +cc_test { } `, }, diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 55de9936..ee00907f 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -50,6 +50,7 @@ type FixRequest struct { rewriteIncorrectAndroidmkAndroidLibraries bool mergeMatchingModuleProperties bool reorderCommonProperties bool + removeTags bool } func NewFixRequest() FixRequest { @@ -63,6 +64,7 @@ func (r FixRequest) AddAll() (result FixRequest) { result.rewriteIncorrectAndroidmkAndroidLibraries = true result.mergeMatchingModuleProperties = true result.reorderCommonProperties = true + result.removeTags = true return result } @@ -180,6 +182,13 @@ func (f *Fixer) fixTreeOnce(config FixRequest) error { return err } } + + if config.removeTags { + err := f.runPatchListMod(removeTags) + if err != nil { + return err + } + } return nil } @@ -352,6 +361,72 @@ func reorderCommonProperties(mod *parser.Module, buf []byte, patchlist *parser.P return nil } +func removeTags(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error { + prop, ok := mod.GetProperty("tags") + if !ok { + return nil + } + list, ok := prop.Value.(*parser.List) + if !ok { + return nil + } + + replaceStr := "" + + for _, item := range list.Values { + str, ok := item.(*parser.String) + if !ok { + replaceStr += fmt.Sprintf("// ERROR: Unable to parse tag %q\n", item) + continue + } + + switch str.Value { + case "optional": + continue + case "debug": + replaceStr += `// WARNING: Module tags are not supported in Soong. + // Add this module to PRODUCT_PACKAGES_DEBUG in your product file if you want to + // force installation for -userdebug and -eng builds. + ` + case "eng": + replaceStr += `// WARNING: Module tags are not supported in Soong. + // Add this module to PRODUCT_PACKAGES_ENG in your product file if you want to + // force installation for -eng builds. + ` + case "tests": + if strings.Contains(mod.Type, "cc_test") || strings.Contains(mod.Type, "cc_library_static") { + continue + } else if 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") { + 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") { + 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 { + 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 + ` + } + default: + replaceStr += fmt.Sprintf("// WARNING: Unknown module tag %q\n", str.Value) + } + } + + return patchlist.Add(prop.Pos().Offset, prop.End().Offset+2, replaceStr) +} + func mergeMatchingModuleProperties(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error { return mergeMatchingProperties(&mod.Properties, buf, patchlist) } @@ -206,10 +206,6 @@ type VendorProperties struct { Double_loadable *bool } -type UnusedProperties struct { - Tags []string -} - type ModuleContextIntf interface { static() bool staticBinary() bool @@ -320,7 +316,6 @@ type Module struct { Properties BaseProperties VendorProperties VendorProperties - unused UnusedProperties // initialize before calling Init hod android.HostOrDeviceSupported @@ -360,7 +355,7 @@ type Module struct { } func (c *Module) Init() android.Module { - c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused) + c.AddProperties(&c.Properties, &c.VendorProperties) if c.compiler != nil { c.AddProperties(c.compiler.compilerProps()...) } @@ -1475,7 +1470,6 @@ func DefaultsFactory(props ...interface{}) android.Module { &BinaryLinkerProperties{}, &TestProperties{}, &TestBinaryProperties{}, - &UnusedProperties{}, &StlProperties{}, &SanitizeProperties{}, &StripProperties{}, |