Skip to contentSkip to conversation

Fixes for errors and warnings in layer updates

PATCH New Tim Orling 1 participant 5 messages Oct 19

lore
Share & tools
lore

Tim Orling

author
#0 lore raw

cover Fixes for errors and warnings in layer updates

These fix problems found while running full updates on a test instance loaded with a copy of the layers.openembedded.org database.

1: Files in layers within a layer were indexed as part of the outer
layer on incremental updates (e.g. meta-voltumna's vendored openembedded-core and meta-openembedded). Affected layer branches need a full rescan (update.py -r) to drop those records.
2: A layer first seen on a new branch copied its subdirectory from the
oldest branch, so meta-tq failed on wrynose.
3: The core layer was in BBPATH twice, giving a "Duplicate inclusion"
warning for maintainers.inc for every layer. The matching BitBake fix for include_all has been sent to bitbake-devel.
4: Long recipe values (LICENSE, inherits, BBCLASSEXTEND, ...) were being
truncated. This adds a migration on layerindex_recipe, which took under a minute for 365,000 recipes on the test instance.

Tim Orling (4):
update_layer.py: skip layers within a layer on incremental updates
update: copy a new layer branch's subdirectory from the newest branch
recipeparse: don't add the core layer to BBPATH twice layerindex/models.py: store long recipe values without truncating

 .../migrations/0055_recipe_text_fields.py     | 58 +++++++++++++++++++
 layerindex/models.py                          | 27 ++++++---
 layerindex/recipeparse.py                     |  9 +--
 layerindex/update.py                          |  2 +-
 layerindex/update_layer.py                    | 41 ++++---------
 layerindex/utils.py                           | 22 +++++++
 tests/test_latest_layerbranch.py              | 52 +++++++++++++++++
 tests/test_recipe_fields.py                   | 53 +++++++++++++++++
 tests/test_utils.py                           | 45 ++++++++++++++
 9 files changed, 264 insertions(+), 45 deletions(-)
 create mode 100644 layerindex/migrations/0055_recipe_text_fields.py
 create mode 100644 tests/test_latest_layerbranch.py
 create mode 100644 tests/test_recipe_fields.py

base-commit: ede7510fae1ea6225cac56a020e5e9ae0033b467

Signature · 1 line
2.56.0
author
#1 lore raw

PATCH 1/4 update_layer.py: skip layers within a layer on incremental updates

On incremental updates the check for layers within a layer compared repository-relative git diff paths with absolute directory paths, so it never matched, and files in nested layers (e.g. meta-voltumna's vendored copies of oe-core and meta-openembedded) were indexed as part of the outer layer. Move the check into utils.nested_layer_dirs() and utils.in_nested_layer(), use it for all change types, and treat renames into a nested layer as deletes.

Records already indexed this way are removed by a full rescan (update.py -r).

AI-Generated: Claude Opus 5.5

---
 layerindex/update_layer.py | 39 ++++++++-------------------------
 layerindex/utils.py        | 22 +++++++++++++++++++
 tests/test_utils.py        | 45 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 30 deletions(-)
layerindex/update_layer.py +9 -30
index 55b3e14..441efc2 100644
@@ -494,11 +494,7 @@ def main():
                 layerrecipes_add = []
 
                 # Check if any paths should be ignored because there are layers within this layer
-                removedirs = []
-                for root, dirs, files in os.walk(layerdir):
-                    for diritem in dirs:
-                        if os.path.exists(os.path.join(root, diritem, 'conf', 'layer.conf')):
-                            removedirs.append(os.path.join(root, diritem) + os.sep)
+                removedirs = utils.nested_layer_dirs(layerdir)
 
                 if diff:
                     # Apply git changes to existing recipe list
@@ -515,19 +511,17 @@ def main():
                     for diffitem in diff.iter_change_type('R'):
                         oldpath = diffitem.a_blob.path
                         newpath = diffitem.b_blob.path
-                        skip = False
-                        for removedir in removedirs:
-                            # FIXME what about files moved into removedirs?
-                            if oldpath.startswith(removedir):
-                                skip = True
-                                break
-                        if skip:
+                        if utils.in_nested_layer(oldpath, removedirs, repodir):
                             continue
                         if oldpath.startswith(subdir_start):
                             if not newpath.startswith(subdir_start):
                                 logger.debug("Treating rename of %s to %s as a delete since new path is outside layer" % (oldpath, newpath))
                                 other_deletes.append(diffitem)
                                 continue
+                            if utils.in_nested_layer(newpath, removedirs, repodir):
+                                logger.debug("Treating rename of %s to %s as a delete since new path is in a layer within this layer" % (oldpath, newpath))
+                                other_deletes.append(diffitem)
+                                continue
                             (oldtypename, oldfilepath, oldfilename) = recipeparse.detect_file_type(oldpath, subdir_start)
                             (newtypename, newfilepath, newfilename) = recipeparse.detect_file_type(newpath, subdir_start)
                             if oldtypename != newtypename:
@@ -606,12 +600,7 @@ def main():
                     for diffitem in itertools.chain(diff.iter_change_type('D'), other_deletes):
                         path = diffitem.a_blob.path
                         if path.startswith(subdir_start):
-                            skip = False
-                            for removedir in removedirs:
-                                if path.startswith(removedir):
-                                    skip = True
-                                    break
-                            if skip:
+                            if utils.in_nested_layer(path, removedirs, repodir):
                                 continue
                             (typename, filepath, filename) = recipeparse.detect_file_type(path, subdir_start)
                             if typename == 'recipe':
@@ -636,12 +625,7 @@ def main():
                     for diffitem in itertools.chain(diff.iter_change_type('A'), other_adds):
                         path = diffitem.b_blob.path
                         if path.startswith(subdir_start):
-                            skip = False
-                            for removedir in removedirs:
-                                if path.startswith(removedir):
-                                    skip = True
-                                    break
-                            if skip:
+                            if utils.in_nested_layer(path, removedirs, repodir):
                                 continue
                             (typename, filepath, filename) = recipeparse.detect_file_type(path, subdir_start)
                             if typename == 'recipe':
@@ -685,12 +669,7 @@ def main():
                     for diffitem in diff.iter_change_type('M'):
                         path = diffitem.b_blob.path
                         if path.startswith(subdir_start):
-                            skip = False
-                            for removedir in removedirs:
-                                if path.startswith(removedir):
-                                    skip = True
-                                    break
-                            if skip:
+                            if utils.in_nested_layer(path, removedirs, repodir):
                                 continue
                             (typename, filepath, filename) = recipeparse.detect_file_type(path, subdir_start)
                             if typename == 'recipe':
layerindex/utils.py +22 -0
index e5bad40..fd29de0 100644
@@ -57,6 +57,28 @@ def get_layer_var(config_data, var, logger):
         value = config_data.getVar(var, True)
     return value or ''
 
+def nested_layer_dirs(layerdir):
+    """
+    Return the directories below layerdir that contain a conf/layer.conf of
+    their own, i.e. other layers within this layer, each with a trailing
+    separator.
+    """
+    dirs = []
+    for root, subdirs, _ in os.walk(layerdir):
+        for subdir in subdirs:
+            if os.path.exists(os.path.join(root, subdir, 'conf', 'layer.conf')):
+                dirs.append(os.path.join(root, subdir) + os.sep)
+    return dirs
+
+def in_nested_layer(path, nested_dirs, repodir):
+    """
+    Check whether path is within one of nested_dirs (as returned by
+    nested_layer_dirs()). path may be relative to repodir, as git diff paths
+    are, or absolute.
+    """
+    fullpath = os.path.join(repodir, path)
+    return any(fullpath.startswith(nested_dir) for nested_dir in nested_dirs)
+
 def is_deps_satisfied(req_col, req_ver, collections):
     """ Check whether required collection and version are in collections"""
     for existed_col, existed_ver in collections:
tests/test_utils.py +45 -0

54 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#2 lore raw

PATCH 2/4 update: copy a new layer branch's subdirectory from the newest branch

In reply to Tim Orling

When a layer is first found on a new branch, vcs_subdir was copied from get_layerbranch(None), an arbitrary and usually the oldest layer branch. meta-tq has since moved into a subdirectory, so its wrynose update failed with "conf/layer.conf not found". Copy it from the newest non-comparison branch instead.

AI-Generated: Claude Opus 5.5

---
 layerindex/models.py             |  9 ++++++
 layerindex/update.py             |  2 +-
 layerindex/update_layer.py       |  2 +-
 tests/test_latest_layerbranch.py | 52 ++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 tests/test_latest_layerbranch.py
layerindex/models.py +9 -0
index a72a72b..a9e9bdf 100644
@@ -162,6 +162,15 @@ class LayerItem(models.Model):
             return res[0]
         return None
 
+    def get_latest_layerbranch(self):
+        """
+        Return the layer branch for the newest non-comparison branch (by
+        branch sort priority), e.g. to copy settings such as vcs_subdir from
+        when the layer is first seen on a new branch.
+        """
+        return self.layerbranch_set.filter(branch__comparison=False).order_by(
+            models.F('branch__sort_priority').asc(nulls_last=True), '-id').first()
+
     def active_maintainers(self):
         matches = None
         for layerbranch in self.layerbranch_set.all():
layerindex/update.py +1 -1
index dd730ca..ca68e3e 100755
@@ -389,7 +389,7 @@ def main():
                         layerbranch.branch = branchobj
                         layerbranch_source = layer.get_layerbranch(branchobj)
                         if not layerbranch_source:
-                            layerbranch_source = layer.get_layerbranch(None)
+                            layerbranch_source = layer.get_latest_layerbranch()
                         if layerbranch_source:
                             layerbranch.vcs_subdir = layerbranch_source.vcs_subdir
 
layerindex/update_layer.py +1 -1
index 441efc2..0f49371 100644
@@ -380,7 +380,7 @@ def main():
                     layerbranch.actual_branch = options.actual_branch
                 layerbranch_source = layer.get_layerbranch(branch)
                 if not layerbranch_source:
-                    layerbranch_source = layer.get_layerbranch(None)
+                    layerbranch_source = layer.get_latest_layerbranch()
                 if layerbranch_source:
                     layerbranch.vcs_subdir = layerbranch_source.vcs_subdir
                 layerbranch.save()
tests/test_latest_layerbranch.py new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#3 lore raw

PATCH 3/4 recipeparse: don't add the core layer to BBPATH twice

In reply to Tim Orling

The core layer is in BBLAYERS, so its layer.conf already appends it to BBPATH. Adding it to the initial BBPATH as well made include_all read maintainers.inc twice, giving "Duplicate inclusion" warnings. Leave it out of the initial BBPATH, and use core_layerdir in BBLAYERS instead of assuming "meta".

AI-Generated: Claude Opus 5.5

---
 layerindex/recipeparse.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
layerindex/recipeparse.py +5 -4
index d593def..d8486e7 100644
@@ -66,10 +66,11 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
             utils.checkout_repo(core_repodir, "origin/%s" % core_branchname, logger=logger)
         if not os.path.exists(os.path.join(core_layerdir, 'conf/bitbake.conf')):
             raise RecipeParseError("conf/bitbake.conf not found in core layer %s - is subdirectory set correctly?" % core_layer.name)
-        # The directory above where this script exists should contain our conf/layer.conf,
-        # so add it to BBPATH along with the core layer directory
+        # The directory above where this script exists should contain our conf/local.conf,
+        # so add it to BBPATH. The core layer is added by its layer.conf via BBLAYERS
+        # below; listing it here as well would put it in BBPATH twice.
         confparentdir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
-        os.environ['BBPATH'] = str("%s:%s" % (confparentdir, core_layerdir))
+        os.environ['BBPATH'] = str(confparentdir)
 
     # Change into a temporary directory so we don't write the cache and other files to the current dir
     if not os.path.exists(settings.TEMP_BASE_DIR):
@@ -84,7 +85,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
         if not classic:
             # We need this to avoid problems with AVAILABLE_LICENSES
             f.write('COREBASE = "%s"\n' % core_repodir)
-            f.write('BBLAYERS = "%s/meta"\n' % core_repodir)
+            f.write('BBLAYERS = "%s"\n' % core_layerdir)
         pass
 
     if logger:
Signature · 1 line
2.56.0
author
#4 lore raw

PATCH 4/4 layerindex/models.py: store long recipe values without truncating

In reply to Tim Orling

Several Recipe fields hold free-form values from the metadata with no real length limit, and the update script kept truncating them (e.g. linux-firmware's LICENSE at 4688 characters). Raising CharField limits again only moves the problem and runs into MariaDB's per-row VARCHAR limit, so make Recipe.summary, license, provides, bbclassextend, inherits and configopts, and PackageConfig.with_option and without_option, TextFields. Recipe.pn is indexed, so raise it to 255 characters instead.

AI-Generated: Claude Opus 5.5

---
 .../migrations/0055_recipe_text_fields.py     | 58 +++++++++++++++++++
 layerindex/models.py                          | 18 +++---
 tests/test_recipe_fields.py                   | 53 +++++++++++++++++
 3 files changed, 120 insertions(+), 9 deletions(-)
 create mode 100644 layerindex/migrations/0055_recipe_text_fields.py
 create mode 100644 tests/test_recipe_fields.py
layerindex/migrations/0055_recipe_text_fields.py new file +58 -0
new file mode 100644
index 0000000..0714623
@@ -0,0 +1,58 @@
+# Generated by Django 5.2.18 on 2026-10-19 03:19
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('layerindex', '0054_alter_sitenotice_expires'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='packageconfig',
+            name='with_option',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='packageconfig',
+            name='without_option',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='bbclassextend',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='configopts',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='inherits',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='license',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='pn',
+            field=models.CharField(blank=True, max_length=255),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='provides',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='recipe',
+            name='summary',
+            field=models.TextField(blank=True),
+        ),
+    ]
layerindex/models.py +9 -9
index a9e9bdf..425af53 100644
@@ -469,22 +469,22 @@ class Recipe(models.Model):
     layerbranch = models.ForeignKey(LayerBranch, on_delete=models.CASCADE)
     filename = models.CharField(max_length=255)
     filepath = models.CharField(max_length=255, blank=True)
-    pn = models.CharField(max_length=100, blank=True)
+    pn = models.CharField(max_length=255, blank=True)
     pv = models.CharField(max_length=100, blank=True)
     pr = models.CharField(max_length=100, blank=True)
     pe = models.CharField(max_length=100, blank=True)
-    summary = models.CharField(max_length=200, blank=True)
+    summary = models.TextField(blank=True)
     description = models.TextField(blank=True)
     section = models.CharField(max_length=100, blank=True)
-    license = models.CharField(max_length=3072, blank=True)
+    license = models.TextField(blank=True)
     homepage = models.URLField(blank=True)
     bugtracker = models.URLField(blank=True)
-    provides = models.CharField(max_length=2048, blank=True)
-    bbclassextend = models.CharField(max_length=100, blank=True)
-    inherits = models.CharField(max_length=383, blank=True)
+    provides = models.TextField(blank=True)
+    bbclassextend = models.TextField(blank=True)
+    inherits = models.TextField(blank=True)
     updated = models.DateTimeField(auto_now=True)
     blacklisted = models.CharField(max_length=255, blank=True)
-    configopts = models.CharField(max_length=4096, blank=True)
+    configopts = models.TextField(blank=True)
     srcrev = models.CharField(max_length=64, blank=True)
 
     class Meta:
@@ -639,8 +639,8 @@ class Patch(models.Model):
 class PackageConfig(models.Model):
     recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
     feature = models.CharField(max_length=255)
-    with_option = models.CharField(max_length=255, blank=True)
-    without_option = models.CharField(max_length=255, blank=True)
+    with_option = models.TextField(blank=True)
+    without_option = models.TextField(blank=True)
     build_deps = models.CharField(max_length=255, blank=True)
 
     def __str__(self):
tests/test_recipe_fields.py new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.56.0