Fix parsing of layers like meta-luneos
cover Fix parsing of layers like meta-luneos
Image recipes in meta-luneos fail to parse in the layer index with "NameError: name 'oebackport' is not defined" (bug 16192). Two independent problems lead to it; each patch fixes one, and each on its own stops the failure.
1: Bug 16497: update_layer.py parses each distro configuration file
into the datastore it then parses the layer's recipes with, so the recipes parsed after luneos.conf got LuneOS's configuration. They are now parsed into a copy.
2: Bug 16192: the BitBake server, which parses the recipes, never
imported the libraries a layer adds with addpylib in its conf/layer.conf. Their addpylib statements now go in the bblayers.conf it reads.
On a test instance loaded with a copy of the layers.openembedded.org database, luneos-emulator-appliance.bb and luneos-image.bb on scarthgap fail as reported when parsed after luneos.conf, as update_layer.py does, and parse with either patch. Dry-run updates of meta-tegra, meta-qcom and meta-luneos, which use addpylib, give the same errors and warnings with and without the series. The test suite passes in the Docker image at each patch (77 passed, 1 skipped at the end).
Tim Orling (2):
update_layer: don't parse distro configuration into the recipe
datastore
update_layer: make addpylib libraries available to recipe parsing
layerindex/recipeparse.py | 23 ++++++++++++++++++- layerindex/update_layer.py | 13 +++++++++-- tests/test_distro_conf.py | 47 ++++++++++++++++++++++++++++++++++++++ tests/test_update.py | 20 ++++++++++++++++ 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 tests/test_distro_conf.py
base-commit: 08e58cdece30019a6f9e5d14af16ebe20afa6177
Signature · 1 line
2.56.0
PATCH 1/2 update_layer: don't parse distro configuration into the recipe datastore
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
--- 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
layerindex/update_layer.py +3 -1
@@ -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)))
tests/test_distro_conf.py new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH 2/2 update_layer: make addpylib libraries available to recipe parsing
In reply to Tim OrlingA recipe that uses a Python library added with addpylib in its layer's conf/layer.conf failed to parse, e.g. meta-luneos with "NameError: name 'oebackport' is not defined". update_layer.py parses layer.conf itself, but the recipes are parsed by the BitBake server, which only processes addpylib in its base configuration, so the library was never imported there. Add the addpylib statements of the layer and its dependencies to the bblayers.conf the server reads.
[YOCTO #16192]
AI-Generated: Claude Opus 5.5
--- layerindex/recipeparse.py | 23 ++++++++++++++++++++++- layerindex/update_layer.py | 9 ++++++++- tests/test_update.py | 20 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-)
layerindex/recipeparse.py +22 -1
@@ -24,7 +24,24 @@ class RecipeParseError(Exception): -def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None): +def layer_addpylibs(layerdir): + """ + Return the addpylib statements in a layer's conf/layer.conf, with LAYERDIR + expanded. The BitBake server only processes addpylib while parsing its base + configuration, so these need to go in bblayers.conf for its recipe parsing + to be able to use the libraries. + """ + lines = [] + try: + with open(os.path.join(layerdir, 'conf', 'layer.conf')) as f: + for line in f: + if re.match(r'\s*addpylib\s', line): + lines.append(line.strip().replace('${LAYERDIR}', layerdir)) + except FileNotFoundError: + pass + return lines + +def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None, pylib_layerdirs=None): if not (nocheckout or classic): # Check out the branch of BitBake appropriate for this branch and clean out any stale files (e.g. *.pyc) if re.match('[0-9a-f]{40}', branch.bitbake_branch):
@@ -86,6 +103,10 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout # We need this to avoid problems with AVAILABLE_LICENSES f.write('COREBASE = "%s"\n' % core_repodir) f.write('BBLAYERS = "%s"\n' % core_layerdir) + # Python libraries of the layer being parsed and its dependencies + for layerdir in pylib_layerdirs or []: + for line in layer_addpylibs(layerdir): + f.write(line + '\n') pass if logger:
layerindex/update_layer.py +8 -1
@@ -428,8 +428,15 @@ def main(): logger.warn("Unable to checkout dependent layer %s - %s" % (layerdependency.dependency, str(e))) logger.info("Collecting data for layer %s on branch %s" % (layer.name, branchdesc)) + # Layers whose addpylib libraries recipes may use (the core + # layer's are loaded through BBLAYERS) + pylib_layerdirs = [layerdir] + for dep in layerbranch.dependencies_set.all(): + deplayerbranch = dep.dependency.get_layerbranch(branch.name) + if deplayerbranch and dep.dependency.name != settings.CORE_LAYER_NAME: + pylib_layerdirs.append(os.path.join(fetchdir, dep.dependency.get_fetch_dir(), deplayerbranch.vcs_subdir)) try: - (tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=options.nocheckout, logger=logger) + (tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, nocheckout=options.nocheckout, logger=logger, pylib_layerdirs=pylib_layerdirs) except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1)
tests/test_update.py +20 -0
@@ -144,6 +144,26 @@ def test_upgrade_recipe(import_layer, repo, db_access_without_rollback_and_trunc assert recipe.filename == 'upgrademe_0.2.bb' assert recipe.filepath == 'recipes-example/upgrademe' +def test_addpylib_used_in_recipe(import_layer, repo, db_access_without_rollback_and_truncate): + # [YOCTO #16192] a recipe can use a Python library the layer adds with + # addpylib in conf/layer.conf, as it can in a build + from layerindex.models import LayerBranch, Recipe + layerdir = os.path.join(repo, 'meta-layerindex-test') + os.makedirs(os.path.join(layerdir, 'lib', 'layerindextestlib')) + with open(os.path.join(layerdir, 'lib', 'layerindextestlib', '__init__.py'), 'w') as f: + f.write('def summary():\n return "Summary from addpylib"\n') + with open(os.path.join(layerdir, 'conf', 'layer.conf'), 'a') as f: + f.write('\naddpylib ${LAYERDIR}/lib layerindextestlib\n') + os.makedirs(os.path.join(layerdir, 'recipes-example', 'pylib')) + with open(os.path.join(layerdir, 'recipes-example', 'pylib', 'pylib_1.0.bb'), 'w') as f: + f.write('SUMMARY = "${@layerindextestlib.summary()}"\nLICENSE = "MIT"\n') + run_cmd('git add -A && git commit -m "Add a recipe that uses addpylib"', cwd=repo) + run_cmd("layerindex/update.py -d -l meta-layerindex-test --nofetch --nocheckout") + layerbranch = LayerBranch.objects.get(layer__name='meta-layerindex-test') + recipe = Recipe.objects.filter(layerbranch=layerbranch, pn='pylib').first() + assert recipe, 'pylib recipe not found' + assert recipe.summary == 'Summary from addpylib' + def test_add_recipe(import_layer, repo, db_access_without_rollback_and_truncate): from layerindex.models import LayerBranch, Recipe layerbranch = LayerBranch.objects.get(layer__name='meta-layerindex-test')
Signature · 1 line
2.56.0