@@ -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())
new file mode 100644
@@ -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)
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