Skip to content

Commit 857db91

Browse files
committed
targets: add skip-arches / only-arches filters to items-from-inventory
Lets targets.yaml scope board-based inventory items by ARCH: items-from-inventory: not-eos-with-video: skip-arches: [loong64, riscv64] # or only-arches: [arm64] Stops the compositor from emitting combinations that compile.sh will just reject downstream as 'target not supported' (e.g. noble + uefi-loong64, because noble doesn't declare loong64 in its architectures list). Cuts log noise and runner minutes. Resolution of the board's ARCH: - armbian_utils.armbian_parse_board_file_for_static_info already picks up any ARCH='…' line it finds in the board conf via the generic top-level var regex. - armbian_get_all_boards_inventory now falls back to the board's BOARDFAMILY family conf (config/sources/families/<fam>.conf) for boards that don't carry an explicit ARCH. The family conf is bash-sourced in a throwaway subshell with an EXIT trap so ARCH is captured even when the family conf aborts mid-source on a ${FOO:?required} check (ls1046a, etc). - Family-file results are cached per family. - Five boards with unresolvable ARCH under the fallback get an explicit ARCH="arm64" declaration: aml-t95z-plus.tvb (comment apostrophe breaks BOARDFAMILY regex) ayn-odin2mini.csc (sources ayn-odin2.csc — parser doesn't follow) ayn-odin2portal.csc (ditto) ayn-thor.csc (ditto) gateway-dk.conf (family conf aborts before subshell captures ARCH) All 367 boards now report ARCH; breakdown: arm64=272, armhf=76, riscv64=15, amd64=3, loong64=1. Smoke-tested with a targets.yaml carrying skip-arches: [loong64, riscv64] — compositor drops 17 entries cleanly, no leakage of filtered arches in final output. userspace inventory has its own internal arch filtering via the existing 'arches:' key and is not affected.
1 parent a10a815 commit 857db91

7 files changed

Lines changed: 108 additions & 2 deletions

File tree

config/boards/aml-t95z-plus.tvb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
BOARD_NAME="T95Z Plus" # (a q201 Chinese clone with internal amlogic ethernet 1gbit, complete with a chunk of metal inside to delay thermal throttling)
33
BOARD_VENDOR="amlogic"
44
BOOT_FDT_FILE="amlogic/meson-gxm-t95z-plus.dtb" # From chewitt's patches
5-
BOARDFAMILY="meson-gxl" # s912's are actually meson-gxm, no harm done.
5+
BOARDFAMILY="meson-gxl" # s912s are actually meson-gxm, no harm done.
6+
ARCH="arm64"
67
BOARD_VENDOR="generic"
78
BOOTCONFIG="meson-gxm-t95z-plus_defconfig" # patched-in
89
BOARD_MAINTAINER=""

config/boards/ayn-odin2mini.csc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Qualcomm SM8550 octa core 8GB/12GB/16GB RAM SoC eMMC USB-C WiFi/BT
22
source "${SRC}/config/boards/ayn-odin2.csc"
3+
declare -g ARCH="arm64"
34
declare -g BOARD_NAME="Ayn Odin2 Mini"
45
declare -g BOARD_VENDOR="ayntec"
56
declare -g BOARD_MAINTAINER="Squishy123"

config/boards/ayn-odin2portal.csc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Qualcomm SM8550 octa core 8GB/12GB/16GB RAM SoC eMMC USB-C WiFi/BT
22
source "${SRC}/config/boards/ayn-odin2.csc"
3+
declare -g ARCH="arm64"
34
declare -g BOARD_NAME="Ayn Odin2 Portal"
45
declare -g BOARD_VENDOR="ayntec"
56
declare -g BOARD_MAINTAINER="Squishy123"

config/boards/ayn-thor.csc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Qualcomm SM8550 octa core 8GB/12GB/16GB RAM SoC eMMC USB-C WiFi/BT
22
source "${SRC}/config/boards/ayn-odin2.csc"
3+
declare -g ARCH="arm64"
34
declare -g BOARD_NAME="Ayn Thor"
45
declare -g BOARD_VENDOR="ayntec"
56
declare -g BOARD_MAINTAINER="Squishy123"

config/boards/gateway-dk.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BOARD_NAME="Mono Gateway Development Kit"
33
BOARD_VENDOR="mono"
44
BOARDFAMILY="ls1046a"
5+
ARCH="arm64"
56
BOARD_MAINTAINER="tomazzaman"
67
BOOTCONFIG="mono_gateway_dk_defconfig"
78
KERNEL_TARGET="current"

lib/tools/common/armbian_utils.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import multiprocessing
1616
import os
1717
import re
18+
import shlex
1819
import subprocess
1920
from pathlib import Path
2021

@@ -350,6 +351,47 @@ def armbian_get_all_userspace_inventory():
350351
return all_distros
351352

352353

