diff mbox series

[v2] yocto-check-layer: don't skip entries when dropping invalid layers

Message ID 20261030121428.1658630-1-vinicius.eduardo.pedrosa@gmail.com
State New
Headers show
Series [v2] yocto-check-layer: don't skip entries when dropping invalid layers | expand

Commit Message

Vinicius Pedrosa Oct. 30, 2026, 12:14 p.m. UTC
The "Detected layers" loop removes invalid entries from the list it's
iterating over. When two invalid layers are next to each other,
removing the first one skips the second.

A skipped entry without conf/layer.conf makes the dependency pass fail
with KeyError: 'collections'. A skipped BSP+DISTRO entry isn't
reported at all. If no other layer is left to test, the script exits 0.

Move the check into validate_layers(), which returns a new list with
only the valid layers. Call it right after detect_layers(), so
dep_layers is built from the filtered list too.

Signed-off-by: Vinicius Pedrosa <vinicius.eduardo.pedrosa@gmail.com>
---
v2: move the check into validate_layers(), as suggested by Paul.

Since it now runs before dep_layers is built, a dropped BSP+DISTRO
layer no longer takes part in the duplicate collection check, and with
--dependency it can't be pulled in as a dependency of another layer
anymore. Without --dependency it already couldn't.

Hit it on a layer that had a few subdirectories with an empty conf/ in
them.

Tested on master (b62d5e6) with small synthetic layers, same tree and
command before/after:
- two adjacent dirs with an empty conf/: KeyError before; after, both
  get the "ignoring" line and the real layer is tested
- two adjacent BSP+DISTRO dirs only: exit 0 before, exit 1 after
- valid layer + one stray conf/ dir: same test results before/after
- --dependency, valid layer depending on a BSP+DISTRO one: before, the
  BSP+DISTRO layer was added to BBLAYERS for the test; after, the valid
  layer is skipped for the missing dependency, same as without
  --dependency

Applies to master-next too, not tested there.

 scripts/yocto-check-layer | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/scripts/yocto-check-layer b/scripts/yocto-check-layer
index 8c8b4db..607b03b 100755
--- a/scripts/yocto-check-layer
+++ b/scripts/yocto-check-layer
@@ -48,6 +48,22 @@  def dump_layer_debug(layer):
     if collections:
         logger.debug("%s collections: %s" % (layer["name"], ", ".join(collections)))
 
+def validate_layers(layers):
+    valid_layers = []
+    for layer in layers:
+        if layer['type'] == LayerType.ERROR_BSP_DISTRO:
+            logger.error("%s: Can't be DISTRO and BSP type at the same time."\
+                     " Both conf/distro and conf/machine folders were found."\
+                     % layer['name'])
+        elif layer['type'] == LayerType.ERROR_NO_LAYER_CONF:
+            logger.info("%s: Doesn't have conf/layer.conf file, so ignoring"\
+                     % layer['name'])
+        else:
+            logger.info("%s: %s, %s" % (layer['name'], layer['type'],
+                layer['path']))
+            valid_layers.append(layer)
+    return valid_layers
+
 def main():
     parser = argparse.ArgumentParser(
             description="Yocto Project layer checking tool",
@@ -103,6 +119,12 @@  def main():
     if not layers:
         logger.error("Failed to detect layers")
         return 1
+
+    logger.info("Detected layers:")
+    layers = validate_layers(layers)
+    if not layers:
+        return 1
+
     if args.additional_layers:
         additional_layers = detect_layers(args.additional_layers, args.no_auto)
     else:
@@ -124,23 +146,6 @@  def main():
         logger.error("Failed layer validation")
         return 1
 
-    logger.info("Detected layers:")
-    for layer in layers:
-        if layer['type'] == LayerType.ERROR_BSP_DISTRO:
-            logger.error("%s: Can't be DISTRO and BSP type at the same time."\
-                     " Both conf/distro and conf/machine folders were found."\
-                     % layer['name'])
-            layers.remove(layer)
-        elif layer['type'] == LayerType.ERROR_NO_LAYER_CONF:
-            logger.info("%s: Doesn't have conf/layer.conf file, so ignoring"\
-                     % layer['name'])
-            layers.remove(layer)
-        else:
-            logger.info("%s: %s, %s" % (layer['name'], layer['type'],
-                layer['path']))
-    if not layers:
-        return 1
-
     # Find all dependencies, and get them checked too
     if not args.no_auto_dependency:
         depends = []