diff mbox series

[RFC,12/14] meta/lib/oe/tune.py: add riscv_pkgarch()

Message ID 20260915190244.2983746-13-tgamblin@baylibre.com
State New
Headers show
Series riscv: add new ISA extensions and profile support | expand

Commit Message

Trevor Gamblin Sept. 15, 2026, 7:02 p.m. UTC
Create a new function to help match RISC-V ISA extension combinations
against recognized profile strings (e.g. 'rva22u64'), so that we can use
simpler patterns for naming things like sstate/build paths.

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 meta/lib/oe/tune.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oe/tune.py b/meta/lib/oe/tune.py
index 7296f39e66..0d8e4417e7 100644
--- a/meta/lib/oe/tune.py
+++ b/meta/lib/oe/tune.py
@@ -90,3 +90,32 @@  def riscv_isa_to_tune(isa):
     # Eliminate duplicates, but preserve the order
     feature = list(dict.fromkeys(feature))
     return ' '.join(feature)
+
+# riscv_pkgarch(features, exact_pkgarch)
+#
+# Prefer a RISCV_PROFILES name (plus any extensions enabled on top of it) as the
+# package arch fragment, since otherwise the full ISA extension list will exceed
+# what the sstate class can handle. When several profiles match, the one with
+# the most extensions is preferred, as it is the more specific/clearer match.
+# If there's no clear profile matching the extension list, then fall back to
+# exact_pkgarch.
+def riscv_pkgarch(features, exact_pkgarch):
+    if not features:
+        return exact_pkgarch
+
+    current = set(features.split())
+
+    best_match = None
+    best_features = None
+    for name in RISCV_PROFILES:
+        profile_features = set(riscv_isa_to_tune(name).split())
+        if profile_features.issubset(current):
+            if best_features is None or len(profile_features) > len(best_features):
+                best_match = name
+                best_features = profile_features
+
+    if best_match is None:
+        return exact_pkgarch
+
+    extra = sorted(current - best_features)
+    return '_'.join([best_match] + extra)