@@ -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",
@@ -125,19 +141,10 @@ def main():
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']))
+ layers = validate_layers(layers)
+ # Keep dep_layers in sync when it previously shared the layers list.
+ if not args.dependency:
+ dep_layers = layers
if not layers:
return 1
The "Detected layers" loop removes invalid entries from the list it's iterating over. When two invalid layers are adjacent, removing the first skips the second, leaving it in the list. A skipped entry without conf/layer.conf makes the dependency pass fail with KeyError: 'collections'. A skipped BSP+DISTRO entry isn't reported. If no other layer is left to test, the script exits 0. Move the filtering into validate_layers(), which builds a new list containing only valid layers. Keep validation at its original position and update dep_layers when it previously shared the same list, without changing the existing dependency handling. Signed-off-by: Vinicius Pedrosa <vinicius.eduardo.pedrosa@gmail.com> --- Changes in v3: Paul was right that v2 combined two separate changes. I should have kept the dependency-handling change separate from the original bug fix. This version keeps only the fix, with validation at its original position, preserving the existing dependency handling and duplicate collection checks. Tested on master (b62d5e6) with two adjacent directories containing only an empty conf/. Before the fix, the script raises KeyError; afterwards, both directories are ignored and the valid layer is tested. Regarding AI, I wrote the code myself and use AI to help with English and code review. I'm not sure whether that alone requires the AI-Generated tag, but I can add it if needed. scripts/yocto-check-layer | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)