Support registering hard coded pre arch mutators

Some pre arch mutators are hard coded into mutator.go and so could not
share code for registering those mutators between tests and runtime.
This change adds a new HardCodedPreArchMutators(RegisterMutatorFunc)
method to RegistrationContext which allows hard coded mutators to be
registered alongside other build components during init() and testing.

The method is treated as a noop on the InitRegistrationContext and
behaves just like the PreArchMutators(RegisterMutatorFunc) method on
the TestingContext.

Bug: 146540677
Test: m nothing
Change-Id: I6f8b1e2d54d9dc4e86f951ced61d1ee7b0fe4b2e
This commit is contained in:
Paul Duffin 2020-01-14 12:09:36 +00:00
parent 90169baf0e
commit a80ef84652
2 changed files with 15 additions and 0 deletions

View File

@ -127,6 +127,12 @@ type RegistrationContext interface {
RegisterModuleType(name string, factory ModuleFactory)
RegisterSingletonType(name string, factory SingletonFactory)
PreArchMutators(f RegisterMutatorFunc)
// Register pre arch mutators that are hard coded into mutator.go.
//
// Only registers mutators for testing, is a noop on the InitRegistrationContext.
HardCodedPreArchMutators(f RegisterMutatorFunc)
PreDepsMutators(f RegisterMutatorFunc)
PostDepsMutators(f RegisterMutatorFunc)
}
@ -180,6 +186,10 @@ func (ctx *initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) {
PreArchMutators(f)
}
func (ctx *initRegistrationContext) HardCodedPreArchMutators(f RegisterMutatorFunc) {
// Nothing to do as the mutators are hard code in preArch in mutator.go
}
func (ctx *initRegistrationContext) PreDepsMutators(f RegisterMutatorFunc) {
PreDepsMutators(f)
}

View File

@ -59,6 +59,11 @@ func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) {
ctx.preArch = append(ctx.preArch, f)
}
func (ctx *TestContext) HardCodedPreArchMutators(f RegisterMutatorFunc) {
// Register mutator function as normal for testing.
ctx.PreArchMutators(f)
}
func (ctx *TestContext) PreDepsMutators(f RegisterMutatorFunc) {
ctx.preDeps = append(ctx.preDeps, f)
}