Update CreateModule to require a type name

This makes the LoadHook and TopDownMutatorContext interfaces for
CreateModule the same.

Test: CI
Change-Id: I30122099bdf109cda40f9d81a574dd6fa861f459
This commit is contained in:
Liz Kammer 2022-04-26 09:15:13 -04:00
parent 8097d1a0e6
commit 9967d62fad
2 changed files with 6 additions and 5 deletions

View file

@ -461,17 +461,17 @@ func createTestMutator(ctx TopDownMutatorContext) {
Deps []string Deps []string
} }
ctx.CreateModule(newBarModule, &props{ ctx.CreateModule(newBarModule, "new_bar", &props{
Name: "B", Name: "B",
Deps: []string{"D"}, Deps: []string{"D"},
}) })
ctx.CreateModule(newBarModule, &props{ ctx.CreateModule(newBarModule, "new_bar", &props{
Name: "C", Name: "C",
Deps: []string{"D"}, Deps: []string{"D"},
}) })
ctx.CreateModule(newFooModule, &props{ ctx.CreateModule(newFooModule, "new_foo", &props{
Name: "D", Name: "D",
}) })
} }

View file

@ -862,7 +862,7 @@ type TopDownMutatorContext interface {
// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
// the specified property structs to it as if the properties were set in a blueprint file. // the specified property structs to it as if the properties were set in a blueprint file.
CreateModule(ModuleFactory, ...interface{}) Module CreateModule(ModuleFactory, string, ...interface{}) Module
} }
type BottomUpMutatorContext interface { type BottomUpMutatorContext interface {
@ -1228,13 +1228,14 @@ func (mctx *mutatorContext) Rename(name string) {
mctx.rename = append(mctx.rename, rename{mctx.module.group, name}) mctx.rename = append(mctx.rename, rename{mctx.module.group, name})
} }
func (mctx *mutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { func (mctx *mutatorContext) CreateModule(factory ModuleFactory, typeName string, props ...interface{}) Module {
module := newModule(factory) module := newModule(factory)
module.relBlueprintsFile = mctx.module.relBlueprintsFile module.relBlueprintsFile = mctx.module.relBlueprintsFile
module.pos = mctx.module.pos module.pos = mctx.module.pos
module.propertyPos = mctx.module.propertyPos module.propertyPos = mctx.module.propertyPos
module.createdBy = mctx.module module.createdBy = mctx.module
module.typeName = typeName
for _, p := range props { for _, p := range props {
err := proptools.AppendMatchingProperties(module.properties, p, nil) err := proptools.AppendMatchingProperties(module.properties, p, nil)