From c05b034e95636ab9692d41b45f9c8cca67950c0c Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Sat, 6 Mar 2021 13:28:13 +0000 Subject: [PATCH] Separate the collation of mutators from registration This separates the collation of mutators from the registration of them to allow the test infrastructure to sort the mutator order to match that used at runtime. Bug: 181953909 Test: m nothing Change-Id: I01a073289d44417f327b0815c09eb1c033d464f2 --- android/mutator.go | 11 +++++++++-- android/register.go | 3 ++- android/testing.go | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/android/mutator.go b/android/mutator.go index 8bfb24ed3..9552aa15c 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -69,7 +69,14 @@ func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutat mctx.mutators.registerAll(ctx) } -func registerMutators(ctx *Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) { +// collateGloballyRegisteredMutators constructs the list of mutators that have been registered +// with the InitRegistrationContext and will be used at runtime. +func collateGloballyRegisteredMutators() sortableComponents { + return collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps) +} + +// collateRegisteredMutators constructs a single list of mutators from the separate lists. +func collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) sortableComponents { mctx := ®isterMutatorsContext{} register := func(funcs []RegisterMutatorFunc) { @@ -89,7 +96,7 @@ func registerMutators(ctx *Context, preArch, preDeps, postDeps, finalDeps []Regi mctx.finalPhase = true register(finalDeps) - mctx.mutators.registerAll(ctx) + return mctx.mutators } type registerMutatorsContext struct { diff --git a/android/register.go b/android/register.go index 5efa280cc..278a04f26 100644 --- a/android/register.go +++ b/android/register.go @@ -188,7 +188,8 @@ func (ctx *Context) Register() { singletons.registerAll(ctx) - registerMutators(ctx, preArch, preDeps, postDeps, finalDeps) + mutators := collateGloballyRegisteredMutators() + mutators.registerAll(ctx) ctx.RegisterSingletonType("bazeldeps", SingletonFactoryAdaptor(ctx, BazelSingleton)) diff --git a/android/testing.go b/android/testing.go index 556db7863..b134eae38 100644 --- a/android/testing.go +++ b/android/testing.go @@ -141,7 +141,8 @@ func (ctx *TestContext) DepsBp2BuildMutators(f RegisterMutatorFunc) { } func (ctx *TestContext) Register() { - registerMutators(ctx.Context, ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps) + mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps) + mutators.registerAll(ctx.Context) ctx.RegisterSingletonType("env", EnvSingleton) }