diff mbox series

meta/lib/oe/sanity.py: error on very long package archs

Message ID 20261123170125.328630-1-tgamblin@baylibre.com
State Under Review
Headers show
Series meta/lib/oe/sanity.py: error on very long package archs | expand

Commit Message

Trevor Gamblin Nov. 23, 2026, 5:01 p.m. UTC
RISC-V tunes that don't set RISCVPKGARCH:tune-<name> fall back to
TUNE_RISCV_PKGARCH, which grows with every extension enabled. This can
easily exceed allowable maximums for build and sstate paths, so it
should be a fatal error when this tuning string becomes too long to
build.

Add a generic check in sanity.py so that sanity.bbclass throws an error
if TUNE_PKGARCH is too long for any architecture. This gives plenty of
headroom for basic RISC-V tunings and profiles, and it should be
adequate for other platforms as well. Update the selftest in
riscvtunes.py to make sure we do a parse and check the sanity output for
the new message.

AI-Generated: Uses Claude Opus 5.5
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 meta/conf/machine/include/riscv/README     |  5 +++--
 meta/lib/oe/sanity.py                      |  9 +++++++++
 meta/lib/oeqa/selftest/cases/riscvtunes.py | 12 +++++++-----
 3 files changed, 19 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/meta/conf/machine/include/riscv/README b/meta/conf/machine/include/riscv/README
index 278da51ba9..2b84688cb9 100644
--- a/meta/conf/machine/include/riscv/README
+++ b/meta/conf/machine/include/riscv/README
@@ -92,8 +92,9 @@  TUNE_RISCV_PKGARCH - This is the PKGARCH value generated from TUNE_FEATURES.
 RISCVPKGARCH - This is the package arch actually used.  As with ARMPKGARCH
                on arm, each tune sets it as a literal in
                RISCVPKGARCH:tune-<name>, so that it only changes when
-               deliberately changed.  Tunes that don't set it fall back to
-               TUNE_RISCV_PKGARCH.
+               deliberately changed. Tunes that don't set it fall back to
+               TUNE_RISCV_PKGARCH. The sanity check errors if the package
+               arch is longer than 64 characters.
 
 The standard variables are defined as:
 
diff --git a/meta/lib/oe/sanity.py b/meta/lib/oe/sanity.py
index c9149ec974..139a2ef314 100644
--- a/meta/lib/oe/sanity.py
+++ b/meta/lib/oe/sanity.py
@@ -279,6 +279,15 @@  def check_sanity_validmachine(sanity_data):
     if tunefound == False:
         messages = messages + "Error, the PACKAGE_ARCHS variable (%s) for DEFAULTTUNE (%s) does not contain TUNE_PKGARCH (%s)." % (pkgarchs, defaulttune, tunepkg)
 
+    # Very long package archs (e.g. RISC-V tunes falling back to the full ISA
+    # string) can exceed allowable lengths for build and sstate paths, so alert
+    # the user if this is the case.
+    if len(tunepkg) > 64:
+        messages = messages + ("Error, TUNE_PKGARCH (%s) for DEFAULTTUNE (%s) is "
+                               "longer than 64 characters. Set a shorter package "
+                               "arch for the tune (e.g. RISCVPKGARCH:tune-%s on "
+                               "RISC-V).\n" % (tunepkg, defaulttune, defaulttune))
+
     return messages
 
 # Patch before 2.7 can't handle all the features in git-style diffs.  Some
diff --git a/meta/lib/oeqa/selftest/cases/riscvtunes.py b/meta/lib/oeqa/selftest/cases/riscvtunes.py
index b2ff2cc739..7e30e50a75 100644
--- a/meta/lib/oeqa/selftest/cases/riscvtunes.py
+++ b/meta/lib/oeqa/selftest/cases/riscvtunes.py
@@ -93,22 +93,24 @@  class RiscvTunesTests(OESelftestTestCase):
     def test_riscv_pkgarch_fallback(self):
         """
         Check that custom tunes which don't set RISCVPKGARCH:tune-<name> get
-        TUNE_RISCV_PKGARCH as their package arch, and that it's an error if
-        that is too long.
+        TUNE_RISCV_PKGARCH as their package arch, and that the sanity checks
+        reject it if that is too long.
         """
         def config(tune, features):
             return self._machine_config() + \
                    'AVAILTUNES += "%s"\n' \
                    'TUNE_FEATURES:tune-%s = "%s"\n' \
-                   'DEFAULTTUNE = "%s"\n' % (tune, tune, features, tune)
+                   'PACKAGE_EXTRA_ARCHS:tune-%s = "${RISCVPKGARCH}"\n' \
+                   'DEFAULTTUNE = "%s"\n' % (tune, tune, features, tune, tune)
 
         self.write_config(config('rv64imac-zicond', riscv_isa_to_tune('rv64imac_zicond')))
         self.assertEqual(get_bb_var('TUNE_PKGARCH'), 'riscv64imac_zicond')
 
+        # Use 'bitbake -p' to parse, so that sanity checks are triggered
         self.write_config(config('rva22-zicond', riscv_isa_to_tune('rva22u64') + ' zicond'))
-        result = bitbake('-e', ignore_status=True)
+        result = bitbake('-p', ignore_status=True)
         self.assertNotEqual(result.status, 0)
-        self.assertIn('Set RISCVPKGARCH:tune-rva22-zicond to a shorter name', result.output)
+        self.assertIn('for DEFAULTTUNE (rva22-zicond) is longer than 64 characters', result.output)
 
     def test_riscv_unusual_tunes(self):
         """