Add VisitDirectDepsWithTag

Add a method on ModuleContext and TopDownMutatorContext to visit
direct dependencies that have a given dependency tag.

Test: m checkbuild
Change-Id: Ib875563091dcae6b7282b3e3427d0eb07d8c8af5
This commit is contained in:
Colin Cross 2017-12-30 17:54:27 -08:00
parent b4330e222b
commit ee6143cde2
6 changed files with 32 additions and 21 deletions

View File

@ -139,6 +139,7 @@ type ModuleContext interface {
VisitDirectDepsBlueprint(visit func(blueprint.Module))
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))
@ -831,6 +832,16 @@ func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
})
}
func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule := a.validateAndroidModule(module); aModule != nil {
if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
visit(aModule)
}
}
})
}
func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
a.ModuleContext.VisitDirectDepsIf(
// pred

View File

@ -127,6 +127,7 @@ type TopDownMutatorContext interface {
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))
@ -230,6 +231,16 @@ func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) {
})
}
func (a *androidTopDownMutatorContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
if a.TopDownMutatorContext.OtherModuleDependencyTag(aModule) == tag {
visit(aModule)
}
}
})
}
func (a *androidTopDownMutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
a.TopDownMutatorContext.VisitDirectDepsIf(
// pred

View File

@ -109,14 +109,12 @@ func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil)
}
} else if s, ok := ctx.Module().(Module); ok {
ctx.VisitDirectDeps(func(m Module) {
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
ctx.VisitDirectDepsWithTag(prebuiltDepTag, func(m Module) {
p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx, s) {
p.properties.UsePrebuilt = true
s.SkipInstall()
}
}
})
}
}

View File

@ -59,11 +59,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
// For static libraries, the only thing that changes our object files
// are included whole static libraries, so check to see if any of
// those have coverage enabled.
ctx.VisitDirectDeps(func(m android.Module) {
if ctx.OtherModuleDependencyTag(m) != wholeStaticDepTag {
return
}
ctx.VisitDirectDepsWithTag(wholeStaticDepTag, func(m android.Module) {
if cc, ok := m.(*Module); ok && cc.coverage != nil {
if cc.coverage.linkCoverage {
cov.linkCoverage = true

View File

@ -112,11 +112,9 @@ type SystemModulesProperties struct {
func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var jars android.Paths
ctx.VisitDirectDeps(func(module android.Module) {
if ctx.OtherModuleDependencyTag(module) == libTag {
ctx.VisitDirectDepsWithTag(libTag, func(module android.Module) {
dep, _ := module.(Dependency)
jars = append(jars, dep.HeaderJars()...)
}
})
jars = append(jars, android.PathsForModuleSrc(ctx, system.properties.Jars)...)

View File

@ -133,10 +133,7 @@ func (binary *binaryDecorator) bootstrap(ctx android.ModuleContext, actual_versi
var launcher_path android.Path
if embedded_launcher {
ctx.VisitDirectDeps(func(m android.Module) {
if ctx.OtherModuleDependencyTag(m) != launcherTag {
return
}
ctx.VisitDirectDepsWithTag(launcherTag, func(m android.Module) {
if provider, ok := m.(IntermPathProvider); ok {
if launcher_path != nil {
panic(fmt.Errorf("launcher path was found before: %q",