Merge "Let LoadHooks call CreateModule"
This commit is contained in:
commit
d293e65c82
|
@ -16,7 +16,6 @@ package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file implements hooks that external module types can use to inject logic into existing
|
// This file implements hooks that external module types can use to inject logic into existing
|
||||||
|
@ -31,6 +30,7 @@ type LoadHookContext interface {
|
||||||
BaseContext
|
BaseContext
|
||||||
AppendProperties(...interface{})
|
AppendProperties(...interface{})
|
||||||
PrependProperties(...interface{})
|
PrependProperties(...interface{})
|
||||||
|
CreateModule(blueprint.ModuleFactory, ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arch hooks are run after the module has been split into architecture variants, and can be used
|
// Arch hooks are run after the module has been split into architecture variants, and can be used
|
||||||
|
@ -51,62 +51,22 @@ func AddArchHook(m blueprint.Module, hook func(ArchHookContext)) {
|
||||||
h.arch = append(h.arch, hook)
|
h.arch = append(h.arch, hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
type propertyHookContext struct {
|
func (x *hooks) runLoadHooks(ctx LoadHookContext, m *ModuleBase) {
|
||||||
BaseContext
|
|
||||||
|
|
||||||
module *ModuleBase
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *propertyHookContext) AppendProperties(props ...interface{}) {
|
|
||||||
for _, p := range props {
|
|
||||||
err := proptools.AppendMatchingProperties(ctx.module.customizableProperties, p, nil)
|
|
||||||
if err != nil {
|
|
||||||
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
|
||||||
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
|
||||||
} else {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *propertyHookContext) PrependProperties(props ...interface{}) {
|
|
||||||
for _, p := range props {
|
|
||||||
err := proptools.PrependMatchingProperties(ctx.module.customizableProperties, p, nil)
|
|
||||||
if err != nil {
|
|
||||||
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
|
||||||
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
|
||||||
} else {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *hooks) runLoadHooks(ctx BaseContext, m *ModuleBase) {
|
|
||||||
if len(x.load) > 0 {
|
if len(x.load) > 0 {
|
||||||
mctx := &propertyHookContext{
|
|
||||||
BaseContext: ctx,
|
|
||||||
module: m,
|
|
||||||
}
|
|
||||||
for _, x := range x.load {
|
for _, x := range x.load {
|
||||||
x(mctx)
|
x(ctx)
|
||||||
if mctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *hooks) runArchHooks(ctx BaseContext, m *ModuleBase) {
|
func (x *hooks) runArchHooks(ctx ArchHookContext, m *ModuleBase) {
|
||||||
if len(x.arch) > 0 {
|
if len(x.arch) > 0 {
|
||||||
mctx := &propertyHookContext{
|
|
||||||
BaseContext: ctx,
|
|
||||||
module: m,
|
|
||||||
}
|
|
||||||
for _, x := range x.arch {
|
for _, x := range x.arch {
|
||||||
x(mctx)
|
x(ctx)
|
||||||
if mctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,12 +125,18 @@ type hooks struct {
|
||||||
|
|
||||||
func loadHookMutator(ctx TopDownMutatorContext) {
|
func loadHookMutator(ctx TopDownMutatorContext) {
|
||||||
if m, ok := ctx.Module().(Module); ok {
|
if m, ok := ctx.Module().(Module); ok {
|
||||||
m.base().hooks.runLoadHooks(ctx, m.base())
|
// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
|
||||||
|
// on *androidTopDownMutatorContext but not exposed through TopDownMutatorContext
|
||||||
|
var loadHookCtx LoadHookContext = ctx.(*androidTopDownMutatorContext)
|
||||||
|
m.base().hooks.runLoadHooks(loadHookCtx, m.base())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func archHookMutator(ctx TopDownMutatorContext) {
|
func archHookMutator(ctx TopDownMutatorContext) {
|
||||||
if m, ok := ctx.Module().(Module); ok {
|
if m, ok := ctx.Module().(Module); ok {
|
||||||
m.base().hooks.runArchHooks(ctx, m.base())
|
// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
|
||||||
|
// on *androidTopDownMutatorContext but not exposed through TopDownMutatorContext
|
||||||
|
var archHookCtx ArchHookContext = ctx.(*androidTopDownMutatorContext)
|
||||||
|
m.base().hooks.runArchHooks(archHookCtx, m.base())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Phases:
|
// Phases:
|
||||||
|
@ -112,7 +113,7 @@ type TopDownMutatorContext interface {
|
||||||
|
|
||||||
OtherModuleExists(name string) bool
|
OtherModuleExists(name string) bool
|
||||||
Rename(name string)
|
Rename(name string)
|
||||||
Module() blueprint.Module
|
Module() Module
|
||||||
|
|
||||||
OtherModuleName(m blueprint.Module) string
|
OtherModuleName(m blueprint.Module) string
|
||||||
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
|
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
|
||||||
|
@ -192,6 +193,11 @@ func depsMutator(ctx BottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *androidTopDownMutatorContext) Module() Module {
|
||||||
|
module, _ := a.TopDownMutatorContext.Module().(Module)
|
||||||
|
return module
|
||||||
|
}
|
||||||
|
|
||||||
func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) {
|
func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) {
|
||||||
a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
|
a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
|
||||||
if aModule, _ := module.(Module); aModule != nil {
|
if aModule, _ := module.(Module); aModule != nil {
|
||||||
|
@ -251,3 +257,31 @@ func (a *androidTopDownMutatorContext) WalkDeps(visit func(Module, Module) bool)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *androidTopDownMutatorContext) AppendProperties(props ...interface{}) {
|
||||||
|
for _, p := range props {
|
||||||
|
err := proptools.AppendMatchingProperties(a.Module().base().customizableProperties,
|
||||||
|
p, nil)
|
||||||
|
if err != nil {
|
||||||
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
||||||
|
a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *androidTopDownMutatorContext) PrependProperties(props ...interface{}) {
|
||||||
|
for _, p := range props {
|
||||||
|
err := proptools.PrependMatchingProperties(a.Module().base().customizableProperties,
|
||||||
|
p, nil)
|
||||||
|
if err != nil {
|
||||||
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
||||||
|
a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue