Revert "Consolidate *MutatorContext and ModuleContext into BaseModuleContext"
This reverts commit 7e0a2cb590f2f2d117571327f40fa8557363658c.
Reason for revert: broke TARGET_BUILD_APPS builds
Change-Id: I5316a62f77bb38f6195e3df5e31b073dbd1eb682
diff --git a/android/mutator.go b/android/mutator.go
index 081c2b2..cd0d152 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -115,14 +115,35 @@
type TopDownMutatorContext interface {
BaseModuleContext
+ OtherModuleExists(name string) bool
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{})
+
+ 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 {
- bp blueprint.TopDownMutatorContext
+ blueprint.TopDownMutatorContext
baseModuleContext
+ walkPath []Module
}
type BottomUpMutator func(BottomUpMutatorContext)
@@ -130,7 +151,9 @@
type BottomUpMutatorContext interface {
BaseModuleContext
+ OtherModuleExists(name string) bool
Rename(name string)
+ Module() blueprint.Module
AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string)
AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
@@ -144,7 +167,7 @@
}
type bottomUpMutatorContext struct {
- bp blueprint.BottomUpMutatorContext
+ blueprint.BottomUpMutatorContext
baseModuleContext
}
@@ -152,8 +175,8 @@
f := func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
actx := &bottomUpMutatorContext{
- bp: ctx,
- baseModuleContext: a.base().baseModuleContextFactory(ctx),
+ BottomUpMutatorContext: ctx,
+ baseModuleContext: a.base().baseModuleContextFactory(ctx),
}
m(actx)
}
@@ -167,8 +190,8 @@
f := func(ctx blueprint.TopDownMutatorContext) {
if a, ok := ctx.Module().(Module); ok {
actx := &topDownMutatorContext{
- bp: ctx,
- baseModuleContext: a.base().baseModuleContextFactory(ctx),
+ TopDownMutatorContext: ctx,
+ baseModuleContext: a.base().baseModuleContextFactory(ctx),
}
m(actx)
}
@@ -193,6 +216,99 @@
}
}
+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{}) {
for _, p := range props {
err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties,
@@ -220,61 +336,3 @@
}
}
}
-
-// 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)
-}