Merge "Share CreateModule between hooks & mutators"
This commit is contained in:
commit
60fe34a79d
2 changed files with 25 additions and 28 deletions
|
@ -89,8 +89,17 @@ func (l *loadHookContext) PrependProperties(props ...interface{}) {
|
|||
l.appendPrependHelper(props, proptools.PrependMatchingProperties)
|
||||
}
|
||||
|
||||
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
||||
inherited := []interface{}{&l.Module().base().commonProperties}
|
||||
func (l *loadHookContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
|
||||
return l.bp.CreateModule(factory, name, props...)
|
||||
}
|
||||
|
||||
type createModuleContext interface {
|
||||
Module() Module
|
||||
createModule(blueprint.ModuleFactory, string, ...interface{}) blueprint.Module
|
||||
}
|
||||
|
||||
func createModule(ctx createModuleContext, factory ModuleFactory, ext string, props ...interface{}) Module {
|
||||
inherited := []interface{}{&ctx.Module().base().commonProperties}
|
||||
|
||||
var typeName string
|
||||
if typeNameLookup, ok := ModuleTypeByFactory()[reflect.ValueOf(factory)]; ok {
|
||||
|
@ -101,12 +110,12 @@ func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface
|
|||
filePath, _ := factoryFunc.FileLine(factoryPtr)
|
||||
typeName = fmt.Sprintf("%s_%s", path.Base(filePath), factoryFunc.Name())
|
||||
}
|
||||
typeName = typeName + "_loadHookModule"
|
||||
typeName = typeName + "_" + ext
|
||||
|
||||
module := l.bp.CreateModule(ModuleFactoryAdaptor(factory), typeName, append(inherited, props...)...).(Module)
|
||||
module := ctx.createModule(ModuleFactoryAdaptor(factory), typeName, append(inherited, props...)...).(Module)
|
||||
|
||||
if l.Module().base().variableProperties != nil && module.base().variableProperties != nil {
|
||||
src := l.Module().base().variableProperties
|
||||
if ctx.Module().base().variableProperties != nil && module.base().variableProperties != nil {
|
||||
src := ctx.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
|
||||
|
@ -122,6 +131,10 @@ func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface
|
|||
return module
|
||||
}
|
||||
|
||||
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
||||
return createModule(l, factory, "_loadHookModule", props...)
|
||||
}
|
||||
|
||||
func (l *loadHookContext) registerScopedModuleType(name string, factory blueprint.ModuleFactory) {
|
||||
l.bp.RegisterScopedModuleType(name, factory)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue