Add walkDeps to context and module_ctx.
walkDeps performs a pre-order DFS (unlike visitDepsDepthFirst which is a post-order DFS). The visit function takes in both a parent and child node and returns a bool indicating if the child node should be traversed.
This commit is contained in:
parent
e12c780957
commit
222e2458b1
2 changed files with 31 additions and 0 deletions
21
context.go
21
context.go
|
@ -1825,6 +1825,27 @@ func (c *Context) processLocalBuildActions(out, in *localBuildActions,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) walkDeps(topModule *moduleInfo,
|
||||
visit func(Module, Module) bool) {
|
||||
|
||||
visited := make(map[*moduleInfo]bool)
|
||||
|
||||
var walk func(module *moduleInfo)
|
||||
walk = func(module *moduleInfo) {
|
||||
visited[module] = true
|
||||
|
||||
for _, moduleDep := range module.directDeps {
|
||||
if !visited[moduleDep] {
|
||||
if visit(moduleDep.logicModule, module.logicModule) {
|
||||
walk(moduleDep)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(topModule)
|
||||
}
|
||||
|
||||
func (c *Context) visitDepsDepthFirst(topModule *moduleInfo, visit func(Module)) {
|
||||
visited := make(map[*moduleInfo]bool)
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ type ModuleContext interface {
|
|||
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)
|
||||
|
||||
ModuleSubDir() string
|
||||
|
||||
|
@ -251,6 +252,10 @@ func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool,
|
|||
m.context.visitDepsDepthFirstIf(m.module, pred, visit)
|
||||
}
|
||||
|
||||
func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
|
||||
m.context.walkDeps(m.module, visit)
|
||||
}
|
||||
|
||||
func (m *moduleContext) ModuleSubDir() string {
|
||||
return m.module.variantName
|
||||
}
|
||||
|
@ -382,6 +387,7 @@ type TopDownMutatorContext interface {
|
|||
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)
|
||||
}
|
||||
|
||||
type BottomUpMutatorContext interface {
|
||||
|
@ -501,3 +507,7 @@ func (mctx *mutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool,
|
|||
|
||||
mctx.context.visitDepsDepthFirstIf(mctx.module, pred, visit)
|
||||
}
|
||||
|
||||
func (mctx *mutatorContext) WalkDeps(visit func(Module, Module) bool) {
|
||||
mctx.context.walkDeps(mctx.module, visit)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue