diff mbox series

[layerindex-web,1/2] rrs_distros: strip the native/cross suffixes before matching distro packages

Message ID 20261115031803.74076-4-tim.orling@konsulko.com
State Under Review
Delegated to: Tim Orling
Headers show
Series rrs_distros: match python3-* recipes to distro packages | expand

Commit Message

Tim Orling Nov. 15, 2026, 3:18 a.m. UTC
search_package_in_distros() meant to strip nativesdk-, -native, -cross
and -initial from the recipe name, but discarded the result of
str.replace(). Keep it.

[YOCTO #16513]

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

Patch

diff --git a/rrs/tools/rrs_distros.py b/rrs/tools/rrs_distros.py
index 3dc745d..55f5aeb 100755
--- a/rrs/tools/rrs_distros.py
+++ b/rrs/tools/rrs_distros.py
@@ -59,7 +59,7 @@  def search_package_in_distros(pkglst_dir, recipe, data):
 
     removes = ['nativesdk-', '-native', '-cross', '-initial']
     for r in removes:
-        recipe_name.replace(r, '')
+        recipe_name = recipe_name.replace(r, '')
 
     distro_alias = data.getVar('DISTRO_PN_ALIAS', True)
     if distro_alias:
diff --git a/tests/test_rrs_distros.py b/tests/test_rrs_distros.py
new file mode 100644
index 0000000..419b44d
--- /dev/null
+++ b/tests/test_rrs_distros.py
@@ -0,0 +1,45 @@ 
+# layerindex-web - tests for matching recipes to distro packages in rrs/tools/rrs_distros.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'))
+
+
+@pytest.fixture
+def rrs_distros(monkeypatch):
+    # The test settings don't install the rrs app, which the script imports
+    monkeypatch.setitem(sys.modules, 'rrs.models', types.SimpleNamespace(RecipeDistro=None, MaintenancePlan=None))
+    monkeypatch.delitem(sys.modules, 'rrs_distros', raising=False)
+    import rrs_distros
+    return rrs_distros
+
+
+@pytest.fixture
+def pkglst_dir(tmp_path):
+    # Package lists as OE-Core's distro_check writes them: <distro>-<release>, "<name>:<section>" lines
+    (tmp_path / 'Debian-13.7').write_text('brotli:main\npython3-brotli:main\nlz4:main\nfoo:main\n')
+    (tmp_path / 'Fedora-45').write_text('python-brotli:main\nlz4:main\n')
+    return tmp_path
+
+
+def search(rrs_distros, pkglst_dir, pn, alias=None):
+    recipe = types.SimpleNamespace(pn=pn)
+    data = types.SimpleNamespace(getVar=lambda name, expand=True: alias if name == 'DISTRO_PN_ALIAS' else None)
+    return rrs_distros.search_package_in_distros(str(pkglst_dir), recipe, data)
+
+
+def test_native_suffix_is_ignored(rrs_distros, pkglst_dir):
+    assert search(rrs_distros, pkglst_dir, 'foo-native') == {'Debian-main': 'foo'}
+
+
+def test_distro_pn_alias(rrs_distros, pkglst_dir):
+    assert search(rrs_distros, pkglst_dir, 'liblz4', alias='Debian=lz4 Fedora=lz4') == {'Debian-main': 'lz4', 'Fedora-main': 'lz4'}
+