From f8b860a0fb98448dd44db835d5f146e8a50e5ef5 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 16 Apr 2019 14:43:28 -0700 Subject: [PATCH] Use LoadHook to create modules in java_sdk_library Creating new modules in a mutator is dangerous, as other mutators that need to see the new modules may already have run, in this case the prebuilts mutator. Move SdkLibraryMutator to a LoadHook instead. Also moves registering the LoadHook mutator to testing.go so it is registered for all tests. Test: m checkbuild Change-Id: I08bd76a0e6205d2ca27861058067a1562c339eed --- android/hooks.go | 4 ++++ android/mutator.go | 4 +--- android/testing.go | 2 ++ java/java_test.go | 1 - java/sdk_library.go | 25 +++++-------------------- sysprop/sysprop_library.go | 7 ++----- sysprop/sysprop_test.go | 4 ---- 7 files changed, 14 insertions(+), 33 deletions(-) diff --git a/android/hooks.go b/android/hooks.go index 6b2468dc5..d55678e9d 100644 --- a/android/hooks.go +++ b/android/hooks.go @@ -123,6 +123,10 @@ type hooks struct { install []func(InstallHookContext) } +func registerLoadHookMutator(ctx RegisterMutatorsContext) { + ctx.TopDown("load_hooks", LoadHookMutator).Parallel() +} + func LoadHookMutator(ctx TopDownMutatorContext) { if m, ok := ctx.Module().(Module); ok { // Cast through *androidTopDownMutatorContext because AppendProperties is implemented diff --git a/android/mutator.go b/android/mutator.go index 71237a1cd..5ce743a8f 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -73,9 +73,7 @@ type RegisterMutatorsContext interface { type RegisterMutatorFunc func(RegisterMutatorsContext) var preArch = []RegisterMutatorFunc{ - func(ctx RegisterMutatorsContext) { - ctx.TopDown("load_hooks", LoadHookMutator).Parallel() - }, + registerLoadHookMutator, RegisterNamespaceMutator, RegisterPrebuiltsPreArchMutators, RegisterDefaultsPreArchMutators, diff --git a/android/testing.go b/android/testing.go index 0ec5af58a..aee68550b 100644 --- a/android/testing.go +++ b/android/testing.go @@ -37,6 +37,8 @@ func NewTestContext() *TestContext { ctx.SetNameInterface(nameResolver) + ctx.preArch = append(ctx.preArch, registerLoadHookMutator) + ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator) return ctx diff --git a/java/java_test.go b/java/java_test.go index 3ae993d26..89f871cb1 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -94,7 +94,6 @@ func testContext(config android.Config, bp string, ctx.PreArchMutators(android.RegisterOverridePreArchMutators) ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel() - ctx.TopDown("java_sdk_library", SdkLibraryMutator).Parallel() }) ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) ctx.RegisterPreSingletonType("sdk", android.SingletonFactoryAdaptor(sdkSingletonFactory)) diff --git a/java/sdk_library.go b/java/sdk_library.go index 72cce5794..3bda9c7b8 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -42,10 +42,6 @@ type stubsLibraryDependencyTag struct { name string } -type syspropLibraryInterface interface { - SyspropJavaModule() *SdkLibrary -} - var ( publicApiStubsTag = dependencyTag{name: "public"} systemApiStubsTag = dependencyTag{name: "system"} @@ -80,10 +76,6 @@ var ( func init() { android.RegisterModuleType("java_sdk_library", SdkLibraryFactory) - android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { - ctx.TopDown("java_sdk_library", SdkLibraryMutator).Parallel() - }) - android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { javaSdkLibraries := javaSdkLibraries(ctx.Config()) sort.Strings(*javaSdkLibraries) @@ -376,7 +368,7 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) strin } // Creates a static java library that has API stubs -func (module *SdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) { +func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) { props := struct { Name *string Srcs []string @@ -435,7 +427,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, // Creates a droiddoc module that creates stubs source files from the given full source // files -func (module *SdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) { +func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) { props := struct { Name *string Srcs []string @@ -534,7 +526,7 @@ func (module *SdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScop } // Creates the xml file that publicizes the runtime library -func (module *SdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) { +func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { template := `