354+
# ARCH is declared per-family in config/sources/families/<BOARDFAMILY>.conf —
355+
# but many families delegate to a shared include (e.g. meson-g12b.conf sources
356+
# meson64_common.inc which then sets ARCH=arm64). Rather than hand-write a
357+
# mini-bash to follow `source` directives, just bash-source the family file
358+
# in a throwaway subshell and print ARCH. Cache results per family — there
359+
# are ~60 unique families across ~370 boards.
360+
_family_arch_cache: dict = {}
361+
362+
363+
def armbian_get_arch_for_family(family_name, armbian_src_path):
364+
"""Return the ARCH declared by config/sources/families/<family>.conf
365+
(after resolving any `source` includes), or None if the file or the
366+
ARCH declaration is missing. Result is cached per family."""
367+
if not family_name:
368+
return None
369+
if family_name in _family_arch_cache:
370+
return _family_arch_cache[family_name]
371+
family_file = os.path.join(armbian_src_path, "config", "sources", "families", f"{family_name}.conf")
372+
arch = None
373+
if os.path.isfile(family_file):
374+
# Set ARCH via the EXIT trap so we still capture it even if the
375+
# family conf aborts mid-source via `${FOO:?error}` on a required
376+
# var that wouldn't be set in this minimal context (ls1046a, etc).
377+
bash_code = (
378+
"( trap 'printf \"%s\" \"${ARCH:-}\"; exit 0' EXIT; "
379+
"source " + shlex.quote(family_file) + " >/dev/null 2>&1 )"
380+
)
381+
try:
382+
proc = subprocess.run(
383+
["bash", "-c", bash_code],
384+
capture_output=True, text=True, timeout=5, check=False,
385+
)
386+
value = (proc.stdout or "").strip()
387+
if value and re.match(r"^[a-zA-Z0-9_]+$", value):
388+
arch = value
389+
except (subprocess.TimeoutExpired, OSError) as e:
390+
log.debug(f"Could not resolve ARCH for family '{family_name}': {e}")
391+
_family_arch_cache[family_name] = arch
392+
return arch
393+
394+
353395
def armbian_get_all_boards_inventory():
354396
armbian_paths = find_armbian_src_path()
355397
core_boards = armbian_get_all_boards_list(armbian_paths["core_boards_path"])
@@ -379,6 +421,27 @@ def armbian_get_all_boards_inventory():
379421
log.debug(f"Userpatched Board {uboard_name} is already in core boards")
380422
info_for_board[uboard_name] = {**info_for_board[uboard_name], **uboard}
381423

424+
# Resolve ARCH per-board. Prefer an explicit board-level ARCH
425+
# declaration (picked up by the generic board-file regex into
426+
# BOARD_TOP_LEVEL_VARS); fall back to the family conf so boards
427+
# that inherit their arch transitively (most of them) don't need
428+
# the redundant declaration. Targets compositors use this to drop
429+
# matrix invocations where board arch doesn't match the requested
430+
# release's arch list (e.g. noble without loong64) instead of
431+
# relying on compile.sh to reject the combo downstream.
432+
for board, info in info_for_board.items():
433+
top_vars = info.get("BOARD_TOP_LEVEL_VARS", {})
434+
arch = top_vars.get("ARCH")
435+
if not arch:
436+
family = top_vars.get("BOARDFAMILY")
437+
arch = armbian_get_arch_for_family(family, armbian_paths["armbian_src_path"])
438+
if arch:
439+
top_vars["ARCH"] = arch
440+
if arch:
441+
info["ARCH"] = arch
442+
else:
443+
log.warning(f"Could not resolve ARCH for board '{board}' (family '{top_vars.get('BOARDFAMILY')}')")
444+
382445
return info_for_board
383446

384447

lib/tools/info/targets-compositor.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ def get_userspace_inventory(opts: dict):
197197
if "items-from-inventory" in target_obj:
198198
# loop over the keys, for regular board vs branches inventory
199199
for key in target_obj["items-from-inventory"]:
200+
cfg = target_obj["items-from-inventory"][key]
200201
to_add = []
201202
if key == "userspace":
202-
to_add.extend(get_userspace_inventory(target_obj["items-from-inventory"][key]))
203+
to_add.extend(get_userspace_inventory(cfg))
203204
elif key == "all":
204205
to_add.extend(all_boards_all_branches)
205206
elif key == "not-eos":
@@ -208,6 +209,43 @@ def get_userspace_inventory(opts: dict):
208209
to_add.extend(not_eos_with_video_boards_all_branches)
209210
else:
210211
to_add.extend(boards_by_support_level_and_branches[key])
212+
213+
# For non-userspace inventory sources, honour optional
214+
# skip-arches / only-arches filters declared on the
215+
# inventory key. Example:
216+
# items-from-inventory:
217+
# not-eos-with-video:
218+
# skip-arches: [loong64, riscv64]
219+
# Drops board entries whose ARCH matches skip-arches, or
220+
# doesn't match only-arches. Board ARCH comes from the
221+
# board/family conf (see armbian_utils.armbian_get_all_boards_inventory).
222+
# userspace inventory has its own internal arch filtering
223+
# via the `arches:` key and is not touched here.
224+
if key != "userspace" and isinstance(cfg, dict):
225+
skip_arches = set(cfg.get("skip-arches") or [])
226+
only_arches_raw = cfg.get("only-arches")
227+
only_arches = set(only_arches_raw) if only_arches_raw else None
228+
if skip_arches or only_arches is not None:
229+
before = len(to_add)
230+
filtered = []
231+
for bb in to_add:
232+
board = bb.get("BOARD")
233+
arch = board_inventory.get(board, {}).get("ARCH")
234+
if arch is None:
235+
log.warning(f"Cannot resolve ARCH for board '{board}'; keeping it")
236+
filtered.append(bb)
237+
continue
238+
if only_arches is not None and arch not in only_arches:
239+
continue
240+
if arch in skip_arches:
241+
continue
242+
filtered.append(bb)
243+
to_add = filtered
244+
log.info(
245+
f"Arch filter on '{key}' (skip={sorted(skip_arches)}, "
246+
f"only={sorted(only_arches) if only_arches else None}): "
247+
f"{before}{len(to_add)}")
248+
211249
log.info(f"Adding '{key}' from inventory to target '{target_name}': {len(to_add)} targets")
212250
all_items.extend(to_add)
213251

0 commit comments

Comments
 (0)