add type to modules created by LoadHookContext

Modules created by a LoadHookContext do not currently set a module type
when creating new modules, but it would make analysis of the
module-graph.json much easier if this module type information was available.

Bug: 174879786
Test: m json-module-graph && check that module which previously had a
    blank module type now have the field populated
Change-Id: I3be5d259694a1540d21deb8a665ec7bea3464054
This commit is contained in:
Sam Delmerico
2022-03-09 20:46:37 +00:00
parent 10eada743a
commit 286bf26c2c
2 changed files with 22 additions and 1 deletions

View File

@@ -15,7 +15,10 @@
package android
import (
"fmt"
"path"
"reflect"
"runtime"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -88,7 +91,19 @@ func (l *loadHookContext) PrependProperties(props ...interface{}) {
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
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 {
src := l.Module().base().variableProperties