Ignore dependency variations for TransitionMutators that didn't apply

When adding a dependency on a module that has already had variants
created by a TransitionMutator, ignore any variation added by the
TransitionMutator to the current module if the TransitionMutator
didn't apply to the target module.  This requires passing in the
list of variations requested by the AddVariationDependencies call
so that explicitly requested variations are not ignored.

This fixes TestAndroidTest_FixTestConfig when the override mutator
is converted to a TransitionMutator, as it can't add a dependency from
the "foo_test" module with an empty override variation to the
"foo" module  that has no override variation.

Bug: 319288033
Test: TestAndroidTest_FixTestConfig
Flag: NONE
Change-Id: If0fca7adc28cd702f953885aef440a0805ac017c
This commit is contained in:
Colin Cross 2024-04-30 12:08:20 -07:00
parent 9f260255f2
commit de024f6167

View file

@ -1876,8 +1876,16 @@ func (c *Context) findReverseDependency(module *moduleInfo, config any, destName
// and applies the IncomingTransition method of each completed TransitionMutator to modify the requested variation.
// It finds a variant that existed before the TransitionMutator ran that is a subset of the requested variant to
// use as the module context for IncomingTransition.
func (c *Context) applyIncomingTransitions(config any, group *moduleGroup, variant variationMap) {
func (c *Context) applyIncomingTransitions(config any, group *moduleGroup, variant variationMap, requestedVariations []Variation) {
for _, transitionMutator := range c.transitionMutators {
if len(transitionMutator.inputVariants[group]) == 0 {
// The transition mutator didn't apply anything to the target module, remove the variation unless it
// was explicitly requested when adding the dependency.
if !slices.ContainsFunc(requestedVariations, func(v Variation) bool { return v.Mutator == transitionMutator.name }) {
delete(variant, transitionMutator.name)
}
continue
}
for _, inputVariant := range transitionMutator.inputVariants[group] {
if inputVariant.variant.variations.subsetOf(variant) {
sourceVariation := variant[transitionMutator.name]
@ -1893,11 +1901,10 @@ func (c *Context) applyIncomingTransitions(config any, group *moduleGroup, varia
}
}
}
}
func (c *Context) findVariant(module *moduleInfo, config any,
possibleDeps *moduleGroup, variations []Variation, far bool, reverse bool) (*moduleInfo, variationMap) {
possibleDeps *moduleGroup, requestedVariations []Variation, far bool, reverse bool) (*moduleInfo, variationMap) {
// We can't just append variant.Variant to module.dependencyVariant.variantName and
// compare the strings because the result won't be in mutator registration order.
@ -1913,14 +1920,14 @@ func (c *Context) findVariant(module *moduleInfo, config any,
newVariant = module.variant.variations.clone()
}
}
for _, v := range variations {
for _, v := range requestedVariations {
if newVariant == nil {
newVariant = make(variationMap)
}
newVariant[v.Mutator] = v.Variation
}
c.applyIncomingTransitions(config, possibleDeps, newVariant)
c.applyIncomingTransitions(config, possibleDeps, newVariant, requestedVariations)
check := func(variant variationMap) bool {
if far {