Merge "Separate the collation of mutators from registration"
diff --git a/android/mutator.go b/android/mutator.go
index 8bfb24e..9552aa1 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -69,7 +69,14 @@
 	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 := &registerMutatorsContext{}
 
 	register := func(funcs []RegisterMutatorFunc) {
@@ -89,7 +96,7 @@
 	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 5efa280..278a04f 100644
--- a/android/register.go
+++ b/android/register.go
@@ -188,7 +188,8 @@
 
 	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 556db78..b134eae 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -141,7 +141,8 @@
 }
 
 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)
 }