Add sortableComponent abstraction
In preparation for following changes that will ensure the order of registration (and so execution) for mutators, singletons and pre-singletons in tests match the order in runtime this change creates the sortableComponent interface to allow those to be sorted in the same way without having to resort to reflection. By moving the registration code into each component type this change also eliminates some unnecessary duplication of that code. Bug: 181953909 Test: m nothing Change-Id: I597b461b966c84faaeb13e7dff765f1fadd99981
This commit is contained in:
@@ -33,22 +33,8 @@ import (
|
||||
// run FinalDeps mutators (CreateVariations disallowed in this phase)
|
||||
// continue on to GenerateAndroidBuildActions
|
||||
|
||||
func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
|
||||
for _, t := range mutators {
|
||||
var handle blueprint.MutatorHandle
|
||||
if t.bottomUpMutator != nil {
|
||||
handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
|
||||
} else if t.topDownMutator != nil {
|
||||
handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator)
|
||||
}
|
||||
if t.parallel {
|
||||
handle.Parallel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
|
||||
func RegisterMutatorsForBazelConversion(ctx *blueprint.Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) {
|
||||
func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) {
|
||||
mctx := ®isterMutatorsContext{
|
||||
bazelConversionMode: true,
|
||||
}
|
||||
@@ -80,10 +66,10 @@ func RegisterMutatorsForBazelConversion(ctx *blueprint.Context, preArchMutators,
|
||||
f(mctx)
|
||||
}
|
||||
|
||||
registerMutatorsToContext(ctx, mctx.mutators)
|
||||
mctx.mutators.registerAll(ctx)
|
||||
}
|
||||
|
||||
func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) {
|
||||
func registerMutators(ctx *Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) {
|
||||
mctx := ®isterMutatorsContext{}
|
||||
|
||||
register := func(funcs []RegisterMutatorFunc) {
|
||||
@@ -103,11 +89,11 @@ func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalD
|
||||
mctx.finalPhase = true
|
||||
register(finalDeps)
|
||||
|
||||
registerMutatorsToContext(ctx, mctx.mutators)
|
||||
mctx.mutators.registerAll(ctx)
|
||||
}
|
||||
|
||||
type registerMutatorsContext struct {
|
||||
mutators []*mutator
|
||||
mutators sortableComponents
|
||||
finalPhase bool
|
||||
bazelConversionMode bool
|
||||
}
|
||||
@@ -473,6 +459,23 @@ func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) Mutator
|
||||
return mutator
|
||||
}
|
||||
|
||||
func (mutator *mutator) componentName() string {
|
||||
return mutator.name
|
||||
}
|
||||
|
||||
func (mutator *mutator) register(ctx *Context) {
|
||||
blueprintCtx := ctx.Context
|
||||
var handle blueprint.MutatorHandle
|
||||
if mutator.bottomUpMutator != nil {
|
||||
handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator)
|
||||
} else if mutator.topDownMutator != nil {
|
||||
handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator)
|
||||
}
|
||||
if mutator.parallel {
|
||||
handle.Parallel()
|
||||
}
|
||||
}
|
||||
|
||||
type MutatorHandle interface {
|
||||
Parallel() MutatorHandle
|
||||
}
|
||||
|
Reference in New Issue
Block a user