Merge remote-tracking branch 'aosp/upstream' am: 726d2e6085

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1354383

Change-Id: Ic720c2289434125580ff1e832a32ddf1438f1f30
This commit is contained in:
Colin Cross 2020-07-08 18:22:28 +00:00 committed by Automerger Merge Worker
commit 8ea9686962
2 changed files with 25 additions and 4 deletions

View file

@ -2659,6 +2659,7 @@ func (c *Context) walkDeps(topModule *moduleInfo, allowDuplicates bool,
type replace struct {
from, to *moduleInfo
predicate ReplaceDependencyPredicate
}
type rename struct {
@ -2704,18 +2705,25 @@ func (c *Context) handleRenames(renames []rename) []error {
func (c *Context) handleReplacements(replacements []replace) []error {
var errs []error
changedDeps := false
for _, replace := range replacements {
for _, m := range replace.from.reverseDeps {
for i, d := range m.directDeps {
if d.module == replace.from {
// If the replacement has a predicate then check it.
if replace.predicate == nil || replace.predicate(m.logicModule, d.tag, d.module.logicModule) {
m.directDeps[i].module = replace.to
changedDeps = true
}
}
}
}
}
if changedDeps {
atomic.AddUint32(&c.depsModified, 1)
}
return errs
}

View file

@ -843,6 +843,13 @@ type BottomUpMutatorContext interface {
// after the mutator pass is finished.
ReplaceDependencies(string)
// ReplaceDependencies replaces all dependencies on the identical variant of the module with the
// specified name with the current variant of this module as long as the supplied predicate returns
// true.
//
// Replacements don't take effect until after the mutator pass is finished.
ReplaceDependenciesIf(string, ReplaceDependencyPredicate)
// AliasVariation takes a variationName that was passed to CreateVariations for this module, and creates an
// alias from the current variant to the new variant. The alias will be valid until the next time a mutator
// calls CreateVariations or CreateLocalVariations on this module without also calling AliasVariation. The
@ -1006,6 +1013,12 @@ func (mctx *mutatorContext) AddInterVariantDependency(tag DependencyTag, from, t
}
func (mctx *mutatorContext) ReplaceDependencies(name string) {
mctx.ReplaceDependenciesIf(name, nil)
}
type ReplaceDependencyPredicate func(from Module, tag DependencyTag, to Module) bool
func (mctx *mutatorContext) ReplaceDependenciesIf(name string, predicate ReplaceDependencyPredicate) {
target := mctx.context.moduleMatchingVariant(mctx.module, name)
if target == nil {
@ -1013,7 +1026,7 @@ func (mctx *mutatorContext) ReplaceDependencies(name string) {
mctx.module.variantName, name))
}
mctx.replace = append(mctx.replace, replace{target, mctx.module})
mctx.replace = append(mctx.replace, replace{target, mctx.module, predicate})
}
func (mctx *mutatorContext) Rename(name string) {