Add VisitDirectDepsIgnoreBlueprint

This method allows dependencies on non-Android modules, which it ignores
in strict mode, rather than flagging the dependency as an error.

Bug: none
Test: manual
Change-Id: I9575e46638fa8ffc69c8935b1b65aab37ceab3c3
This commit is contained in:
LaMont Jones 2024-01-18 18:27:35 +00:00
parent 4ebab14f2e
commit 34314b7d15
3 changed files with 29 additions and 16 deletions

View file

@ -49,13 +49,7 @@ func CollectDependencyAconfigFiles(ctx ModuleContext, mergedAconfigFiles *map[st
if *mergedAconfigFiles == nil {
*mergedAconfigFiles = make(map[string]Paths)
}
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
// Walk our direct dependencies, ignoring blueprint Modules and disabled Android Modules.
aModule, _ := module.(Module)
if aModule == nil || !aModule.Enabled() {
return
}
ctx.VisitDirectDepsIgnoreBlueprint(func(module Module) {
if dep, _ := OtherModuleProvider(ctx, module, AconfigDeclarationsProviderKey); dep.IntermediateCacheOutputPath != nil {
(*mergedAconfigFiles)[dep.Container] = append((*mergedAconfigFiles)[dep.Container], dep.IntermediateCacheOutputPath)
return

View file

@ -105,7 +105,7 @@ type BaseModuleContext interface {
// dependencies that are not an android.Module.
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
// name, or nil if none exists. If there are multiple dependencies on the same module it returns
// the first DependencyTag.
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
@ -118,6 +118,15 @@ type BaseModuleContext interface {
// function, it may be invalidated by future mutators.
VisitDirectDepsBlueprint(visit func(blueprint.Module))
// VisitDirectDepsIgnoreBlueprint calls visit for each direct dependency. If there are multiple
// direct dependencies on the same module visit will be called multiple times on that module
// and OtherModuleDependencyTag will return a different tag for each. It silently ignores any
// dependencies that are not an android.Module.
//
// The Module passed to the visit function should not be retained outside of the visit
// function, it may be invalidated by future mutators.
VisitDirectDepsIgnoreBlueprint(visit func(Module))
// VisitDirectDeps calls visit for each direct dependency. If there are multiple
// direct dependencies on the same module visit will be called multiple times on that module
// and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the
@ -306,7 +315,7 @@ type AllowDisabledModuleDependency interface {
AllowDisabledModuleDependency(target Module) bool
}
func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool, ignoreBlueprint bool) Module {
aModule, _ := module.(Module)
if !strict {
@ -314,7 +323,9 @@ func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag b
}
if aModule == nil {
b.ModuleErrorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)
if !ignoreBlueprint {
b.ModuleErrorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)
}
return nil
}
@ -411,8 +422,16 @@ func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module
}
func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
b.visitDirectDeps(visit, false)
}
func (b *baseModuleContext) VisitDirectDepsIgnoreBlueprint(visit func(Module)) {
b.visitDirectDeps(visit, true)
}
func (b *baseModuleContext) visitDirectDeps(visit func(Module), ignoreBlueprint bool) {
b.bp.VisitDirectDeps(func(module blueprint.Module) {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, ignoreBlueprint); aModule != nil {
visit(aModule)
}
})
@ -421,7 +440,7 @@ func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
b.bp.VisitDirectDeps(func(module blueprint.Module) {
if b.bp.OtherModuleDependencyTag(module) == tag {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
visit(aModule)
}
}
@ -432,7 +451,7 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func
b.bp.VisitDirectDepsIf(
// pred
func(module blueprint.Module) bool {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
return pred(aModule)
} else {
return false
@ -446,7 +465,7 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func
func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
visit(aModule)
}
})
@ -456,7 +475,7 @@ func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit
b.bp.VisitDepsDepthFirstIf(
// pred
func(module blueprint.Module) bool {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
return pred(aModule)
} else {
return false

View file

@ -1692,7 +1692,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
// ensure all direct android.Module deps are enabled
ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
if m, ok := bm.(Module); ok {
ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps)
ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps, false)
}
})