From b9ed16435cf8dc80d703c311d2d5ee2de71534a9 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 5 May 2022 11:23:29 +0200 Subject: [PATCH] Add nspawn version check to check_native() From systemd-nspawn v250 onwards, it's possible to run build scripts on non-native architectures (as long as binfmt.d is configured correctly) so update the native check to consider that. --- mkosi/__init__.py | 3 ++- mkosi/backend.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 3cbfa177c..c3abea729 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -85,6 +85,7 @@ from .backend import ( nspawn_executable, nspawn_params_for_blockdev_access, nspawn_rlimit_params, + nspawn_version, patch_file, path_relative_to_cwd, run, @@ -7471,7 +7472,7 @@ def check_root() -> None: def check_native(args: MkosiArgs) -> None: - if args.architecture is not None and args.architecture != platform.machine() and args.build_script: + if args.architecture is not None and args.architecture != platform.machine() and args.build_script and nspawn_version() < 250: die("Cannot (currently) override the architecture and run build commands") diff --git a/mkosi/backend.py b/mkosi/backend.py index 384494db6..2f35b065d 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -631,6 +631,10 @@ def nspawn_executable() -> str: return os.getenv("MKOSI_NSPAWN_EXECUTABLE", "systemd-nspawn") +def nspawn_version() -> int: + return int(run([nspawn_executable(), "--version"], stdout=subprocess.PIPE).stdout.strip().split()[1]) + + def run_workspace_command( args: MkosiArgs, root: Path, -- 2.47.2