Merge "Make BottomUpMutators parallel"

This commit is contained in:
Treehugger Robot 2016-08-11 21:35:23 +00:00 committed by Gerrit Code Review
commit aa99f84e57
7 changed files with 38 additions and 19 deletions

View file

@ -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 (

View file

@ -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,

View file

@ -24,7 +24,7 @@ import (
)
func init() {
RegisterBottomUpMutator("variable", variableMutator)
RegisterBottomUpMutator("variable", variableMutator).Parallel()
}
type variableProperties struct {

View file

@ -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")
}

View file

@ -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

View file

@ -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 (

View file

@ -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)