From 9dabce43d2307578f620fe45b497d4c415cb3fc6 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 22 Mar 2024 20:17:03 +0100 Subject: [PATCH] scripts: Ignore duplicate roots in list_boards/hardware When iterating over `--arch-root`, `--board-root`, and `--soc-root`, treat them as collections of absolute paths with no repeats, to ensure that no input root has to be handled more than once. Signed-off-by: Grzegorz Swiderski --- scripts/list_boards.py | 7 ++++--- scripts/list_hardware.py | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/list_boards.py b/scripts/list_boards.py index 5321f31b0bc..597ecf91809 100755 --- a/scripts/list_boards.py +++ b/scripts/list_boards.py @@ -13,6 +13,7 @@ import sys from typing import List import yaml import list_hardware +from list_hardware import unique_paths BOARD_SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'board-schema.yml') with open(BOARD_SCHEMA_PATH, 'r') as f: @@ -116,7 +117,7 @@ def find_arch2board_set(args): arches = sorted(find_arches(args)) ret = defaultdict(set) - for root in args.board_roots: + for root in unique_paths(args.board_roots): for arch, boards in find_arch2board_set_in(root, arches, args.board_dir).items(): if args.board is not None: ret[arch] |= {b for b in boards if b.name == args.board} @@ -129,7 +130,7 @@ def find_arch2board_set(args): def find_arches(args): arch_set = set() - for root in args.arch_roots: + for root in unique_paths(args.arch_roots): arch_set |= find_arches_in(root) return arch_set @@ -236,7 +237,7 @@ def find_v2_boards(args): boards = [] board_files = [] - for root in args.board_roots: + for root in unique_paths(args.board_roots): board_files.extend((root / 'boards').rglob(BOARD_YML)) for board_yml in board_files: diff --git a/scripts/list_hardware.py b/scripts/list_hardware.py index e17ff7b4532..2fa7c2a3638 100755 --- a/scripts/list_hardware.py +++ b/scripts/list_hardware.py @@ -141,9 +141,14 @@ class Family: socs: List[Soc] +def unique_paths(paths): + # Using dict keys ensures both uniqueness and a deterministic order. + yield from dict.fromkeys(map(Path.resolve, paths)).keys() + + def find_v2_archs(args): ret = {'archs': []} - for root in args.arch_roots: + for root in unique_paths(args.arch_roots): archs_yml = root / ARCHS_YML_PATH if Path(archs_yml).is_file(): @@ -172,7 +177,7 @@ def find_v2_archs(args): def find_v2_systems(args): yml_files = [] systems = Systems() - for root in args.soc_roots: + for root in unique_paths(args.soc_roots): yml_files.extend(sorted((root / 'soc').rglob(SOC_YML))) for soc_yml in yml_files: