Convert Visit*Deps from blueprint.Module to android.Module

Also adds checks that the dependencies are android.Modules and
are not disabled.

Test: m checkbuild
Change-Id: I05e945f38915d49cd3c0ab72a86576949bc7eff2
This commit is contained in:
Colin Cross
2017-10-23 17:59:01 -07:00
parent b671544973
commit d11fcda940
15 changed files with 166 additions and 67 deletions

View File

@@ -131,7 +131,7 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) {
func defaultsMutator(ctx TopDownMutatorContext) { func defaultsMutator(ctx TopDownMutatorContext) {
if defaultable, ok := ctx.Module().(Defaultable); ok && len(defaultable.defaults().Defaults) > 0 { if defaultable, ok := ctx.Module().(Defaultable); ok && len(defaultable.defaults().Defaults) > 0 {
var defaultsList []Defaults var defaultsList []Defaults
ctx.WalkDeps(func(module, parent blueprint.Module) bool { ctx.WalkDeps(func(module, parent Module) bool {
if ctx.OtherModuleDependencyTag(module) == DefaultsDepTag { if ctx.OtherModuleDependencyTag(module) == DefaultsDepTag {
if defaults, ok := module.(Defaults); ok { if defaults, ok := module.(Defaults); ok {
defaultsList = append(defaultsList, defaults) defaultsList = append(defaultsList, defaults)

View File

@@ -108,11 +108,11 @@ type ModuleContext interface {
ModuleSubDir() string ModuleSubDir() string
VisitDirectDeps(visit func(blueprint.Module)) VisitDirectDeps(visit func(Module))
VisitDirectDepsIf(pred func(blueprint.Module) bool, visit func(blueprint.Module)) VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
VisitDepsDepthFirst(visit func(blueprint.Module)) VisitDepsDepthFirst(visit func(Module))
VisitDepsDepthFirstIf(pred func(blueprint.Module) bool, visit func(blueprint.Module)) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
WalkDeps(visit func(blueprint.Module, blueprint.Module) bool) WalkDeps(visit func(Module, Module) bool)
Variable(pctx blueprint.PackageContext, name, value string) Variable(pctx blueprint.PackageContext, name, value string)
Rule(pctx blueprint.PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule Rule(pctx blueprint.PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
@@ -663,9 +663,89 @@ func (a *androidModuleContext) GetMissingDependencies() []string {
func (a *androidModuleContext) AddMissingDependencies(deps []string) { func (a *androidModuleContext) AddMissingDependencies(deps []string) {
if deps != nil { if deps != nil {
a.missingDeps = append(a.missingDeps, deps...) a.missingDeps = append(a.missingDeps, deps...)
a.missingDeps = FirstUniqueStrings(a.missingDeps)
} }
} }
func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
aModule, _ := module.(Module)
if aModule == nil {
a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
return nil
}
if !aModule.Enabled() {
if a.AConfig().AllowMissingDependencies() {
a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
} else {
a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
}
return nil
}
return aModule
}
func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule := a.validateAndroidModule(module); aModule != nil {
visit(aModule)
}
})
}
func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
a.ModuleContext.VisitDirectDepsIf(
// pred
func(module blueprint.Module) bool {
if aModule := a.validateAndroidModule(module); aModule != nil {
return pred(aModule)
} else {
return false
}
},
// visit
func(module blueprint.Module) {
visit(module.(Module))
})
}
func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
if aModule := a.validateAndroidModule(module); aModule != nil {
visit(aModule)
}
})
}
func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
a.ModuleContext.VisitDepsDepthFirstIf(
// pred
func(module blueprint.Module) bool {
if aModule := a.validateAndroidModule(module); aModule != nil {
return pred(aModule)
} else {
return false
}
},
// visit
func(module blueprint.Module) {
visit(module.(Module))
})
}
func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
childAndroidModule := a.validateAndroidModule(child)
parentAndroidModule := a.validateAndroidModule(parent)
if childAndroidModule != nil && parentAndroidModule != nil {
return visit(childAndroidModule, parentAndroidModule)
} else {
return false
}
})
}
func (a *androidBaseContextImpl) Target() Target { func (a *androidBaseContextImpl) Target() Target {
return a.target return a.target
} }

View File

@@ -123,11 +123,11 @@ type TopDownMutatorContext interface {
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
VisitDirectDeps(visit func(blueprint.Module)) VisitDirectDeps(visit func(Module))
VisitDirectDepsIf(pred func(blueprint.Module) bool, visit func(blueprint.Module)) VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
VisitDepsDepthFirst(visit func(blueprint.Module)) VisitDepsDepthFirst(visit func(Module))
VisitDepsDepthFirstIf(pred func(blueprint.Module) bool, visit func(blueprint.Module)) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
WalkDeps(visit func(blueprint.Module, blueprint.Module) bool) WalkDeps(visit func(Module, Module) bool)
} }
type androidTopDownMutatorContext struct { type androidTopDownMutatorContext struct {
@@ -191,3 +191,63 @@ func depsMutator(ctx BottomUpMutatorContext) {
m.DepsMutator(ctx) m.DepsMutator(ctx)
} }
} }
func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) {
a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
visit(aModule)
}
})
}
func (a *androidTopDownMutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
a.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 (a *androidTopDownMutatorContext) VisitDepsDepthFirst(visit func(Module)) {
a.TopDownMutatorContext.VisitDepsDepthFirst(func(module blueprint.Module) {
if aModule, _ := module.(Module); aModule != nil {
visit(aModule)
}
})
}
func (a *androidTopDownMutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
a.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 (a *androidTopDownMutatorContext) WalkDeps(visit func(Module, Module) bool) {
a.TopDownMutatorContext.WalkDeps(func(child, parent blueprint.Module) bool {
childAndroidModule, _ := child.(Module)
parentAndroidModule, _ := parent.(Module)
if childAndroidModule != nil && parentAndroidModule != nil {
return visit(childAndroidModule, parentAndroidModule)
} else {
return false
}
})
}

View File

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

View File

@@ -1037,16 +1037,10 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
directStaticDeps := []*Module{} directStaticDeps := []*Module{}
ctx.VisitDirectDeps(func(dep blueprint.Module) { ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep) depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep) depTag := ctx.OtherModuleDependencyTag(dep)
aDep, _ := dep.(android.Module)
if aDep == nil {
ctx.ModuleErrorf("module %q not an android module", depName)
return
}
ccDep, _ := dep.(*Module) ccDep, _ := dep.(*Module)
if ccDep == nil { if ccDep == nil {
// handling for a few module types that aren't cc Module but that are also supported // handling for a few module types that aren't cc Module but that are also supported
@@ -1096,20 +1090,11 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return return
} }
// some validation if dep.Target().Os != ctx.Os() {
if !aDep.Enabled() {
if ctx.AConfig().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{depName})
} else {
ctx.ModuleErrorf("depends on disabled module %q", depName)
}
return
}
if aDep.Target().Os != ctx.Os() {
ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
return return
} }
if aDep.Target().Arch.ArchType != ctx.Arch().ArchType { if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
return return
} }

