Add FinalDeps mutator phase, where CreateVariations is disallowed.

This is for use to add dependencies between specific module variants,
without getting the dependencies potentially duplicated as more
variants are created.

Moved genrule tool dependency registration to this phase, to avoid
potential splitting of its dependencies, and for consistency with the
same kind of dependency on dex2oat in https://r.android.com/1205730.

Test: m nothing
Bug: 145934348
Change-Id: I1f9e75354e359cef5f41d14e5016b0a67d7655d7
This commit is contained in:
Martin Stjernholm
2020-01-16 15:12:04 +00:00
parent dca59a516d
commit 710ec3aef2
6 changed files with 163 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ import (
// run Pre-deps mutators
// run depsMutator
// run PostDeps mutators
// run FinalDeps mutators (CreateVariations disallowed in this phase)
// continue on to GenerateAndroidBuildActions
func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
@@ -43,7 +44,7 @@ func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
}
}
func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps []RegisterMutatorFunc) {
func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) {
mctx := &registerMutatorsContext{}
register := func(funcs []RegisterMutatorFunc) {
@@ -60,11 +61,15 @@ func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps []Regis
register(postDeps)
mctx.finalPhase = true
register(finalDeps)
registerMutatorsToContext(ctx, mctx.mutators)
}
type registerMutatorsContext struct {
mutators []*mutator
mutators []*mutator
finalPhase bool
}
type RegisterMutatorsContext interface {
@@ -102,6 +107,8 @@ var postDeps = []RegisterMutatorFunc{
RegisterOverridePostDepsMutators,
}
var finalDeps = []RegisterMutatorFunc{}
func PreArchMutators(f RegisterMutatorFunc) {
preArch = append(preArch, f)
}
@@ -114,6 +121,10 @@ func PostDepsMutators(f RegisterMutatorFunc) {
postDeps = append(postDeps, f)
}
func FinalDepsMutators(f RegisterMutatorFunc) {
finalDeps = append(finalDeps, f)
}
type TopDownMutator func(TopDownMutatorContext)
type TopDownMutatorContext interface {
@@ -156,14 +167,17 @@ type BottomUpMutatorContext interface {
type bottomUpMutatorContext struct {
bp blueprint.BottomUpMutatorContext
baseModuleContext
finalPhase bool
}
func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
finalPhase := x.finalPhase
f := func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
actx := &bottomUpMutatorContext{
bp: ctx,
baseModuleContext: a.base().baseModuleContextFactory(ctx),
finalPhase: finalPhase,
}
m(actx)
}
@@ -285,6 +299,10 @@ func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, t
}
func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
if b.finalPhase {
panic("CreateVariations not allowed in FinalDepsMutators")
}
modules := b.bp.CreateVariations(variations...)
aModules := make([]Module, len(modules))
@@ -299,6 +317,10 @@ func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module
}
func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
if b.finalPhase {
panic("CreateLocalVariations not allowed in FinalDepsMutators")
}
modules := b.bp.CreateLocalVariations(variations...)
aModules := make([]Module, len(modules))