Share CreateModule between hooks & mutators

These contained duplicate code, but evolved separately in the effort to
identify module type of those created with CreateModule. This refactors
to share a common implementation between the two.

Test: m json-module-graph and verify Type fields
Test: CI
Change-Id: Ifdb9a006d9b1bef7411f9ce3a4384797693b4bfc
This commit is contained in:
Liz Kammer
2022-04-26 09:08:55 -04:00
parent e31a071389
commit f31c90050c
2 changed files with 25 additions and 28 deletions

View File

@@ -15,12 +15,9 @@
package android
import (
"reflect"
"android/soong/bazel"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
// Phases:
@@ -553,29 +550,16 @@ func (t *topDownMutatorContext) Rename(name string) {
t.Module().base().commonProperties.DebugName = name
}
func (t *topDownMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
return t.bp.CreateModule(factory, name, props...)
}
func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
inherited := []interface{}{&t.Module().base().commonProperties}
module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module)
if t.Module().base().variableProperties != nil && module.base().variableProperties != nil {
src := t.Module().base().variableProperties
dst := []interface{}{
module.base().variableProperties,
// Put an empty copy of the src properties into dst so that properties in src that are not in dst
// don't cause a "failed to find property to extend" error.
proptools.CloneEmptyProperties(reflect.ValueOf(src)).Interface(),
}
err := proptools.AppendMatchingProperties(dst, src, nil)
if err != nil {
panic(err)
}
}
return module
return createModule(t, factory, "_topDownMutatorModule", props...)
}
func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module {
module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), props...).(Module)
module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), "", props...).(Module)
return module
}