View File

@@ -16,8 +16,6 @@ package cc
import ( import (
"android/soong/android" "android/soong/android"
"github.com/google/blueprint"
) )
type CoverageProperties struct { type CoverageProperties struct {
@@ -61,7 +59,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
// For static libraries, the only thing that changes our object files // For static libraries, the only thing that changes our object files
// are included whole static libraries, so check to see if any of // are included whole static libraries, so check to see if any of
// those have coverage enabled. // those have coverage enabled.
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.VisitDirectDeps(func(m android.Module) {
if ctx.OtherModuleDependencyTag(m) != wholeStaticDepTag { if ctx.OtherModuleDependencyTag(m) != wholeStaticDepTag {
return return
} }
@@ -75,7 +73,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
} else { } else {
// For executables and shared libraries, we need to check all of // For executables and shared libraries, we need to check all of
// our static dependencies. // our static dependencies.
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.VisitDirectDeps(func(m android.Module) {
cc, ok := m.(*Module) cc, ok := m.(*Module)
if !ok || cc.coverage == nil { if !ok || cc.coverage == nil {
return return

View File

@@ -15,8 +15,6 @@
package cc package cc
import ( import (
"github.com/google/blueprint"
"android/soong/android" "android/soong/android"
) )
@@ -104,7 +102,7 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) {
mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive") mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive")
} }
mctx.VisitDepsDepthFirst(func(m blueprint.Module) { mctx.VisitDepsDepthFirst(func(m android.Module) {
tag := mctx.OtherModuleDependencyTag(m) tag := mctx.OtherModuleDependencyTag(m)
switch tag { switch tag {
case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag, objDepTag, reuseObjTag: case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag, objDepTag, reuseObjTag:

View File

@@ -17,8 +17,6 @@ package cc
import ( import (
"strings" "strings"
"github.com/google/blueprint"
"android/soong/android" "android/soong/android"
"android/soong/cc/config" "android/soong/cc/config"
) )
@@ -81,7 +79,7 @@ func sabiDepsMutator(mctx android.TopDownMutatorContext) {
if c, ok := mctx.Module().(*Module); ok && if c, ok := mctx.Module().(*Module); ok &&
((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) || ((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) ||
(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) { (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
mctx.VisitDirectDeps(func(m blueprint.Module) { mctx.VisitDirectDeps(func(m android.Module) {
tag := mctx.OtherModuleDependencyTag(m) tag := mctx.OtherModuleDependencyTag(m)
switch tag { switch tag {
case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:

View File

@@ -19,8 +19,6 @@ import (
"io" "io"
"strings" "strings"
"github.com/google/blueprint"
"android/soong/android" "android/soong/android"
"android/soong/cc/config" "android/soong/cc/config"
) )
@@ -493,7 +491,7 @@ func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) {
func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) { func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) {
return func(mctx android.TopDownMutatorContext) { return func(mctx android.TopDownMutatorContext) {
if c, ok := mctx.Module().(*Module); ok && c.sanitize.Sanitizer(t) { if c, ok := mctx.Module().(*Module); ok && c.sanitize.Sanitizer(t) {
mctx.VisitDepsDepthFirst(func(module blueprint.Module) { mctx.VisitDepsDepthFirst(func(module android.Module) {
if d, ok := mctx.Module().(*Module); ok && c.sanitize != nil && if d, ok := mctx.Module().(*Module); ok && c.sanitize != nil &&
!c.sanitize.Properties.Sanitize.Never { !c.sanitize.Properties.Sanitize.Never {
d.sanitize.Properties.SanitizeDep = true d.sanitize.Properties.SanitizeDep = true

View File

@@ -157,7 +157,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
tools := map[string]android.Path{} tools := map[string]android.Path{}
if len(g.properties.Tools) > 0 { if len(g.properties.Tools) > 0 {
ctx.VisitDirectDeps(func(module blueprint.Module) { ctx.VisitDirectDeps(func(module android.Module) {
switch ctx.OtherModuleDependencyTag(module) { switch ctx.OtherModuleDependencyTag(module) {
case android.SourceDepTag: case android.SourceDepTag:
// Nothing to do // Nothing to do

View File

@@ -20,7 +20,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
@@ -231,7 +230,7 @@ func (a *AndroidApp) aaptFlags(ctx android.ModuleContext) ([]string, android.Pat
aaptFlags = append(aaptFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A ")) aaptFlags = append(aaptFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A "))
aaptFlags = append(aaptFlags, android.JoinWithPrefix(resourceDirs.Strings(), "-S ")) aaptFlags = append(aaptFlags, android.JoinWithPrefix(resourceDirs.Strings(), "-S "))
ctx.VisitDirectDeps(func(module blueprint.Module) { ctx.VisitDirectDeps(func(module android.Module) {
var depFiles android.Paths var depFiles android.Paths
if javaDep, ok := module.(Dependency); ok { if javaDep, ok := module.(Dependency); ok {
if ctx.OtherModuleName(module) == "framework-res" { if ctx.OtherModuleName(module) == "framework-res" {

View File

@@ -406,25 +406,10 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
} }
ctx.VisitDirectDeps(func(module blueprint.Module) { ctx.VisitDirectDeps(func(module android.Module) {
otherName := ctx.OtherModuleName(module) otherName := ctx.OtherModuleName(module)
tag := ctx.OtherModuleDependencyTag(module) tag := ctx.OtherModuleDependencyTag(module)
aDep, _ := module.(android.Module)
if aDep == nil {
ctx.ModuleErrorf("module %q not an android module", ctx.OtherModuleName(aDep))
return
}
if !aDep.Enabled() {
if ctx.AConfig().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{ctx.OtherModuleName(aDep)})
} else {
ctx.ModuleErrorf("depends on disabled module %q", ctx.OtherModuleName(aDep))
}
return
}
dep, _ := module.(Dependency) dep, _ := module.(Dependency)
if dep == nil { if dep == nil {
switch tag { switch tag {

View File

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

View File

@@ -21,8 +21,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/google/blueprint"
"android/soong/android" "android/soong/android"
) )
@@ -135,7 +133,7 @@ func (binary *binaryDecorator) bootstrap(ctx android.ModuleContext, actual_versi
var launcher_path android.Path var launcher_path android.Path
if embedded_launcher { if embedded_launcher {
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.VisitDirectDeps(func(m android.Module) {
if ctx.OtherModuleDependencyTag(m) != launcherTag { if ctx.OtherModuleDependencyTag(m) != launcherTag {
return return
} }

View File

@@ -508,7 +508,7 @@ func (p *Module) uniqWholeRunfilesTree(ctx android.ModuleContext) {
} }
// visit all its dependencies in depth first. // visit all its dependencies in depth first.
ctx.VisitDepsDepthFirst(func(module blueprint.Module) { ctx.VisitDepsDepthFirst(func(module android.Module) {
if ctx.OtherModuleDependencyTag(module) != pythonLibTag { if ctx.OtherModuleDependencyTag(module) != pythonLibTag {
return return
} }