Merge "Revert "Consolidate *MutatorContext and ModuleContext into BaseModuleContext""

am: 90ef4b9c12

Change-Id: Icc67a56bbb690b626ec1685cb5bca1e1d6e166e2
This commit is contained in:
Colin Cross 2019-06-10 11:13:00 -07:00 committed by android-build-merger
commit 437679ddd1
3 changed files with 217 additions and 185 deletions

View file

@ -57,40 +57,14 @@ type BuildParams struct {
type ModuleBuildParams BuildParams type ModuleBuildParams BuildParams
// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns // BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module // a Config instead of an interface{}, plus some extra methods that return Android-specific information
// instead of a blueprint.Module, plus some extra methods that return Android-specific information
// about the current module. // about the current module.
type BaseModuleContext interface { type BaseModuleContext interface {
Module() Module
ModuleName() string ModuleName() string
ModuleDir() string ModuleDir() string
ModuleType() string ModuleType() string
Config() Config Config() Config
OtherModuleName(m blueprint.Module) string
OtherModuleDir(m blueprint.Module) string
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
OtherModuleExists(name string) bool
GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
VisitDirectDepsBlueprint(visit func(blueprint.Module))
VisitDirectDeps(visit func(Module))
VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
VisitDepsDepthFirst(visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
WalkDeps(visit func(Module, Module) bool)
WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
// GetWalkPath is supposed to be called in visit function passed in WalkDeps()
// and returns a top-down dependency path from a start module to current child module.
GetWalkPath() []Module
ContainsProperty(name string) bool ContainsProperty(name string) bool
Errorf(pos scanner.Position, fmt string, args ...interface{}) Errorf(pos scanner.Position, fmt string, args ...interface{})
ModuleErrorf(fmt string, args ...interface{}) ModuleErrorf(fmt string, args ...interface{})
@ -103,9 +77,6 @@ type BaseModuleContext interface {
// file that does not match the pattern is added to a searched directory. // file that does not match the pattern is added to a searched directory.
GlobWithDeps(pattern string, excludes []string) ([]string, error) GlobWithDeps(pattern string, excludes []string) ([]string, error)
Glob(globPattern string, excludes []string) Paths
GlobFiles(globPattern string, excludes []string) Paths
Fs() pathtools.FileSystem Fs() pathtools.FileSystem
AddNinjaFileDeps(deps ...string) AddNinjaFileDeps(deps ...string)
@ -144,6 +115,8 @@ type ModuleContext interface {
ExpandSources(srcFiles, excludes []string) Paths ExpandSources(srcFiles, excludes []string) Paths
ExpandSource(srcFile, prop string) Path ExpandSource(srcFile, prop string) Path
ExpandOptionalSource(srcFile *string, prop string) OptionalPath ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Glob(globPattern string, excludes []string) Paths
GlobFiles(globPattern string, excludes []string) Paths
InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
@ -161,8 +134,30 @@ type ModuleContext interface {
HostRequiredModuleNames() []string HostRequiredModuleNames() []string
TargetRequiredModuleNames() []string TargetRequiredModuleNames() []string
// android.ModuleContext methods
// These are duplicated instead of embedded so that can eventually be wrapped to take an
// android.Module instead of a blueprint.Module
OtherModuleName(m blueprint.Module) string
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
ModuleSubDir() string ModuleSubDir() string
VisitDirectDepsBlueprint(visit func(blueprint.Module))
VisitDirectDeps(visit func(Module))
VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
VisitDepsDepthFirst(visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
WalkDeps(visit func(Module, Module) bool)
WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Variable(pctx PackageContext, name, value string) Variable(pctx PackageContext, name, value string)
Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
// Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
@ -843,7 +838,7 @@ func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) b
func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) { func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
ctx := &moduleContext{ ctx := &moduleContext{
module: m.module, module: m.module,
bp: blueprintCtx, ModuleContext: blueprintCtx,
baseModuleContext: m.baseModuleContextFactory(blueprintCtx), baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
installDeps: m.computeInstallDeps(blueprintCtx), installDeps: m.computeInstallDeps(blueprintCtx),
installFiles: m.installFiles, installFiles: m.installFiles,
@ -892,16 +887,6 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
} }
if m.Enabled() { if m.Enabled() {
ctx.VisitDirectDeps(func(dep Module) {
if !dep.Enabled() {
if ctx.Config().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{ctx.OtherModuleName(dep)})
} else {
ctx.ModuleErrorf("depends on disabled module %q", ctx.OtherModuleName(dep))
}
}
})
m.module.GenerateAndroidBuildActions(ctx) m.module.GenerateAndroidBuildActions(ctx)
if ctx.Failed() { if ctx.Failed() {
return return
@ -939,12 +924,10 @@ type baseModuleContext struct {
debug bool debug bool
kind moduleKind kind moduleKind
config Config config Config
walkPath []Module
} }
type moduleContext struct { type moduleContext struct {
bp blueprint.ModuleContext blueprint.ModuleContext
baseModuleContext baseModuleContext
installDeps Paths installDeps Paths
installFiles Paths installFiles Paths
@ -959,7 +942,7 @@ type moduleContext struct {
} }
func (m *moduleContext) ninjaError(desc string, outputs []string, err error) { func (m *moduleContext) ninjaError(desc string, outputs []string, err error) {
m.bp.Build(pctx.PackageContext, blueprint.BuildParams{ m.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Rule: ErrorRule, Rule: ErrorRule,
Description: desc, Description: desc,
Outputs: outputs, Outputs: outputs,
@ -971,6 +954,10 @@ func (m *moduleContext) ninjaError(desc string, outputs []string, err error) {
return return
} }
func (m *moduleContext) Config() Config {
return m.ModuleContext.Config().(Config)
}
func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) { func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
m.Build(pctx, BuildParams(params)) m.Build(pctx, BuildParams(params))
} }
@ -1020,13 +1007,13 @@ func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
m.variables[name] = value m.variables[name] = value
} }
m.bp.Variable(pctx.PackageContext, name, value) m.ModuleContext.Variable(pctx.PackageContext, name, value)
} }
func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams, func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule { argNames ...string) blueprint.Rule {
rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...) rule := m.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
if m.config.captureBuild { if m.config.captureBuild {
m.ruleParams[rule] = params m.ruleParams[rule] = params
@ -1053,20 +1040,7 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
return return
} }
m.bp.Build(pctx.PackageContext, bparams) m.ModuleContext.Build(pctx.PackageContext, bparams)
}
func (m *moduleContext) Module() Module {
return m.baseModuleContext.Module()
}
func (b *baseModuleContext) Module() Module {
module, _ := b.BaseModuleContext.Module().(Module)
return module
}
func (b *baseModuleContext) Config() Config {
return b.BaseModuleContext.Config().(Config)
} }
func (m *moduleContext) GetMissingDependencies() []string { func (m *moduleContext) GetMissingDependencies() []string {
@ -1080,20 +1054,34 @@ func (m *moduleContext) AddMissingDependencies(deps []string) {
} }
} }
func (b *baseModuleContext) validateAndroidModule(module blueprint.Module) Module { func (m *moduleContext) validateAndroidModule(module blueprint.Module) Module {
aModule, _ := module.(Module) aModule, _ := module.(Module)
if aModule == nil {
m.ModuleErrorf("module %q not an android module", m.OtherModuleName(aModule))
return nil
}
if !aModule.Enabled() {
if m.Config().AllowMissingDependencies() {
m.AddMissingDependencies([]string{m.OtherModuleName(aModule)})
} else {
m.ModuleErrorf("depends on disabled module %q", m.OtherModuleName(aModule))
}
return nil
}
return aModule return aModule
} }
func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) { func (m *moduleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
type dep struct { type dep struct {
mod blueprint.Module mod blueprint.Module
tag blueprint.DependencyTag tag blueprint.DependencyTag
} }
var deps []dep var deps []dep
b.VisitDirectDepsBlueprint(func(module blueprint.Module) { m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name { if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule) returnedTag := m.ModuleContext.OtherModuleDependencyTag(aModule)
if tag == nil || returnedTag == tag { if tag == nil || returnedTag == tag {
deps = append(deps, dep{aModule, returnedTag}) deps = append(deps, dep{aModule, returnedTag})
} }
@ -1103,17 +1091,17 @@ func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.Depe
return deps[0].mod, deps[0].tag return deps[0].mod, deps[0].tag
} else if len(deps) >= 2 { } else if len(deps) >= 2 {
panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q", panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
name, b.ModuleName())) name, m.ModuleName()))
} else { } else {
return nil, nil return nil, nil
} }
} }
func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module { func (m *moduleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
var deps []Module var deps []Module
b.VisitDirectDepsBlueprint(func(module blueprint.Module) { m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil { if aModule, _ := module.(Module); aModule != nil {
if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag { if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
deps = append(deps, aModule) deps = append(deps, aModule)
} }
} }
@ -1126,37 +1114,37 @@ func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.Dependenc
return module return module
} }
func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) { func (m *moduleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
return b.getDirectDepInternal(name, nil) return m.getDirectDepInternal(name, nil)
} }
func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { func (m *moduleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
b.BaseModuleContext.VisitDirectDeps(visit) m.ModuleContext.VisitDirectDeps(visit)
} }
func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) { func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) { m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule := b.validateAndroidModule(module); aModule != nil { if aModule := m.validateAndroidModule(module); aModule != nil {
visit(aModule) visit(aModule)
} }
}) })
} }
func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) { func (m *moduleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) { m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule := b.validateAndroidModule(module); aModule != nil { if aModule := m.validateAndroidModule(module); aModule != nil {
if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag { if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
visit(aModule) visit(aModule)
} }
} }
}) })
} }
func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
b.BaseModuleContext.VisitDirectDepsIf( m.ModuleContext.VisitDirectDepsIf(
// pred // pred
func(module blueprint.Module) bool { func(module blueprint.Module) bool {
if aModule := b.validateAndroidModule(module); aModule != nil { if aModule := m.validateAndroidModule(module); aModule != nil {
return pred(aModule) return pred(aModule)
} else { } else {
return false return false
@ -1168,19 +1156,19 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func
}) })
} }
func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) { func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) { m.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
if aModule := b.validateAndroidModule(module); aModule != nil { if aModule := m.validateAndroidModule(module); aModule != nil {
visit(aModule) visit(aModule)
} }
}) })
} }
func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
b.BaseModuleContext.VisitDepsDepthFirstIf( m.ModuleContext.VisitDepsDepthFirstIf(
// pred // pred
func(module blueprint.Module) bool { func(module blueprint.Module) bool {
if aModule := b.validateAndroidModule(module); aModule != nil { if aModule := m.validateAndroidModule(module); aModule != nil {
return pred(aModule) return pred(aModule)
} else { } else {
return false return false
@ -1192,21 +1180,15 @@ func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit
}) })
} }
func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) { func (m *moduleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
b.BaseModuleContext.WalkDeps(visit) m.ModuleContext.WalkDeps(visit)
} }
func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) { func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
b.walkPath = []Module{b.Module()} m.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool { childAndroidModule := m.validateAndroidModule(child)
childAndroidModule, _ := child.(Module) parentAndroidModule := m.validateAndroidModule(parent)
parentAndroidModule, _ := parent.(Module)
if childAndroidModule != nil && parentAndroidModule != nil { if childAndroidModule != nil && parentAndroidModule != nil {
// record walkPath before visit
for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
}
b.walkPath = append(b.walkPath, childAndroidModule)
return visit(childAndroidModule, parentAndroidModule) return visit(childAndroidModule, parentAndroidModule)
} else { } else {
return false return false
@ -1214,26 +1196,18 @@ func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
}) })
} }
func (b *baseModuleContext) GetWalkPath() []Module {
return b.walkPath
}
func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) { func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
m.bp.VisitAllModuleVariants(func(module blueprint.Module) { m.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
visit(module.(Module)) visit(module.(Module))
}) })
} }
func (m *moduleContext) PrimaryModule() Module { func (m *moduleContext) PrimaryModule() Module {
return m.bp.PrimaryModule().(Module) return m.ModuleContext.PrimaryModule().(Module)
} }
func (m *moduleContext) FinalModule() Module { func (m *moduleContext) FinalModule() Module {
return m.bp.FinalModule().(Module) return m.ModuleContext.FinalModule().(Module)
}
func (m *moduleContext) ModuleSubDir() string {
return m.bp.ModuleSubDir()
} }
func (b *baseModuleContext) Target() Target { func (b *baseModuleContext) Target() Target {
@ -1611,20 +1585,20 @@ func (m *moduleContext) TargetRequiredModuleNames() []string {
return m.module.base().commonProperties.Target_required return m.module.base().commonProperties.Target_required
} }
func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths { func (m *moduleContext) Glob(globPattern string, excludes []string) Paths {
ret, err := b.GlobWithDeps(globPattern, excludes) ret, err := m.GlobWithDeps(globPattern, excludes)
if err != nil { if err != nil {
b.ModuleErrorf("glob: %s", err.Error()) m.ModuleErrorf("glob: %s", err.Error())
} }
return pathsForModuleSrcFromFullPath(b, ret, true) return pathsForModuleSrcFromFullPath(m, ret, true)
} }
func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths { func (m *moduleContext) GlobFiles(globPattern string, excludes []string) Paths {
ret, err := b.GlobWithDeps(globPattern, excludes) ret, err := m.GlobWithDeps(globPattern, excludes)
if err != nil { if err != nil {
b.ModuleErrorf("glob: %s", err.Error()) m.ModuleErrorf("glob: %s", err.Error())
} }
return pathsForModuleSrcFromFullPath(b, ret, false) return pathsForModuleSrcFromFullPath(m, ret, false)
} }
func init() { func init() {

View file

@ -115,14 +115,35 @@ type TopDownMutator func(TopDownMutatorContext)
type TopDownMutatorContext interface { type TopDownMutatorContext interface {
BaseModuleContext BaseModuleContext
OtherModuleExists(name string) bool
Rename(name string) Rename(name string)
Module() Module
OtherModuleName(m blueprint.Module) string
OtherModuleDir(m blueprint.Module) string
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
CreateModule(blueprint.ModuleFactory, ...interface{}) CreateModule(blueprint.ModuleFactory, ...interface{})
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
VisitDirectDeps(visit func(Module))
VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
VisitDepsDepthFirst(visit func(Module))
VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
WalkDeps(visit func(Module, Module) bool)
// GetWalkPath is supposed to be called in visit function passed in WalkDeps()
// and returns a top-down dependency path from a start module to current child module.
GetWalkPath() []Module
} }
type topDownMutatorContext struct { type topDownMutatorContext struct {
bp blueprint.TopDownMutatorContext blueprint.TopDownMutatorContext
baseModuleContext baseModuleContext
walkPath []Module
} }
type BottomUpMutator func(BottomUpMutatorContext) type BottomUpMutator func(BottomUpMutatorContext)
@ -130,7 +151,9 @@ type BottomUpMutator func(BottomUpMutatorContext)
type BottomUpMutatorContext interface { type BottomUpMutatorContext interface {
BaseModuleContext BaseModuleContext
OtherModuleExists(name string) bool
Rename(name string) Rename(name string)
Module() blueprint.Module
AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string)
AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
@ -144,7 +167,7 @@ type BottomUpMutatorContext interface {
} }
type bottomUpMutatorContext struct { type bottomUpMutatorContext struct {
bp blueprint.BottomUpMutatorContext blueprint.BottomUpMutatorContext
baseModuleContext baseModuleContext
} }
@ -152,8 +175,8 @@ func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) Mutat
f := func(ctx blueprint.BottomUpMutatorContext) { f := func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok { if a, ok := ctx.Module().(Module); ok {
actx := &bottomUpMutatorContext{ actx := &bottomUpMutatorContext{
bp: ctx, BottomUpMutatorContext: ctx,
baseModuleContext: a.base().baseModuleContextFactory(ctx), baseModuleContext: a.base().baseModuleContextFactory(ctx),
} }
m(actx) m(actx)
} }
@ -167,8 +190,8 @@ func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) Mutator
f := func(ctx blueprint.TopDownMutatorContext) { f := func(ctx blueprint.TopDownMutatorContext) {
if a, ok := ctx.Module().(Module); ok { if a, ok := ctx.Module().(Module); ok {
actx := &topDownMutatorContext{ actx := &topDownMutatorContext{
bp: ctx, TopDownMutatorContext: ctx,
baseModuleContext: a.base().baseModuleContextFactory(ctx), baseModuleContext: a.base().baseModuleContextFactory(ctx),
} }
m(actx) m(actx)
} }
@ -193,6 +216,99 @@ func depsMutator(ctx BottomUpMutatorContext) {
} }
} }
func (t *topDownMutatorContext) Config() Config {
return t.config
}
func (b *bottomUpMutatorContext) Config() Config {
return b.config
}
func (t *topDownMutatorContext) Module() Module {
module, _ := t.TopDownMutatorContext.Module().(Module)
return module
}
func (t *topDownMutatorContext) VisitDirectDeps(visit func(Module)) {
t.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
visit(aModule)
}
})
}
func (t *topDownMutatorContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
t.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
if t.TopDownMutatorContext.OtherModuleDependencyTag(aModule) == tag {
visit(aModule)
}
}
})
}
func (t *topDownMutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
t.TopDownMutatorContext.VisitDirectDepsIf(
// pred
func(module blueprint.Module) bool {
if aModule, _ := module.(Module); aModule != nil {
return pred(aModule)
} else {
return false
}
},
// visit
func(module blueprint.Module) {
visit(module.(Module))
})
}
func (t *topDownMutatorContext) VisitDepsDepthFirst(visit func(Module)) {
t.TopDownMutatorContext.VisitDepsDepthFirst(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
visit(aModule)
}
})
}
func (t *topDownMutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
t.TopDownMutatorContext.VisitDepsDepthFirstIf(
// pred
func(module blueprint.Module) bool {
if aModule, _ := module.(Module); aModule != nil {
return pred(aModule)
} else {
return false
}
},
// visit
func(module blueprint.Module) {
visit(module.(Module))
})
}
func (t *topDownMutatorContext) WalkDeps(visit func(Module, Module) bool) {
t.walkPath = []Module{t.Module()}
t.TopDownMutatorContext.WalkDeps(func(child, parent blueprint.Module) bool {
childAndroidModule, _ := child.(Module)
parentAndroidModule, _ := parent.(Module)
if childAndroidModule != nil && parentAndroidModule != nil {
// record walkPath before visit
for t.walkPath[len(t.walkPath)-1] != parentAndroidModule {
t.walkPath = t.walkPath[0 : len(t.walkPath)-1]
}
t.walkPath = append(t.walkPath, childAndroidModule)
return visit(childAndroidModule, parentAndroidModule)
} else {
return false
}
})
}
func (t *topDownMutatorContext) GetWalkPath() []Module {
return t.walkPath
}
func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { func (t *topDownMutatorContext) AppendProperties(props ...interface{}) {
for _, p := range props { for _, p := range props {
err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties, err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties,
@ -220,61 +336,3 @@ func (t *topDownMutatorContext) PrependProperties(props ...interface{}) {
} }
} }
} }
// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
func (t *topDownMutatorContext) Rename(name string) {
t.bp.Rename(name)
}
func (t *topDownMutatorContext) CreateModule(factory blueprint.ModuleFactory, props ...interface{}) {
t.bp.CreateModule(factory, props...)
}
func (b *bottomUpMutatorContext) Rename(name string) {
b.bp.Rename(name)
}
func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) {
b.bp.AddDependency(module, tag, name...)
}
func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
b.bp.AddReverseDependency(module, tag, name)
}
func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []blueprint.Module {
return b.bp.CreateVariations(variations...)
}
func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []blueprint.Module {
return b.bp.CreateLocalVariations(variations...)
}
func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
b.bp.SetDependencyVariation(variation)
}
func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
names ...string) {
b.bp.AddVariationDependencies(variations, tag, names...)
}
func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
tag blueprint.DependencyTag, names ...string) {
b.bp.AddFarVariationDependencies(variations, tag, names...)
}
func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
b.bp.AddInterVariantDependency(tag, from, to)
}
func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
b.bp.ReplaceDependencies(name)
}

View file

@ -367,7 +367,7 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P
// each string. If incDirs is false, strip paths with a trailing '/' from the list. // each string. If incDirs is false, strip paths with a trailing '/' from the list.
// It intended for use in globs that only list files that exist, so it allows '$' in // It intended for use in globs that only list files that exist, so it allows '$' in
// filenames. // filenames.
func pathsForModuleSrcFromFullPath(ctx BaseModuleContext, paths []string, incDirs bool) Paths { func pathsForModuleSrcFromFullPath(ctx ModuleContext, paths []string, incDirs bool) Paths {
prefix := filepath.Join(ctx.Config().srcDir, ctx.ModuleDir()) + "/" prefix := filepath.Join(ctx.Config().srcDir, ctx.ModuleDir()) + "/"
if prefix == "./" { if prefix == "./" {
prefix = "" prefix = ""