Handle nil variant in applyTransitions

The input variationMap in applyTransitions may be nil, initialize
it if necessary.

Bug: 319288033
Test: TestPostTransitionDeps
Flag: NONE
Change-Id: I091aa5a04732fdf18931b2534c4c479152c2a9e1
This commit is contained in:
Colin Cross 2024-05-09 10:30:20 -07:00
parent 5bc2b73593
commit eb077c3123
2 changed files with 35 additions and 6 deletions

View file

@ -1877,7 +1877,7 @@ func (c *Context) findReverseDependency(module *moduleInfo, config any, destName
// 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) applyTransitions(config any, module *moduleInfo, group *moduleGroup, variant variationMap,
requestedVariations []Variation) {
requestedVariations []Variation) variationMap {
for _, transitionMutator := range c.transitionMutators {
// Apply the outgoing transition if it was not explicitly requested.
explicitlyRequested := slices.ContainsFunc(requestedVariations, func(variation Variation) bool {
@ -1903,6 +1903,9 @@ func (c *Context) applyTransitions(config any, module *moduleInfo, group *module
}
finalVariation := transitionMutator.mutator.IncomingTransition(ctx, outgoingVariation)
if variant == nil {
variant = make(variationMap)
}
variant[transitionMutator.name] = finalVariation
appliedIncomingTransition = true
break
@ -1914,6 +1917,8 @@ func (c *Context) applyTransitions(config any, module *moduleInfo, group *module
delete(variant, transitionMutator.name)
}
}
return variant
}
func (c *Context) findVariant(module *moduleInfo, config any,
@ -1940,7 +1945,7 @@ func (c *Context) findVariant(module *moduleInfo, config any,
newVariant[v.Mutator] = v.Variation
}
c.applyTransitions(config, module, possibleDeps, newVariant, requestedVariations)
newVariant = c.applyTransitions(config, module, possibleDeps, newVariant, requestedVariations)
check := func(variant variationMap) bool {
if far {

View file

@ -86,7 +86,18 @@ const testTransitionBp = `
}
transition_module {
name: "F"
name: "F",
}
transition_module {
name: "G",
outgoing: "h",
%s
}
transition_module {
name: "H",
split: ["h"],
}
`
@ -128,7 +139,7 @@ func checkTransitionMutate(t *testing.T, m *transitionModule, variant string) {
}
func TestTransition(t *testing.T) {
ctx, errs := testTransition(fmt.Sprintf(testTransitionBp, ""))
ctx, errs := testTransition(fmt.Sprintf(testTransitionBp, "", ""))
assertNoErrors(t, errs)
// Module A uses Split to create a and b variants
@ -154,6 +165,8 @@ func TestTransition(t *testing.T) {
D_d := getTransitionModule(ctx, "D", "d")
E_d := getTransitionModule(ctx, "E", "d")
F := getTransitionModule(ctx, "F", "")
G := getTransitionModule(ctx, "G", "")
H_h := getTransitionModule(ctx, "H", "h")
checkTransitionDeps(t, ctx, A_a, "B(a)", "C(a)")
checkTransitionDeps(t, ctx, A_b, "B(b)", "C(b)")
@ -165,6 +178,8 @@ func TestTransition(t *testing.T) {
checkTransitionDeps(t, ctx, D_d, "E(d)")
checkTransitionDeps(t, ctx, E_d)
checkTransitionDeps(t, ctx, F)
checkTransitionDeps(t, ctx, G)
checkTransitionDeps(t, ctx, H_h)
checkTransitionMutate(t, A_a, "a")
checkTransitionMutate(t, A_b, "b")
@ -176,11 +191,14 @@ func TestTransition(t *testing.T) {
checkTransitionMutate(t, D_d, "d")
checkTransitionMutate(t, E_d, "d")
checkTransitionMutate(t, F, "")
checkTransitionMutate(t, G, "")
checkTransitionMutate(t, H_h, "h")
}
func TestPostTransitionDeps(t *testing.T) {
ctx, errs := testTransition(fmt.Sprintf(testTransitionBp,
`post_transition_deps: ["C", "D:late", "E:d", "F"],`))
`post_transition_deps: ["C", "D:late", "E:d", "F"],`,
`post_transition_deps: ["H"],`))
assertNoErrors(t, errs)
// Module A uses Split to create a and b variants
@ -206,6 +224,8 @@ func TestPostTransitionDeps(t *testing.T) {
D_d := getTransitionModule(ctx, "D", "d")
E_d := getTransitionModule(ctx, "E", "d")
F := getTransitionModule(ctx, "F", "")
G := getTransitionModule(ctx, "G", "")
H_h := getTransitionModule(ctx, "H", "h")
checkTransitionDeps(t, ctx, A_a, "B(a)", "C(a)")
checkTransitionDeps(t, ctx, A_b, "B(b)", "C(b)")
@ -222,6 +242,8 @@ func TestPostTransitionDeps(t *testing.T) {
checkTransitionDeps(t, ctx, D_d, "E(d)")
checkTransitionDeps(t, ctx, E_d)
checkTransitionDeps(t, ctx, F)
checkTransitionDeps(t, ctx, G, "H(h)")
checkTransitionDeps(t, ctx, H_h)
checkTransitionMutate(t, A_a, "a")
checkTransitionMutate(t, A_b, "b")
@ -233,12 +255,14 @@ func TestPostTransitionDeps(t *testing.T) {
checkTransitionMutate(t, D_d, "d")
checkTransitionMutate(t, E_d, "d")
checkTransitionMutate(t, F, "")
checkTransitionMutate(t, G, "")
checkTransitionMutate(t, H_h, "h")
}
func TestPostTransitionDepsMissingVariant(t *testing.T) {
// TODO: eventually this will create the missing variant on demand
_, errs := testTransition(fmt.Sprintf(testTransitionBp,
`post_transition_deps: ["E:missing"],`))
`post_transition_deps: ["E:missing"],`, ""))
expectedError := `Android.bp:8:4: dependency "E" of "B" missing variant:
transition:missing
available variants: