Merge "add type to modules created by LoadHookContext"
This commit is contained in:
@@ -15,7 +15,10 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
@@ -88,7 +91,19 @@ func (l *loadHookContext) PrependProperties(props ...interface{}) {
|
|||||||
|
|
||||||
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
|
||||||
inherited := []interface{}{&l.Module().base().commonProperties}
|
inherited := []interface{}{&l.Module().base().commonProperties}
|
||||||
module := l.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module)
|
|
||||||
|
var typeName string
|
||||||
|
if typeNameLookup, ok := ModuleTypeByFactory()[reflect.ValueOf(factory)]; ok {
|
||||||
|
typeName = typeNameLookup
|
||||||
|
} else {
|
||||||
|
factoryPtr := reflect.ValueOf(factory).Pointer()
|
||||||
|
factoryFunc := runtime.FuncForPC(factoryPtr)
|
||||||
|
filePath, _ := factoryFunc.FileLine(factoryPtr)
|
||||||
|
typeName = fmt.Sprintf("%s_%s", path.Base(filePath), factoryFunc.Name())
|
||||||
|
}
|
||||||
|
typeName = typeName + "_loadHookModule"
|
||||||
|
|
||||||
|
module := l.bp.CreateModule(ModuleFactoryAdaptor(factory), typeName, append(inherited, props...)...).(Module)
|
||||||
|
|
||||||
if l.Module().base().variableProperties != nil && module.base().variableProperties != nil {
|
if l.Module().base().variableProperties != nil && module.base().variableProperties != nil {
|
||||||
src := l.Module().base().variableProperties
|
src := l.Module().base().variableProperties
|
||||||
|
@@ -59,6 +59,7 @@ func (t moduleType) register(ctx *Context) {
|
|||||||
|
|
||||||
var moduleTypes []moduleType
|
var moduleTypes []moduleType
|
||||||
var moduleTypesForDocs = map[string]reflect.Value{}
|
var moduleTypesForDocs = map[string]reflect.Value{}
|
||||||
|
var moduleTypeByFactory = map[reflect.Value]string{}
|
||||||
|
|
||||||
type singleton struct {
|
type singleton struct {
|
||||||
// True if this should be registered as a pre-singleton, false otherwise.
|
// True if this should be registered as a pre-singleton, false otherwise.
|
||||||
@@ -140,6 +141,7 @@ func RegisterModuleType(name string, factory ModuleFactory) {
|
|||||||
// RegisterModuleType was a lambda.
|
// RegisterModuleType was a lambda.
|
||||||
func RegisterModuleTypeForDocs(name string, factory reflect.Value) {
|
func RegisterModuleTypeForDocs(name string, factory reflect.Value) {
|
||||||
moduleTypesForDocs[name] = factory
|
moduleTypesForDocs[name] = factory
|
||||||
|
moduleTypeByFactory[factory] = name
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterSingletonType(name string, factory SingletonFactory) {
|
func RegisterSingletonType(name string, factory SingletonFactory) {
|
||||||
@@ -228,6 +230,10 @@ func ModuleTypeFactoriesForDocs() map[string]reflect.Value {
|
|||||||
return moduleTypesForDocs
|
return moduleTypesForDocs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ModuleTypeByFactory() map[reflect.Value]string {
|
||||||
|
return moduleTypeByFactory
|
||||||
|
}
|
||||||
|
|
||||||
// Interface for registering build components.
|
// Interface for registering build components.
|
||||||
//
|
//
|
||||||
// Provided to allow registration of build components to be shared between the runtime
|
// Provided to allow registration of build components to be shared between the runtime
|
||||||
|
Reference in New Issue
Block a user