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
This commit is contained in:
Colin Cross
2019-04-16 14:43:28 -07:00
parent 8196356248
commit f8b860a0fb
7 changed files with 14 additions and 33 deletions

View File

@@ -18,6 +18,7 @@ import (
"android/soong/android"
"android/soong/cc"
"android/soong/java"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -63,10 +64,6 @@ func (m *syspropLibrary) CcModuleName() string {
return "lib" + m.Name()
}
func (m *syspropLibrary) SyspropJavaModule() *java.SdkLibrary {
return &m.SdkLibrary
}
func syspropLibraryFactory() android.Module {
m := &syspropLibrary{}
@@ -77,7 +74,7 @@ func syspropLibraryFactory() android.Module {
m.InitSdkLibraryProperties()
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
android.AddLoadHook(m, func(ctx android.LoadHookContext) { m.SdkLibrary.CreateInternalModules(ctx) })
return m
}

View File

@@ -61,15 +61,11 @@ func testContext(config android.Config, bp string,
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("load_hooks", android.LoadHookMutator).Parallel()
})
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
ctx.TopDown("java_sdk_library", java.SdkLibraryMutator).Parallel()
})
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))