Skip to contentSkip to conversation

providers: Select highest matching version for PREFERRED_VERSION

PATCH New Mark Asselstine 1 participant 1 message Nov 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 providers: Select highest matching version for PREFERRED_VERSION

When PREFERRED_VERSION or REQUIRED_VERSION uses a '%' wildcard, findPreferredProvider() stopped at the first matching file in the list. Files within a priority set are not sorted by version, so the result depended on file order. For example, with PREFERRED_VERSION_blah = "4.%" and the recipes blah_4.0.bb, blah_4.0.1.bb and blah_4.1.bb, blah_4.0.1.bb was selected instead of blah_4.1.bb.

Check every matching file in the set and keep the highest one, compared with utils.vercmp(), as findLatestProvider() does. The first priority set that contains a match still wins, so layer priority and DEFAULT_PREFERENCE continue to take precedence over version. Exact version matches are unaffected.

Fixes [YOCTO #15967]

AI-Generated: Kiro (Claude Opus 5.5)

---
 lib/bb/providers.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/providers.py +4 -3
index e11a4637d..51f61b6e1 100644
@@ -160,9 +160,10 @@ def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None):
             for f in file_set:
                 pe, pv, pr = dataCache.pkg_pepvpr[f]
                 if preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r):
-                    preferred_file = f
-                    preferred_ver = (pe, pv, pr)
-                    break
+                    # Several files may match (e.g. with a '%' wildcard), keep the highest version
+                    if preferred_file is None or utils.vercmp(preferred_ver, (pe, pv, pr)) < 0:
+                        preferred_file = f
+                        preferred_ver = (pe, pv, pr)
             if preferred_file:
                 break;
         if preferred_r:
Signature · 1 line
2.43.0