From eafc16bf14f4ccd9779e034b3814b9f1e37d4bd2 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 24 Feb 2021 01:43:18 +0000 Subject: [PATCH] Allow pre-singleton types to be registered in RegistrationContext Bug: 181070625 Test: m droid Change-Id: I708b78ed0b42ec55b0442307f40531cfe1233c2b --- android/register.go | 10 ++++++++++ android/testing.go | 4 ++++ java/java_test.go | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/android/register.go b/android/register.go index 18c743f19..47df9729e 100644 --- a/android/register.go +++ b/android/register.go @@ -168,6 +168,7 @@ func ModuleTypeFactoriesForDocs() map[string]reflect.Value { type RegistrationContext interface { RegisterModuleType(name string, factory ModuleFactory) RegisterSingletonModuleType(name string, factory SingletonModuleFactory) + RegisterPreSingletonType(name string, factory SingletonFactory) RegisterSingletonType(name string, factory SingletonFactory) PreArchMutators(f RegisterMutatorFunc) @@ -208,6 +209,7 @@ var _ RegistrationContext = (*TestContext)(nil) type initRegistrationContext struct { moduleTypes map[string]ModuleFactory singletonTypes map[string]SingletonFactory + preSingletonTypes map[string]SingletonFactory moduleTypesForDocs map[string]reflect.Value } @@ -238,6 +240,14 @@ func (ctx *initRegistrationContext) RegisterSingletonType(name string, factory S RegisterSingletonType(name, factory) } +func (ctx *initRegistrationContext) RegisterPreSingletonType(name string, factory SingletonFactory) { + if _, present := ctx.preSingletonTypes[name]; present { + panic(fmt.Sprintf("pre singleton type %q is already registered", name)) + } + ctx.preSingletonTypes[name] = factory + RegisterPreSingletonType(name, factory) +} + func (ctx *initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) { PreArchMutators(f) } diff --git a/android/testing.go b/android/testing.go index 7852b604b..1b1feb774 100644 --- a/android/testing.go +++ b/android/testing.go @@ -140,6 +140,10 @@ func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFact ctx.Context.RegisterSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory)) } +func (ctx *TestContext) RegisterPreSingletonType(name string, factory SingletonFactory) { + ctx.Context.RegisterPreSingletonType(name, SingletonFactoryAdaptor(ctx.Context, factory)) +} + func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { var module Module ctx.VisitAllModules(func(m blueprint.Module) { diff --git a/java/java_test.go b/java/java_test.go index 11f6a7c21..8407f2462 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -74,8 +74,8 @@ func testContext(config android.Config) *android.TestContext { ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) - ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(ctx.Context, OverlaySingletonFactory)) - ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(ctx.Context, sdkPreSingletonFactory)) + ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory) + ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) android.RegisterPrebuiltMutators(ctx)