diff --git a/android/arch.go b/android/arch.go index c767bd708..5074c4cd5 100644 --- a/android/arch.go +++ b/android/arch.go @@ -25,10 +25,10 @@ import ( ) func init() { - RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) + RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator).Parallel() RegisterTopDownMutator("defaults", defaultsMutator) - RegisterBottomUpMutator("arch", ArchMutator) + RegisterBottomUpMutator("arch", ArchMutator).Parallel() } var ( diff --git a/android/mutator.go b/android/mutator.go index 9405f2d2f..c0cb3aaaa 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -44,8 +44,8 @@ type androidBottomUpMutatorContext struct { androidBaseContextImpl } -func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) { - soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) { +func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) soong.BottomUpMutatorHandle { + return soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) { if a, ok := ctx.Module().(Module); ok { actx := &androidBottomUpMutatorContext{ BottomUpMutatorContext: ctx, diff --git a/android/variable.go b/android/variable.go index d2dc5b92c..531125d56 100644 --- a/android/variable.go +++ b/android/variable.go @@ -24,7 +24,7 @@ import ( ) func init() { - RegisterBottomUpMutator("variable", variableMutator) + RegisterBottomUpMutator("variable", variableMutator).Parallel() } type variableProperties struct { diff --git a/cc/cc.go b/cc/cc.go index 669800711..752046f2c 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -38,17 +38,17 @@ func init() { // LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by // the Go initialization order because this package depends on common, so common's init // functions will run first. - android.RegisterBottomUpMutator("link", linkageMutator) - android.RegisterBottomUpMutator("ndk_api", ndkApiMutator) - android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator) - android.RegisterBottomUpMutator("begin", beginMutator) - android.RegisterBottomUpMutator("deps", depsMutator) + android.RegisterBottomUpMutator("link", linkageMutator).Parallel() + android.RegisterBottomUpMutator("ndk_api", ndkApiMutator).Parallel() + android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator).Parallel() + android.RegisterBottomUpMutator("begin", beginMutator).Parallel() + android.RegisterBottomUpMutator("deps", depsMutator).Parallel() android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan)) - android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)) + android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)).Parallel() android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan)) - android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)) + android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)).Parallel() pctx.Import("android/soong/cc/config") } diff --git a/cc/ndk_library.go b/cc/ndk_library.go index fe52b0e62..b0fd398fa 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -18,6 +18,7 @@ import ( "fmt" "strconv" "strings" + "sync" "github.com/google/blueprint" @@ -58,7 +59,8 @@ var ( // These libraries have migrated over to the new ndk_library, which is added // as a variation dependency via depsMutator. - ndkMigratedLibs = []string{} + ndkMigratedLibs = []string{} + ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel beginMutator ) // Creates a stub shared library based on the provided version file. @@ -177,6 +179,8 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) { c.baseCompiler.compilerInit(ctx) name := strings.TrimSuffix(ctx.ModuleName(), ".ndk") + ndkMigratedLibsLock.Lock() + defer ndkMigratedLibsLock.Unlock() for _, lib := range ndkMigratedLibs { if lib == name { return diff --git a/genrule/genrule.go b/genrule/genrule.go index a50af1c64..ecc5ab803 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -25,7 +25,7 @@ func init() { soong.RegisterModuleType("gensrcs", GenSrcsFactory) soong.RegisterModuleType("genrule", GenRuleFactory) - android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator) + android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator).Parallel() } var ( diff --git a/register.go b/register.go index 353094c0d..5c74273d6 100644 --- a/register.go +++ b/register.go @@ -34,9 +34,10 @@ type mutator struct { name string bottomUpMutator blueprint.BottomUpMutator topDownMutator blueprint.TopDownMutator + parallel bool } -var mutators []mutator +var mutators []*mutator func RegisterModuleType(name string, factory blueprint.ModuleFactory) { moduleTypes = append(moduleTypes, moduleType{name, factory}) @@ -46,12 +47,23 @@ func RegisterSingletonType(name string, factory blueprint.SingletonFactory) { singletons = append(singletons, singleton{name, factory}) } -func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) { - mutators = append(mutators, mutator{name: name, bottomUpMutator: m}) +func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) BottomUpMutatorHandle { + mutator := &mutator{name: name, bottomUpMutator: m} + mutators = append(mutators, mutator) + return mutator } func RegisterTopDownMutator(name string, m blueprint.TopDownMutator) { - mutators = append(mutators, mutator{name: name, topDownMutator: m}) + mutators = append(mutators, &mutator{name: name, topDownMutator: m}) +} + +type BottomUpMutatorHandle interface { + Parallel() BottomUpMutatorHandle +} + +func (mutator *mutator) Parallel() BottomUpMutatorHandle { + mutator.parallel = true + return mutator } func NewContext() *blueprint.Context { @@ -67,7 +79,10 @@ func NewContext() *blueprint.Context { for _, t := range mutators { if t.bottomUpMutator != nil { - ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) + handle := ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) + if t.parallel { + handle.Parallel() + } } if t.topDownMutator != nil { ctx.RegisterTopDownMutator(t.name, t.topDownMutator)