diff mbox series

[layerindex-web,1/2] update_layer: don't parse distro configuration into the recipe datastore

Message ID 20261114044035.88470-2-tim.orling@konsulko.com
State Under Review
Delegated to: Tim Orling
Headers show
Series Fix parsing of layers like meta-luneos | expand

Commit Message

Tim Orling Nov. 14, 2026, 4:40 a.m. UTC
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
diff mbox series

Patch

diff --git a/layerindex/update_layer.py b/layerindex/update_layer.py
index 0f49371..3f21e8b 100644
--- a/layerindex/update_layer.py
+++ b/layerindex/update_layer.py
@@ -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)))
diff --git a/tests/test_distro_conf.py b/tests/test_distro_conf.py
new file mode 100644
index 0000000..8d7c22a
--- /dev/null
+++ b/tests/test_distro_conf.py
@@ -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'