diff mbox series

[layerindex-web,2/6] rrs/tools/common.py: import BitBake after checking out its revision

Message ID 20261115003506.53654-3-tim.orling@konsulko.com
State Under Review
Delegated to: Tim Orling
Headers show
Series Get the RRS update scripts working again | expand

Commit Message

Tim Orling Nov. 15, 2026, 12:35 a.m. UTC
load_recipes() imported bb.fetch before recipeparse.init_parser() checks
out the BitBake revision for the branch, so the bb package came from
whichever revision was checked out before, e.g. an old one left by
rrs_upgrade_history.py, while the rest of BitBake came from the new
one. rrs_upstream_history.py then failed with "cannot import name
'multiprocessing' from 'bb'". Import it after init_parser().

[YOCTO #16501]

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 rrs/tools/common.py            |  4 +++-
 tests/test_rrs_load_recipes.py | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_rrs_load_recipes.py
diff mbox series

Patch

diff --git a/rrs/tools/common.py b/rrs/tools/common.py
index 0caf1c9..ccdbe62 100644
--- a/rrs/tools/common.py
+++ b/rrs/tools/common.py
@@ -93,7 +93,6 @@  def get_recipe_files(layerdir):
 def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger,
         recipe_files=None, nocheckout=False):
     from layerindex import recipeparse
-    from bb.fetch import FetchError
 
     try:
         (tinfoil, tempdir) = recipeparse.init_parser(settings,
@@ -102,6 +101,9 @@  def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger,
     except recipeparse.RecipeParseError as e:
         logger.error(str(e))
         sys.exit(1)
+    # Only now that init_parser() has checked out the BitBake revision for the
+    # branch, or bb would be loaded from whichever one was checked out before
+    from bb.fetch import FetchError
 
     layer = layerbranch.layer
     urldir = str(layer.get_fetch_dir())
diff --git a/tests/test_rrs_load_recipes.py b/tests/test_rrs_load_recipes.py
new file mode 100644
index 0000000..97f3d26
--- /dev/null
+++ b/tests/test_rrs_load_recipes.py
@@ -0,0 +1,35 @@ 
+# layerindex-web - tests for load_recipes() in rrs/tools/common.py
+#
+# Licensed under the MIT license, see COPYING.MIT for details
+#
+# SPDX-License-Identifier: MIT
+
+import os
+import sys
+import types
+
+import pytest
+
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'rrs', 'tools'))
+
+
+def test_load_recipes_checks_out_bitbake_before_importing_it(monkeypatch):
+    # [YOCTO #16501] bb must come from the revision init_parser() checks out
+    import common
+    # As common_setup() does for the scripts: recipeparse imports utils
+    monkeypatch.syspath_prepend(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'layerindex'))
+    from layerindex import recipeparse
+
+    class Stop(Exception):
+        pass
+
+    def fake_init_parser(*args, **kwargs):
+        assert 'bb.fetch' not in sys.modules
+        raise Stop()
+
+    for name in [m for m in sys.modules if m == 'bb' or m.startswith('bb.')]:
+        monkeypatch.delitem(sys.modules, name)
+    monkeypatch.setattr(recipeparse, 'init_parser', fake_init_parser)
+    with pytest.raises(Stop):
+        common.load_recipes(types.SimpleNamespace(branch=None), '/nonexistent', '/nonexistent',
+                            types.SimpleNamespace(), None)