From a48f758d840290dd75fced5234e1c178bf3dc113 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 19 Dec 2019 11:25:19 +0000 Subject: [PATCH 1/3] Dedup prebuilt apis module type/mutator registration Test: m checkbuild Bug: 146540677 Change-Id: If5d6fdace2574df6314fbcf6441838cd11df58ae --- android/register.go | 5 +++++ java/java_test.go | 7 +++---- java/prebuilt_apis.go | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/android/register.go b/android/register.go index 86943f295..9182f8b09 100644 --- a/android/register.go +++ b/android/register.go @@ -122,6 +122,7 @@ func ModuleTypeFactories() map[string]ModuleFactory { type RegistrationContext interface { RegisterModuleType(name string, factory ModuleFactory) RegisterSingletonType(name string, factory SingletonFactory) + PreArchMutators(f RegisterMutatorFunc) } // Used to register build components from an init() method, e.g. @@ -154,3 +155,7 @@ func (ctx initRegistrationContext) RegisterModuleType(name string, factory Modul func (ctx initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) { RegisterSingletonType(name, factory) } + +func (ctx initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) { + PreArchMutators(f) +} diff --git a/java/java_test.go b/java/java_test.go index adc5ad181..1f259627e 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -74,13 +74,12 @@ func testContext() *android.TestContext { RegisterDocsBuildComponents(ctx) RegisterStubsBuildComponents(ctx) RegisterSdkLibraryBuildComponents(ctx) - ctx.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) - ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { - ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel() - }) + + RegisterPrebuiltApisBuildComponents(ctx) + ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory)) diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 0d5e31f69..cb17feedd 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -23,9 +23,13 @@ import ( ) func init() { - android.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory) + RegisterPrebuiltApisBuildComponents(android.InitRegistrationContext) +} - android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { +func RegisterPrebuiltApisBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory) + + ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel() }) } From 0a2868309a3eac9530e456d443074b5f4076d2a9 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 19 Dec 2019 12:23:01 +0000 Subject: [PATCH 2/3] Detect registration of duplicate module/singleton types Module type and singleton type names have to be unique but duplicates are not checked when the relevant android.Register...() func is called. Instead they are collated in lists and then registered with the Context later on, at which point duplicates are detected. That loses information that can be helpful in fixing the issue. This is not an issue when testing as the module and singleton types are registered directly with the Context. This change adds duplicate detection to the initRegistrationContext Register... methods prior to calling the android.Register... methods which should make it easier to detect duplicates registered from an init() function. Test: m checkbuild Bug: 146540677 Change-Id: I7f1a4b649072867717a9829c737a44454b12266c --- android/register.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/android/register.go b/android/register.go index 9182f8b09..e7efe475d 100644 --- a/android/register.go +++ b/android/register.go @@ -15,6 +15,8 @@ package android import ( + "fmt" + "github.com/google/blueprint" ) @@ -141,21 +143,35 @@ type RegistrationContext interface { // // ctx := android.NewTestContext() // RegisterBuildComponents(ctx) -var InitRegistrationContext RegistrationContext = initRegistrationContext{} +var InitRegistrationContext RegistrationContext = &initRegistrationContext{ + moduleTypes: make(map[string]ModuleFactory), + singletonTypes: make(map[string]SingletonFactory), +} // Make sure the TestContext implements RegistrationContext. var _ RegistrationContext = (*TestContext)(nil) -type initRegistrationContext struct{} +type initRegistrationContext struct { + moduleTypes map[string]ModuleFactory + singletonTypes map[string]SingletonFactory +} -func (ctx initRegistrationContext) RegisterModuleType(name string, factory ModuleFactory) { +func (ctx *initRegistrationContext) RegisterModuleType(name string, factory ModuleFactory) { + if _, present := ctx.moduleTypes[name]; present { + panic(fmt.Sprintf("module type %q is already registered", name)) + } + ctx.moduleTypes[name] = factory RegisterModuleType(name, factory) } -func (ctx initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) { +func (ctx *initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) { + if _, present := ctx.singletonTypes[name]; present { + panic(fmt.Sprintf("singleton type %q is already registered", name)) + } + ctx.singletonTypes[name] = factory RegisterSingletonType(name, factory) } -func (ctx initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) { +func (ctx *initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) { PreArchMutators(f) } From 59986b23cc4679f38f305f059c446bd9c4a01032 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 19 Dec 2019 14:38:36 +0000 Subject: [PATCH 3/3] Dedup cc prebuilts module type registration Test: m checkbuild Bug: 146540677 Change-Id: I7e9440a075ef9c683729ed83e0033ab529fe4ac0 --- apex/apex_test.go | 3 +-- cc/prebuilt.go | 10 +++++++--- cc/prebuilt_test.go | 4 +--- sdk/testing.go | 3 +-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index bb6e026cc..035a553f9 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -289,8 +289,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr ctx.RegisterModuleType("cc_library", cc.LibraryFactory) ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) - ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory) - ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) + cc.RegisterPrebuiltBuildComponents(ctx) ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) ctx.RegisterModuleType("cc_object", cc.ObjectFactory) ctx.RegisterModuleType("cc_defaults", func() android.Module { diff --git a/cc/prebuilt.go b/cc/prebuilt.go index f20616f8b..b0cf4890e 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -19,9 +19,13 @@ import ( ) func init() { - android.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) - android.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) - android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) + RegisterPrebuiltBuildComponents(android.InitRegistrationContext) +} + +func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) } type prebuiltLinkerInterface interface { diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go index 31db2dfbf..658cef0b5 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -72,9 +72,7 @@ func TestPrebuilt(t *testing.T) { ctx := CreateTestContext() - ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) - ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) - ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) + RegisterPrebuiltBuildComponents(ctx) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators) diff --git a/sdk/testing.go b/sdk/testing.go index 0aac1a4f6..61043f30a 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -87,8 +87,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) ctx.RegisterModuleType("cc_object", cc.ObjectFactory) - ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory) - ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) + cc.RegisterPrebuiltBuildComponents(ctx) ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {