Merge remote-tracking branch 'aosp/upstream'

* aosp/upstream:
  Don't ignore local variations when creating reverse dep
  Added VisitDirectDeps* methods to SingletonContext.

Test: m
Change-Id: I4832a523588c3095b077b89d2ecb4068b490fed4
This commit is contained in:
Jiyong Park 2019-09-23 10:01:46 +09:00
commit a67e8c98e4
2 changed files with 38 additions and 4 deletions

View file

@ -1410,12 +1410,21 @@ func blueprintDepsMutator(ctx BottomUpMutatorContext) {
// findMatchingVariant searches the moduleGroup for a module with the same variant as module,
// and returns the matching module, or nil if one is not found.
func (c *Context) findMatchingVariant(module *moduleInfo, possible []*moduleInfo) *moduleInfo {
func (c *Context) findMatchingVariant(module *moduleInfo, possible []*moduleInfo, reverse bool) *moduleInfo {
if len(possible) == 1 {
return possible[0]
} else {
var variantToMatch variationMap
if !reverse {
// For forward dependency, ignore local variants by matching against
// dependencyVariant which doesn't have the local variants
variantToMatch = module.dependencyVariant
} else {
// For reverse dependency, use all the variants
variantToMatch = module.variant
}
for _, m := range possible {
if m.variant.equal(module.dependencyVariant) {
if m.variant.equal(variantToMatch) {
return m
}
}
@ -1441,7 +1450,7 @@ func (c *Context) addDependency(module *moduleInfo, tag DependencyTag, depName s
return c.discoveredMissingDependencies(module, depName)
}
if m := c.findMatchingVariant(module, possibleDeps); m != nil {
if m := c.findMatchingVariant(module, possibleDeps, false); m != nil {
module.newDirectDeps = append(module.newDirectDeps, depInfo{m, tag})
atomic.AddUint32(&c.depsModified, 1)
return nil
@ -1479,7 +1488,7 @@ func (c *Context) findReverseDependency(module *moduleInfo, destName string) (*m
}}
}
if m := c.findMatchingVariant(module, possibleDeps); m != nil {
if m := c.findMatchingVariant(module, possibleDeps, true); m != nil {
return m, nil
}

View file

@ -93,6 +93,23 @@ type SingletonContext interface {
// true calls visit.
VisitAllModulesIf(pred func(Module) bool, visit func(Module))
// VisitDirectDeps calls visit for each direct dependency of the Module. 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.
//
// The Module passed to the visit function should not be retained outside of the visit
// function, it may be invalidated by future mutators.
VisitDirectDeps(module Module, visit func(Module))
// VisitDirectDepsIf calls pred for each direct dependency of the Module, and if pred
// returns true calls visit. If there are multiple direct dependencies on the same module
// pred and visit will be called multiple times on that module and OtherModuleDependencyTag
// will return a different tag for each.
//
// The Module passed to the visit function should not be retained outside of the visit
// function, it may be invalidated by future mutators.
VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module))
// VisitDepsDepthFirst calls visit for each transitive dependency, traversing the dependency tree in depth first
// order. visit will only be called once for any given module, even if there are multiple paths through the
// dependency tree to the module or multiple direct dependencies with different tags.
@ -289,6 +306,14 @@ func (s *singletonContext) VisitAllModulesIf(pred func(Module) bool,
s.context.VisitAllModulesIf(pred, visit)
}
func (s *singletonContext) VisitDirectDeps(module Module, visit func(Module)) {
s.context.VisitDirectDeps(module, visit)
}
func (s *singletonContext) VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module)) {
s.context.VisitDirectDepsIf(module, pred, visit)
}
func (s *singletonContext) VisitDepsDepthFirst(module Module,
visit func(Module)) {