|
15 | 15 | import multiprocessing |
16 | 16 | import os |
17 | 17 | import re |
| 18 | +import shlex |
18 | 19 | import subprocess |
19 | 20 | from pathlib import Path |
20 | 21 |
|
@@ -350,6 +351,47 @@ def armbian_get_all_userspace_inventory(): |
350 | 351 | return all_distros |
351 | 352 |
|
352 | 353 |
|
| 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 | + |
353 | 395 | def armbian_get_all_boards_inventory(): |
354 | 396 | armbian_paths = find_armbian_src_path() |
355 | 397 | core_boards = armbian_get_all_boards_list(armbian_paths["core_boards_path"]) |
@@ -379,6 +421,27 @@ def armbian_get_all_boards_inventory(): |
379 | 421 | log.debug(f"Userpatched Board {uboard_name} is already in core boards") |
380 | 422 | info_for_board[uboard_name] = {**info_for_board[uboard_name], **uboard} |
381 | 423 |
|
| 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 | + |
382 | 445 | return info_for_board |
383 | 446 |
|
384 | 447 |
|
|
0 commit comments