aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2024-04-30 12:07:58 -0700
committerColin Cross <ccross@android.com>2024-05-02 14:39:19 -0700
commit38b56e136f567d58ea6ddab3741b9a2396a18d8a (patch)
tree14ec446aaa9d2ab635eeb99179726c1ffeabd527
parentde024f6167fd02452962606b87667ac9d28487bc (diff)
downloadblueprint-main.tar.gz
Change semantics of ReplaceDependencies[If]HEADmastermain
ReplaceDependencies[If] currently replaces dependencies on a given module with the current module. It expects to find a variant of the given module that has the exact same variations as the current module. That was sometimes handled via aliases, but TransitionMutators don't support aliases, they use IncomingTransition to rewrite the variation instead. In all current usages of ReplaceDependencies[If], the given module is also a direct dependency of the current module. Instead of looking for the exact same variations, look for the variant that is a dependency of the current module. Bug: 319288033 Test: all soong tests pass Flag: NONE Change-Id: I3e33111322040b187f6e951554366ccdcaf1bc11
-rw-r--r--context.go21
-rw-r--r--module_ctx.go21
2 files changed, 26 insertions, 16 deletions
diff --git a/context.go b/context.go
index ec74853..87185ab 100644
--- a/context.go
+++ b/context.go
@@ -3485,20 +3485,29 @@ type rename struct {
name string
}
-func (c *Context) moduleMatchingVariant(module *moduleInfo, name string) *moduleInfo {
- group := c.moduleGroupFromName(name, module.namespace())
+// moduleVariantsThatDependOn takes the name of a module and a dependency and returns the all the variants of the
+// module that depends on the dependency.
+func (c *Context) moduleVariantsThatDependOn(name string, dep *moduleInfo) []*moduleInfo {
+ group := c.moduleGroupFromName(name, dep.namespace())
+ var variants []*moduleInfo
if group == nil {
return nil
}
- for _, m := range group.modules {
- if module.variant.name == m.moduleOrAliasVariant().name {
- return m.moduleOrAliasTarget()
+ for _, module := range group.modules {
+ m := module.module()
+ if m == nil {
+ continue
+ }
+ for _, moduleDep := range m.directDeps {
+ if moduleDep.module == dep {
+ variants = append(variants, m)
+ }
}
}
- return nil
+ return variants
}
func (c *Context) handleRenames(renames []rename) []error {
diff --git a/module_ctx.go b/module_ctx.go
index 530eb5e..920b74e 100644
--- a/module_ctx.go
+++ b/module_ctx.go
@@ -924,15 +924,14 @@ type BottomUpMutatorContext interface {
// WalkDeps, etc.
AddInterVariantDependency(tag DependencyTag, from, to Module)
- // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
- // specified name with the current variant of this module. Replacements don't take effect until
- // after the mutator pass is finished.
+ // ReplaceDependencies finds all the variants of the module with the specified name, then
+ // replaces all dependencies onto those variants with the current variant of this module.
+ // Replacements don't take effect until after the mutator pass is finished.
ReplaceDependencies(string)
- // ReplaceDependenciesIf 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.
- //
+ // ReplaceDependenciesIf finds all the variants of the module with the specified name, then
+ // replaces all dependencies onto those variants 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)
@@ -1194,9 +1193,9 @@ func (mctx *mutatorContext) ReplaceDependencies(name string) {
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)
+ targets := mctx.context.moduleVariantsThatDependOn(name, mctx.module)
- if target == nil {
+ if len(targets) == 0 {
panic(fmt.Errorf("ReplaceDependencies could not find identical variant {%s} for module %s\n"+
"available variants:\n %s",
mctx.context.prettyPrintVariant(mctx.module.variant.variations),
@@ -1204,7 +1203,9 @@ func (mctx *mutatorContext) ReplaceDependenciesIf(name string, predicate Replace
mctx.context.prettyPrintGroupVariants(mctx.context.moduleGroupFromName(name, mctx.module.namespace()))))
}
- mctx.replace = append(mctx.replace, replace{target, mctx.module, predicate})
+ for _, target := range targets {
+ mctx.replace = append(mctx.replace, replace{target, mctx.module, predicate})
+ }
}
func (mctx *mutatorContext) Rename(name string) {