Loading android/hooks.go +60 −24 Original line number Diff line number Diff line Loading @@ -15,7 +15,10 @@ package android import ( "reflect" "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) // This file implements hooks that external module types can use to inject logic into existing Loading @@ -34,19 +37,68 @@ type LoadHookContext interface { } func AddLoadHook(m blueprint.Module, hook func(LoadHookContext)) { h := &m.(Module).base().hooks h.load = append(h.load, hook) blueprint.AddLoadHook(m, func(ctx blueprint.LoadHookContext) { actx := &loadHookContext{ earlyModuleContext: m.(Module).base().earlyModuleContextFactory(ctx), bp: ctx, } hook(actx) }) } func (x *hooks) runLoadHooks(ctx LoadHookContext, m *ModuleBase) { if len(x.load) > 0 { for _, x := range x.load { x(ctx) if ctx.Failed() { return type loadHookContext struct { earlyModuleContext bp blueprint.LoadHookContext module Module } func (l *loadHookContext) AppendProperties(props ...interface{}) { for _, p := range props { err := proptools.AppendMatchingProperties(l.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) } else { panic(err) } } } } func (l *loadHookContext) PrependProperties(props ...interface{}) { for _, p := range props { err := proptools.PrependMatchingProperties(l.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) } else { panic(err) } } } } 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) if l.Module().base().variableProperties != nil && module.base().variableProperties != nil { src := l.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).Elem()).Interface(), } err := proptools.AppendMatchingProperties(dst, src, nil) if err != nil { panic(err) } } return module } type InstallHookContext interface { Loading Loading @@ -94,21 +146,5 @@ func (x *hooks) runInstallHooks(ctx ModuleContext, path InstallPath, symlink boo } type hooks struct { load []func(LoadHookContext) install []func(InstallHookContext) } func registerLoadHookMutator(ctx RegisterMutatorsContext) { ctx.TopDown("load_hooks", LoadHookMutator).Parallel() } func LoadHookMutator(ctx TopDownMutatorContext) { if m, ok := ctx.Module().(Module); ok { m.base().commonProperties.DebugName = ctx.ModuleName() // Cast through *topDownMutatorContext because AppendProperties is implemented // on *topDownMutatorContext but not exposed through TopDownMutatorContext var loadHookCtx LoadHookContext = ctx.(*topDownMutatorContext) m.base().hooks.runLoadHooks(loadHookCtx, m.base()) } } android/module.go +8 −8 Original line number Diff line number Diff line Loading @@ -953,7 +953,7 @@ func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { } } func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind { func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind { var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific) var deviceSpecific = Bool(m.commonProperties.Device_specific) var productSpecific = Bool(m.commonProperties.Product_specific) Loading Loading @@ -1012,9 +1012,9 @@ func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleK } } func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.BaseModuleContext) earlyModuleContext { func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext { return earlyModuleContext{ BaseModuleContext: ctx, EarlyModuleContext: ctx, kind: determineModuleKind(m, ctx), config: ctx.Config().(Config), } Loading Loading @@ -1134,7 +1134,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } type earlyModuleContext struct { blueprint.BaseModuleContext blueprint.EarlyModuleContext kind moduleKind config Config Loading @@ -1157,12 +1157,12 @@ func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Pa } func (e *earlyModuleContext) Module() Module { module, _ := e.BaseModuleContext.Module().(Module) module, _ := e.EarlyModuleContext.Module().(Module) return module } func (e *earlyModuleContext) Config() Config { return e.BaseModuleContext.Config().(Config) return e.EarlyModuleContext.Config().(Config) } func (e *earlyModuleContext) AConfig() Config { Loading android/mutator.go +0 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,6 @@ type RegisterMutatorsContext interface { type RegisterMutatorFunc func(RegisterMutatorsContext) var preArch = []RegisterMutatorFunc{ registerLoadHookMutator, RegisterNamespaceMutator, // Rename package module types. RegisterPackageRenamer, Loading android/namespace.go +1 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,7 @@ func (r *NameResolver) NewModule(ctx blueprint.NamespaceContext, moduleGroup blu if ok { // inform the module whether its namespace is one that we want to export to Make amod.base().commonProperties.NamespaceExportedToMake = ns.exportToKati amod.base().commonProperties.DebugName = module.Name() } return ns, nil Loading android/testing.go +15 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ func NewTestContext() *TestContext { ctx.SetNameInterface(nameResolver) ctx.preArch = append(ctx.preArch, registerLoadHookMutator) ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator) return ctx Loading @@ -54,6 +52,7 @@ type TestContext struct { *Context preArch, preDeps, postDeps []RegisterMutatorFunc NameResolver *NameResolver config Config } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { Loading @@ -76,6 +75,20 @@ func (ctx *TestContext) Register(config Config) { registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps) ctx.RegisterSingletonType("env", EnvSingleton) ctx.config = config } func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) { // This function adapts the old style ParseFileList calls that are spread throughout the tests // to the new style that takes a config. return ctx.Context.ParseFileList(rootDir, filePaths, ctx.config) } func (ctx *TestContext) ParseBlueprintsFiles(rootDir string) (deps []string, errs []error) { // This function adapts the old style ParseBlueprintsFiles calls that are spread throughout the // tests to the new style that takes a config. return ctx.Context.ParseBlueprintsFiles(rootDir, ctx.config) } func (ctx *TestContext) RegisterModuleType(name string, factory ModuleFactory) { Loading Loading
android/hooks.go +60 −24 Original line number Diff line number Diff line Loading @@ -15,7 +15,10 @@ package android import ( "reflect" "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) // This file implements hooks that external module types can use to inject logic into existing Loading @@ -34,19 +37,68 @@ type LoadHookContext interface { } func AddLoadHook(m blueprint.Module, hook func(LoadHookContext)) { h := &m.(Module).base().hooks h.load = append(h.load, hook) blueprint.AddLoadHook(m, func(ctx blueprint.LoadHookContext) { actx := &loadHookContext{ earlyModuleContext: m.(Module).base().earlyModuleContextFactory(ctx), bp: ctx, } hook(actx) }) } func (x *hooks) runLoadHooks(ctx LoadHookContext, m *ModuleBase) { if len(x.load) > 0 { for _, x := range x.load { x(ctx) if ctx.Failed() { return type loadHookContext struct { earlyModuleContext bp blueprint.LoadHookContext module Module } func (l *loadHookContext) AppendProperties(props ...interface{}) { for _, p := range props { err := proptools.AppendMatchingProperties(l.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) } else { panic(err) } } } } func (l *loadHookContext) PrependProperties(props ...interface{}) { for _, p := range props { err := proptools.PrependMatchingProperties(l.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) } else { panic(err) } } } } 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) if l.Module().base().variableProperties != nil && module.base().variableProperties != nil { src := l.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).Elem()).Interface(), } err := proptools.AppendMatchingProperties(dst, src, nil) if err != nil { panic(err) } } return module } type InstallHookContext interface { Loading Loading @@ -94,21 +146,5 @@ func (x *hooks) runInstallHooks(ctx ModuleContext, path InstallPath, symlink boo } type hooks struct { load []func(LoadHookContext) install []func(InstallHookContext) } func registerLoadHookMutator(ctx RegisterMutatorsContext) { ctx.TopDown("load_hooks", LoadHookMutator).Parallel() } func LoadHookMutator(ctx TopDownMutatorContext) { if m, ok := ctx.Module().(Module); ok { m.base().commonProperties.DebugName = ctx.ModuleName() // Cast through *topDownMutatorContext because AppendProperties is implemented // on *topDownMutatorContext but not exposed through TopDownMutatorContext var loadHookCtx LoadHookContext = ctx.(*topDownMutatorContext) m.base().hooks.runLoadHooks(loadHookCtx, m.base()) } }
android/module.go +8 −8 Original line number Diff line number Diff line Loading @@ -953,7 +953,7 @@ func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { } } func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind { func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind { var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific) var deviceSpecific = Bool(m.commonProperties.Device_specific) var productSpecific = Bool(m.commonProperties.Product_specific) Loading Loading @@ -1012,9 +1012,9 @@ func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleK } } func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.BaseModuleContext) earlyModuleContext { func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext { return earlyModuleContext{ BaseModuleContext: ctx, EarlyModuleContext: ctx, kind: determineModuleKind(m, ctx), config: ctx.Config().(Config), } Loading Loading @@ -1134,7 +1134,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } type earlyModuleContext struct { blueprint.BaseModuleContext blueprint.EarlyModuleContext kind moduleKind config Config Loading @@ -1157,12 +1157,12 @@ func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Pa } func (e *earlyModuleContext) Module() Module { module, _ := e.BaseModuleContext.Module().(Module) module, _ := e.EarlyModuleContext.Module().(Module) return module } func (e *earlyModuleContext) Config() Config { return e.BaseModuleContext.Config().(Config) return e.EarlyModuleContext.Config().(Config) } func (e *earlyModuleContext) AConfig() Config { Loading
android/mutator.go +0 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,6 @@ type RegisterMutatorsContext interface { type RegisterMutatorFunc func(RegisterMutatorsContext) var preArch = []RegisterMutatorFunc{ registerLoadHookMutator, RegisterNamespaceMutator, // Rename package module types. RegisterPackageRenamer, Loading
android/namespace.go +1 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,7 @@ func (r *NameResolver) NewModule(ctx blueprint.NamespaceContext, moduleGroup blu if ok { // inform the module whether its namespace is one that we want to export to Make amod.base().commonProperties.NamespaceExportedToMake = ns.exportToKati amod.base().commonProperties.DebugName = module.Name() } return ns, nil Loading
android/testing.go +15 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ func NewTestContext() *TestContext { ctx.SetNameInterface(nameResolver) ctx.preArch = append(ctx.preArch, registerLoadHookMutator) ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator) return ctx Loading @@ -54,6 +52,7 @@ type TestContext struct { *Context preArch, preDeps, postDeps []RegisterMutatorFunc NameResolver *NameResolver config Config } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { Loading @@ -76,6 +75,20 @@ func (ctx *TestContext) Register(config Config) { registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps) ctx.RegisterSingletonType("env", EnvSingleton) ctx.config = config } func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) { // This function adapts the old style ParseFileList calls that are spread throughout the tests // to the new style that takes a config. return ctx.Context.ParseFileList(rootDir, filePaths, ctx.config) } func (ctx *TestContext) ParseBlueprintsFiles(rootDir string) (deps []string, errs []error) { // This function adapts the old style ParseBlueprintsFiles calls that are spread throughout the // tests to the new style that takes a config. return ctx.Context.ParseBlueprintsFiles(rootDir, ctx.config) } func (ctx *TestContext) RegisterModuleType(name string, factory ModuleFactory) { Loading