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:
parent
8196356248
commit
f8b860a0fb
|
@ -123,6 +123,10 @@ type hooks struct {
|
||||||
install []func(InstallHookContext)
|
install []func(InstallHookContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerLoadHookMutator(ctx RegisterMutatorsContext) {
|
||||||
|
ctx.TopDown("load_hooks", LoadHookMutator).Parallel()
|
||||||
|
}
|
||||||
|
|
||||||
func LoadHookMutator(ctx TopDownMutatorContext) {
|
func LoadHookMutator(ctx TopDownMutatorContext) {
|
||||||
if m, ok := ctx.Module().(Module); ok {
|
if m, ok := ctx.Module().(Module); ok {
|
||||||
// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
|
// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
|
||||||
|
|
|
@ -73,9 +73,7 @@ type RegisterMutatorsContext interface {
|
||||||
type RegisterMutatorFunc func(RegisterMutatorsContext)
|
type RegisterMutatorFunc func(RegisterMutatorsContext)
|
||||||
|
|
||||||
var preArch = []RegisterMutatorFunc{
|
var preArch = []RegisterMutatorFunc{
|
||||||
func(ctx RegisterMutatorsContext) {
|
registerLoadHookMutator,
|
||||||
ctx.TopDown("load_hooks", LoadHookMutator).Parallel()
|
|
||||||
},
|
|
||||||
RegisterNamespaceMutator,
|
RegisterNamespaceMutator,
|
||||||
RegisterPrebuiltsPreArchMutators,
|
RegisterPrebuiltsPreArchMutators,
|
||||||
RegisterDefaultsPreArchMutators,
|
RegisterDefaultsPreArchMutators,
|
||||||
|
|
|
@ -37,6 +37,8 @@ func NewTestContext() *TestContext {
|
||||||
|
|
||||||
ctx.SetNameInterface(nameResolver)
|
ctx.SetNameInterface(nameResolver)
|
||||||
|
|
||||||
|
ctx.preArch = append(ctx.preArch, registerLoadHookMutator)
|
||||||
|
|
||||||
ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator)
|
ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator)
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
|
@ -94,7 +94,6 @@ func testContext(config android.Config, bp string,
|
||||||
ctx.PreArchMutators(android.RegisterOverridePreArchMutators)
|
ctx.PreArchMutators(android.RegisterOverridePreArchMutators)
|
||||||
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
||||||
ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel()
|
ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel()
|
||||||
ctx.TopDown("java_sdk_library", SdkLibraryMutator).Parallel()
|
|
||||||
})
|
})
|
||||||
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
|
ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory))
|
||||||
ctx.RegisterPreSingletonType("sdk", android.SingletonFactoryAdaptor(sdkSingletonFactory))
|
ctx.RegisterPreSingletonType("sdk", android.SingletonFactoryAdaptor(sdkSingletonFactory))
|
||||||
|
|
|
@ -42,10 +42,6 @@ type stubsLibraryDependencyTag struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
type syspropLibraryInterface interface {
|
|
||||||
SyspropJavaModule() *SdkLibrary
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
publicApiStubsTag = dependencyTag{name: "public"}
|
publicApiStubsTag = dependencyTag{name: "public"}
|
||||||
systemApiStubsTag = dependencyTag{name: "system"}
|
systemApiStubsTag = dependencyTag{name: "system"}
|
||||||
|
@ -80,10 +76,6 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
|
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) {
|
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
|
||||||
javaSdkLibraries := javaSdkLibraries(ctx.Config())
|
javaSdkLibraries := javaSdkLibraries(ctx.Config())
|
||||||
sort.Strings(*javaSdkLibraries)
|
sort.Strings(*javaSdkLibraries)
|
||||||
|
@ -376,7 +368,7 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a static java library that has API stubs
|
// 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 {
|
props := struct {
|
||||||
Name *string
|
Name *string
|
||||||
Srcs []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
|
// Creates a droiddoc module that creates stubs source files from the given full source
|
||||||
// files
|
// files
|
||||||
func (module *SdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) {
|
func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
|
||||||
props := struct {
|
props := struct {
|
||||||
Name *string
|
Name *string
|
||||||
Srcs []string
|
Srcs []string
|
||||||
|
@ -534,7 +526,7 @@ func (module *SdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the xml file that publicizes the runtime library
|
// Creates the xml file that publicizes the runtime library
|
||||||
func (module *SdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) {
|
func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
|
||||||
template := `
|
template := `
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (C) 2018 The Android Open Source Project
|
<!-- Copyright (C) 2018 The Android Open Source Project
|
||||||
|
@ -659,15 +651,7 @@ func javaSdkLibraries(config android.Config) *[]string {
|
||||||
// For a java_sdk_library module, create internal modules for stubs, docs,
|
// For a java_sdk_library module, create internal modules for stubs, docs,
|
||||||
// runtime libs and xml file. If requested, the stubs and docs are created twice
|
// runtime libs and xml file. If requested, the stubs and docs are created twice
|
||||||
// once for public API level and once for system API level
|
// once for public API level and once for system API level
|
||||||
func SdkLibraryMutator(mctx android.TopDownMutatorContext) {
|
func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
|
||||||
if module, ok := mctx.Module().(*SdkLibrary); ok {
|
|
||||||
module.createInternalModules(mctx)
|
|
||||||
} else if module, ok := mctx.Module().(syspropLibraryInterface); ok {
|
|
||||||
module.SyspropJavaModule().createInternalModules(mctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (module *SdkLibrary) createInternalModules(mctx android.TopDownMutatorContext) {
|
|
||||||
if len(module.Library.Module.properties.Srcs) == 0 {
|
if len(module.Library.Module.properties.Srcs) == 0 {
|
||||||
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
|
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
|
||||||
}
|
}
|
||||||
|
@ -744,5 +728,6 @@ func SdkLibraryFactory() android.Module {
|
||||||
module := &SdkLibrary{}
|
module := &SdkLibrary{}
|
||||||
module.InitSdkLibraryProperties()
|
module.InitSdkLibraryProperties()
|
||||||
InitJavaModule(module, android.HostAndDeviceSupported)
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
||||||
|
android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
"android/soong/java"
|
"android/soong/java"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
@ -63,10 +64,6 @@ func (m *syspropLibrary) CcModuleName() string {
|
||||||
return "lib" + m.Name()
|
return "lib" + m.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *syspropLibrary) SyspropJavaModule() *java.SdkLibrary {
|
|
||||||
return &m.SdkLibrary
|
|
||||||
}
|
|
||||||
|
|
||||||
func syspropLibraryFactory() android.Module {
|
func syspropLibraryFactory() android.Module {
|
||||||
m := &syspropLibrary{}
|
m := &syspropLibrary{}
|
||||||
|
|
||||||
|
@ -77,7 +74,7 @@ func syspropLibraryFactory() android.Module {
|
||||||
m.InitSdkLibraryProperties()
|
m.InitSdkLibraryProperties()
|
||||||
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
|
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
|
||||||
android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
|
||||||
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) { m.SdkLibrary.CreateInternalModules(ctx) })
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,11 @@ func testContext(config android.Config, bp string,
|
||||||
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
|
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
|
||||||
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
|
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
|
||||||
ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
|
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.RegisterPrebuiltsPreArchMutators)
|
||||||
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
|
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
|
||||||
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
||||||
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
||||||
ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
|
ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
|
||||||
ctx.TopDown("java_sdk_library", java.SdkLibraryMutator).Parallel()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
|
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
|
||||||
|
|
Loading…
Reference in New Issue