Control mutator order

am: 1e676bef94

Change-Id: I7d7b50c83a9542afe316cdc54795809a3c92e9e5
This commit is contained in:
Colin Cross 2016-10-13 03:43:27 +00:00 committed by android-build-merger
commit d309a15b9d
9 changed files with 98 additions and 36 deletions

View File

@ -260,7 +260,7 @@ func (target Target) String() string {
return target.Os.String() + "_" + target.Arch.String() return target.Os.String() + "_" + target.Arch.String()
} }
func ArchMutator(mctx BottomUpMutatorContext) { func archMutator(mctx BottomUpMutatorContext) {
var module Module var module Module
var ok bool var ok bool
if module, ok = mctx.Module().(Module); !ok { if module, ok = mctx.Module().(Module); !ok {

View File

@ -24,15 +24,6 @@ import (
"github.com/google/blueprint" "github.com/google/blueprint"
) )
func init() {
RegisterTopDownMutator("load_hooks", loadHookMutator).Parallel()
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator).Parallel()
RegisterTopDownMutator("defaults", defaultsMutator).Parallel()
RegisterBottomUpMutator("arch", ArchMutator).Parallel()
RegisterTopDownMutator("arch_hooks", archHookMutator).Parallel()
}
var ( var (
DeviceSharedLibrary = "shared_library" DeviceSharedLibrary = "shared_library"
DeviceStaticLibrary = "static_library" DeviceStaticLibrary = "static_library"
@ -100,6 +91,7 @@ type Module interface {
blueprint.Module blueprint.Module
GenerateAndroidBuildActions(ModuleContext) GenerateAndroidBuildActions(ModuleContext)
DepsMutator(BottomUpMutatorContext)
base() *ModuleBase base() *ModuleBase
Enabled() bool Enabled() bool

View File

@ -16,6 +16,61 @@ package android
import "github.com/google/blueprint" import "github.com/google/blueprint"
// Mutator phases:
// Pre-arch
// Arch
// Pre-deps
// Deps
// PostDeps
func registerMutators() {
ctx := registerMutatorsContext{}
register := func(funcs []RegisterMutatorFunc) {
for _, f := range funcs {
f(ctx)
}
}
ctx.TopDown("load_hooks", loadHookMutator).Parallel()
ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel()
ctx.TopDown("defaults", defaultsMutator).Parallel()
register(preArch)
ctx.BottomUp("arch", archMutator).Parallel()
ctx.TopDown("arch_hooks", archHookMutator).Parallel()
register(preDeps)
ctx.BottomUp("deps", depsMutator).Parallel()
register(postDeps)
}
type registerMutatorsContext struct{}
type RegisterMutatorsContext interface {
TopDown(name string, m AndroidTopDownMutator) MutatorHandle
BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle
}
type RegisterMutatorFunc func(RegisterMutatorsContext)
var preArch, preDeps, postDeps []RegisterMutatorFunc
func PreArchMutators(f RegisterMutatorFunc) {
preArch = append(preArch, f)
}
func PreDepsMutators(f RegisterMutatorFunc) {
preDeps = append(preDeps, f)
}
func PostDepsMutators(f RegisterMutatorFunc) {
postDeps = append(postDeps, f)
}
type AndroidTopDownMutator func(TopDownMutatorContext) type AndroidTopDownMutator func(TopDownMutatorContext)
type TopDownMutatorContext interface { type TopDownMutatorContext interface {
@ -40,7 +95,7 @@ type androidBottomUpMutatorContext struct {
androidBaseContextImpl androidBaseContextImpl
} }
func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandle { func (registerMutatorsContext) BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle {
f := func(ctx blueprint.BottomUpMutatorContext) { f := func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok { if a, ok := ctx.Module().(Module); ok {
actx := &androidBottomUpMutatorContext{ actx := &androidBottomUpMutatorContext{
@ -55,7 +110,7 @@ func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandl
return mutator return mutator
} }
func RegisterTopDownMutator(name string, m AndroidTopDownMutator) MutatorHandle { func (registerMutatorsContext) TopDown(name string, m AndroidTopDownMutator) MutatorHandle {
f := func(ctx blueprint.TopDownMutatorContext) { f := func(ctx blueprint.TopDownMutatorContext) {
if a, ok := ctx.Module().(Module); ok { if a, ok := ctx.Module().(Module); ok {
actx := &androidTopDownMutatorContext{ actx := &androidTopDownMutatorContext{
@ -78,3 +133,9 @@ func (mutator *mutator) Parallel() MutatorHandle {
mutator.parallel = true mutator.parallel = true
return mutator return mutator
} }
func depsMutator(ctx BottomUpMutatorContext) {
if m, ok := ctx.Module().(Module); ok {
m.DepsMutator(ctx)
}
}

View File

@ -58,6 +58,8 @@ func NewContext() *blueprint.Context {
ctx.RegisterSingletonType(t.name, t.factory) ctx.RegisterSingletonType(t.name, t.factory)
} }
registerMutators()
for _, t := range mutators { for _, t := range mutators {
var handle blueprint.MutatorHandle var handle blueprint.MutatorHandle
if t.bottomUpMutator != nil { if t.bottomUpMutator != nil {

View File

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

View File

@ -34,20 +34,20 @@ import (
func init() { func init() {
android.RegisterModuleType("cc_defaults", defaultsFactory) android.RegisterModuleType("cc_defaults", defaultsFactory)
// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
// the Go initialization order because this package depends on common, so common's init ctx.BottomUp("link", linkageMutator).Parallel()
// functions will run first. ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
android.RegisterBottomUpMutator("link", linkageMutator).Parallel() ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
android.RegisterBottomUpMutator("ndk_api", ndkApiMutator).Parallel() ctx.BottomUp("begin", beginMutator).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.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)).Parallel() ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan)) ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)).Parallel() ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
})
pctx.Import("android/soong/cc/config") pctx.Import("android/soong/cc/config")
} }
@ -534,7 +534,11 @@ func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
c.begin(ctx) c.begin(ctx)
} }
func (c *Module) depsMutator(actx android.BottomUpMutatorContext) { func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
if !c.Enabled() {
return
}
ctx := &baseModuleContext{ ctx := &baseModuleContext{
BaseContext: actx, BaseContext: actx,
moduleContextImpl: moduleContextImpl{ moduleContextImpl: moduleContextImpl{
@ -641,12 +645,6 @@ func beginMutator(ctx android.BottomUpMutatorContext) {
} }
} }
func depsMutator(ctx android.BottomUpMutatorContext) {
if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
c.depsMutator(ctx)
}
}
func (c *Module) clang(ctx BaseModuleContext) bool { func (c *Module) clang(ctx BaseModuleContext) bool {
clang := Bool(c.Properties.Clang) clang := Bool(c.Properties.Clang)
@ -911,6 +909,9 @@ type Defaults struct {
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func defaultsFactory() (blueprint.Module, []interface{}) { func defaultsFactory() (blueprint.Module, []interface{}) {
return DefaultsFactory() return DefaultsFactory()
} }

View File

@ -56,6 +56,9 @@ type headerModule struct {
installPaths []string installPaths []string
} }
func (m *headerModule) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
srcFiles := ctx.ExpandSources(m.properties.Srcs, nil) srcFiles := ctx.ExpandSources(m.properties.Srcs, nil)
for _, header := range srcFiles { for _, header := range srcFiles {

View File

@ -25,8 +25,6 @@ import (
func init() { func init() {
android.RegisterModuleType("gensrcs", GenSrcsFactory) android.RegisterModuleType("gensrcs", GenSrcsFactory)
android.RegisterModuleType("genrule", GenRuleFactory) android.RegisterModuleType("genrule", GenRuleFactory)
android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator).Parallel()
} }
var ( var (
@ -95,7 +93,7 @@ func (g *generator) GeneratedHeaderDir() android.Path {
return g.genPath return g.genPath
} }
func genruleDepsMutator(ctx android.BottomUpMutatorContext) { func (g *generator) DepsMutator(ctx android.BottomUpMutatorContext) {
if g, ok := ctx.Module().(*generator); ok { if g, ok := ctx.Module().(*generator); ok {
if g.properties.Tool != "" { if g.properties.Tool != "" {
ctx.AddFarVariationDependencies([]blueprint.Variation{ ctx.AddFarVariationDependencies([]blueprint.Variation{

View File

@ -190,7 +190,7 @@ func (j *javaBase) BootClasspath(ctx android.BaseContext) string {
var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"} var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
func javaDepsMutator(ctx android.BottomUpMutatorContext) { func (j *javaBase) DepsMutator(ctx android.BottomUpMutatorContext) {
if j, ok := ctx.Module().(JavaModuleType); ok { if j, ok := ctx.Module().(JavaModuleType); ok {
ctx.AddDependency(ctx.Module(), nil, j.JavaDependencies(ctx)...) ctx.AddDependency(ctx.Module(), nil, j.JavaDependencies(ctx)...)
} }
@ -513,6 +513,9 @@ type JavaPrebuilt struct {
classJarSpecs, resourceJarSpecs []jarSpec classJarSpecs, resourceJarSpecs []jarSpec
} }
func (j *JavaPrebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(j.properties.Srcs) != 1 { if len(j.properties.Srcs) != 1 {
ctx.ModuleErrorf("expected exactly one jar in srcs") ctx.ModuleErrorf("expected exactly one jar in srcs")