Skip to content

Commit 2f1c06e

Browse files
committed
Incorporate arch into BestKey
With the `--nobest` option disabled (the default), the loader permitted only one RPM candidate per package name, selected via repository priority and version. This logic is intended to prune suboptimal version early; failure to resolve after the prune usually indicates repository issues. However, when multiple architectures are enabled, this filtering can cause resolution failures even with a valid repository state. Specifically, if a dependency requires a package from a secondary architecture (e.g. i686 on an x86_64 system), but the primary architecture variant is considered "better", the required variant is discarded before the solver can consider it. This change ensures that the "best" candidate is calculated independently for each architecture. Explicitly requested packages remain constrained to their "best" version (including best matching architecture), but the dependency tree gains the necessary flexibility to resolve architecture-sensitive requirements.
1 parent cadbe1b commit 2f1c06e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pkg/sat/loader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ type Loader struct {
2828
// (best in terms of repo priority, version criteria).
2929
type BestKey struct {
3030
name string
31+
arch string
3132
}
3233

3334
// CompareBestKey provides an arbitrary, deterministic, total order on BestKey
3435
func CompareBestKey(k1 BestKey, k2 BestKey) int {
3536
return cmp.Or(
3637
cmp.Compare(k1.name, k2.name),
38+
cmp.Compare(k1.arch, k2.arch),
3739
)
3840
}
3941

4042
func MakeBestKey(pkg *api.Package) BestKey {
41-
return BestKey{name: pkg.Name}
43+
return BestKey{name: pkg.Name, arch: pkg.Arch}
4244
}
4345

4446
func NewLoader() *Loader {

pkg/sat/sat_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ func TestNewResolver(t *testing.T) {
14291429
"testa",
14301430
},
14311431
install: []string{"testa-0:2.x86_64"},
1432-
exclude: []string{},
1432+
exclude: []string{"testa-0:3.noarch"},
14331433
solvable: true,
14341434
},
14351435
{name: "prioritize dependency: best arch & version", packages: []*api.Package{
@@ -1443,7 +1443,7 @@ func TestNewResolver(t *testing.T) {
14431443
"testa",
14441444
},
14451445
install: []string{"testa-0:1.noarch", "testb-0:2.x86_64"},
1446-
exclude: []string{},
1446+
exclude: []string{"testb-0:3.noarch"},
14471447
solvable: true,
14481448
},
14491449
{name: "cross-arch dependency (by name and by resource)", packages: []*api.Package{
@@ -1478,9 +1478,21 @@ func TestNewResolver(t *testing.T) {
14781478
"testa",
14791479
},
14801480
install: []string{"testa-0:1.x86_64", "testb-0:1.x86_64"},
1481-
exclude: []string{},
1481+
exclude: []string{"testa-0:1.noarch", "testb-0:1.noarch"},
14821482
solvable: true,
14831483
},
1484+
{name: "dependency on non-primary architecture", packages: []*api.Package{
1485+
newPkgAP("testa", "1", "noarch", 1, []string{}, []string{"/usr/lib/libb.so"}, []string{}),
1486+
newPkgAP("testb", "1", "x86_64", 1, []string{"/usr/lib64/libb.so"}, []string{}, []string{}),
1487+
newPkgAP("testb", "1", "i686", 1, []string{"/usr/lib/libb.so"}, []string{}, []string{}),
1488+
}, requires: []string{
1489+
"testa",
1490+
},
1491+
architectures: []string{"x86_64", "i686"},
1492+
install: []string{"testa-0:1.noarch", "testb-0:1.i686"},
1493+
exclude: []string{"testb-0:1.x86_64"},
1494+
solvable: true,
1495+
},
14841496

14851497
// TODO: Add test cases.
14861498
}

0 commit comments

Comments
 (0)