@@ -248,7 +248,9 @@ def update_distro_conf_file(path, distro, d):
distro_name = ''
try:
- d = utils.parse_conf(path, d)
+ # Parse into a copy: d is also used to parse the layer's recipes,
+ # which must not get this distro's configuration
+ d = utils.parse_conf(path, d.createCopy())
distro_name = d.getVar('DISTRO_NAME', True)
except Exception as e:
logger.warn('Error parsing distro configuration file %s: %s' % (path, str(e)))
new file mode 100644
@@ -0,0 +1,47 @@
+# layerindex-web - test that indexing a distro configuration file doesn't
+# change the configuration used to parse recipes
+#
+# Licensed under the MIT license, see COPYING.MIT for details
+#
+# SPDX-License-Identifier: MIT
+
+import os
+import sys
+import types
+
+import pytest
+
+basepath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+
+
+@pytest.fixture
+def bb_data(settings):
+ from layerindex.models import LayerItem
+ bitbakepath = os.path.join(settings.LAYER_FETCH_DIR,
+ LayerItem(vcs_url=settings.BITBAKE_REPO_URL).get_fetch_dir())
+ if not os.path.isdir(os.path.join(bitbakepath, 'lib', 'bb')):
+ pytest.skip('BitBake not fetched to %s' % bitbakepath)
+ for path in (os.path.join(bitbakepath, 'lib'), os.path.join(basepath, 'layerindex')):
+ if path not in sys.path:
+ sys.path.insert(0, path)
+ import bb.data
+ import bb.parse
+ import utils
+ utils.bb = sys.modules['bb']
+ return bb.data
+
+
+def test_distro_conf_not_parsed_into_recipe_data(bb_data, tmp_path):
+ import update_layer
+ conf = tmp_path / 'conf' / 'distro' / 'testdistro.conf'
+ conf.parent.mkdir(parents=True)
+ conf.write_text('DISTRO_NAME = "Test Distro"\nLEAKCHECK = "from the distro"\n')
+ d = bb_data.init()
+ d.setVar('LEAKCHECK', 'original')
+ distro = types.SimpleNamespace(description='')
+
+ update_layer.update_distro_conf_file(str(conf), distro, d)
+
+ assert distro.description == 'Test Distro'
+ # Recipes parsed with d afterwards must not see the distro's settings
+ assert d.getVar('LEAKCHECK') == 'original'
To index a layer's distros, update_layer.py parsed each distro configuration file into the datastore it then uses to parse the layer's recipes, so every recipe parsed after it got that distro's configuration. For meta-luneos, image recipes then failed with "NameError: name 'oebackport' is not defined" from a LuneOS variable. Parse each distro configuration file into a copy instead. [YOCTO #16497] AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling <tim.orling@konsulko.com> --- layerindex/update_layer.py | 4 +++- tests/test_distro_conf.py | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/test_distro_conf.py