diff options
author | Colin Cross <ccross@android.com> | 2016-10-12 14:38:15 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2016-10-12 15:33:33 -0700 |
commit | 1e676bef94d84d8800a23b8ed897b24a157173cd (patch) | |
tree | 8e22d852a05b65925a0b696dd54d528aae7aae3b /android | |
parent | 798bfce9d00217716eaee2256878db625b9e6e2e (diff) | |
download | build_soong-1e676bef94d84d8800a23b8ed897b24a157173cd.tar.gz build_soong-1e676bef94d84d8800a23b8ed897b24a157173cd.tar.bz2 build_soong-1e676bef94d84d8800a23b8ed897b24a157173cd.zip |
Control mutator order
Register mutators inside lambdas that are called in a defined order to
correctly order mutators before and after the arch and deps mutators.
Test: build.ninja identical
Change-Id: Iefe2a3515aee8570e76a6e76925db4cda0e9e822
Diffstat (limited to 'android')
-rw-r--r-- | android/arch.go | 2 | ||||
-rw-r--r-- | android/module.go | 10 | ||||
-rw-r--r-- | android/mutator.go | 65 | ||||
-rw-r--r-- | android/register.go | 2 | ||||
-rw-r--r-- | android/variable.go | 4 |
5 files changed, 70 insertions, 13 deletions
diff --git a/android/arch.go b/android/arch.go index 606de48b..61564d84 100644 --- a/android/arch.go +++ b/android/arch.go @@ -260,7 +260,7 @@ func (target Target) String() string { return target.Os.String() + "_" + target.Arch.String() } -func ArchMutator(mctx BottomUpMutatorContext) { +func archMutator(mctx BottomUpMutatorContext) { var module Module var ok bool if module, ok = mctx.Module().(Module); !ok { diff --git a/android/module.go b/android/module.go index d6eee446..06f1fca7 100644 --- a/android/module.go +++ b/android/module.go @@ -24,15 +24,6 @@ import ( "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 ( DeviceSharedLibrary = "shared_library" DeviceStaticLibrary = "static_library" @@ -100,6 +91,7 @@ type Module interface { blueprint.Module GenerateAndroidBuildActions(ModuleContext) + DepsMutator(BottomUpMutatorContext) base() *ModuleBase Enabled() bool diff --git a/android/mutator.go b/android/mutator.go index ff2f9ad4..b375bce2 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -16,6 +16,61 @@ package android 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 TopDownMutatorContext interface { @@ -40,7 +95,7 @@ type androidBottomUpMutatorContext struct { androidBaseContextImpl } -func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandle { +func (registerMutatorsContext) BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle { f := func(ctx blueprint.BottomUpMutatorContext) { if a, ok := ctx.Module().(Module); ok { actx := &androidBottomUpMutatorContext{ @@ -55,7 +110,7 @@ func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandl return mutator } -func RegisterTopDownMutator(name string, m AndroidTopDownMutator) MutatorHandle { +func (registerMutatorsContext) TopDown(name string, m AndroidTopDownMutator) MutatorHandle { f := func(ctx blueprint.TopDownMutatorContext) { if a, ok := ctx.Module().(Module); ok { actx := &androidTopDownMutatorContext{ @@ -78,3 +133,9 @@ func (mutator *mutator) Parallel() MutatorHandle { mutator.parallel = true return mutator } + +func depsMutator(ctx BottomUpMutatorContext) { + if m, ok := ctx.Module().(Module); ok { + m.DepsMutator(ctx) + } +} diff --git a/android/register.go b/android/register.go index 7cc9d50e..f869eede 100644 --- a/android/register.go +++ b/android/register.go @@ -58,6 +58,8 @@ func NewContext() *blueprint.Context { ctx.RegisterSingletonType(t.name, t.factory) } + registerMutators() + for _, t := range mutators { var handle blueprint.MutatorHandle if t.bottomUpMutator != nil { diff --git a/android/variable.go b/android/variable.go index 29d6c7de..ac7c730a 100644 --- a/android/variable.go +++ b/android/variable.go @@ -24,7 +24,9 @@ import ( ) func init() { - RegisterBottomUpMutator("variable", variableMutator).Parallel() + PreDepsMutators(func(ctx RegisterMutatorsContext) { + ctx.BottomUp("variable", variableMutator).Parallel() + }) } type variableProperties struct { |