Fix AddFarVariationDependencies subset checks
AddFarVariationDependencies claims to take the first variant that matches all the requested variations, but it did nothing of the sort. It took the first variant that either matched or did not contain each of the requested variations. A module with no variations was always matched, and requesting variations that didn't apply to a module still matched (for example, requesting an image variation for a host module that was ignored by the image mutator). Fix AddFarVariationDependencies by making subset actually check for subsets. Test: Test_findVariant Change-Id: I10063fec342db2a1c0685a7db08e4a650d14bd4e
This commit is contained in:
parent
5df74a8e38
commit
5dc6759951
2 changed files with 45 additions and 6 deletions
|
@ -323,10 +323,10 @@ func (vm variationMap) clone() variationMap {
|
|||
}
|
||||
|
||||
// Compare this variationMap to another one. Returns true if the every entry in this map
|
||||
// is either the same in the other map or doesn't exist in the other map.
|
||||
func (vm variationMap) subset(other variationMap) bool {
|
||||
// exists and has the same value in the other map.
|
||||
func (vm variationMap) subsetOf(other variationMap) bool {
|
||||
for k, v1 := range vm {
|
||||
if v2, ok := other[k]; ok && v1 != v2 {
|
||||
if v2, ok := other[k]; !ok || v1 != v2 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -1687,7 +1687,7 @@ func findVariant(module *moduleInfo, possibleDeps *moduleGroup, variations []Var
|
|||
|
||||
check := func(variant variationMap) bool {
|
||||
if far {
|
||||
return variant.subset(newVariant)
|
||||
return newVariant.subsetOf(variant)
|
||||
} else {
|
||||
return variant.equal(newVariant)
|
||||
}
|
||||
|
|
|
@ -738,6 +738,12 @@ func Test_findVariant(t *testing.T) {
|
|||
name: "AddFarVariationDependencies(far)",
|
||||
// A dependency with far variations
|
||||
possibleDeps: makeDependencyGroup(
|
||||
&moduleInfo{
|
||||
variant: variant{
|
||||
name: "",
|
||||
variations: nil,
|
||||
},
|
||||
},
|
||||
&moduleInfo{
|
||||
variant: variant{
|
||||
name: "far",
|
||||
|
@ -789,12 +795,45 @@ func Test_findVariant(t *testing.T) {
|
|||
reverse: false,
|
||||
want: "far_b",
|
||||
},
|
||||
{
|
||||
name: "AddFarVariationDependencies(far, b) to missing",
|
||||
// A dependency with far variations and aliases
|
||||
possibleDeps: makeDependencyGroup(
|
||||
alias{
|
||||
variant: variant{
|
||||
name: "far",
|
||||
variations: variationMap{
|
||||
"far": "far",
|
||||
},
|
||||
},
|
||||
target: 1,
|
||||
},
|
||||
&moduleInfo{
|
||||
variant: variant{
|
||||
name: "far_a",
|
||||
variations: variationMap{
|
||||
"far": "far",
|
||||
"a": "a",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
variations: []Variation{{"far", "far"}, {"a", "b"}},
|
||||
far: true,
|
||||
reverse: false,
|
||||
want: "nil",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, _ := findVariant(module, tt.possibleDeps, tt.variations, tt.far, tt.reverse)
|
||||
if g, w := got.String(), fmt.Sprintf("module %q variant %q", "dep", tt.want); g != w {
|
||||
t.Errorf("findVariant() got = %v, want %v", g, w)
|
||||
if g, w := got == nil, tt.want == "nil"; g != w {
|
||||
t.Fatalf("findVariant() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got != nil {
|
||||
if g, w := got.String(), fmt.Sprintf("module %q variant %q", "dep", tt.want); g != w {
|
||||
t.Errorf("findVariant() got = %v, want %v", g, w)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue