From 8b899ff19eced45ef2ac03818c334e1d698c40d3 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 10 May 2024 11:27:50 +0200 Subject: [PATCH] Only run configure scripts for verbs that need a build In systemd, we want to use configure scripts to determine whether qemu was built with support for specific devices and skip running a test if it wasn't, or otherwise add the device to the qemu arguments. To make this work, we need to run the configure scripts with the default tools tree available if one is configured. Let's change the behavior of configure scripts to only run for verbs that need a build and run them after building the default tools tree so that they can be run with the tools tree mounted. --- mkosi/__init__.py | 18 ++++++++++-------- mkosi/resources/mkosi.md | 14 +++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 37c059823..8f4e75372 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -462,7 +462,6 @@ def run_configure_scripts(config: Config) -> Config: env=env | config.environment, sandbox=config.sandbox( binary=None, - tools=False, mounts=[*sources, Mount(script, "/work/configure", ro=True)], options=["--dir", "/work/src", "--chdir", "/work/src"] ), @@ -4498,9 +4497,6 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: die("No configuration found", hint="Make sure you're running mkosi from a directory with configuration files") - for i, config in enumerate(images): - images[i] = run_configure_scripts(config) - if args.verb == Verb.summary: if args.json: text = json.dumps( @@ -4559,6 +4555,14 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: check_workspace_directory(config) + if tools and not (tools.output_dir_or_cwd() / tools.output).exists(): + if args.verb == Verb.build or args.force > 0: + fork_and_wait(run_sync, args, tools, resources=resources) + fork_and_wait(run_build, args, tools, resources=resources) + else: + die(f"Default tools tree requested for image '{last.name()}' but it has not been built yet", + hint="Make sure to build the image first with 'mkosi build' or use '--force'") + build = False for i, config in enumerate(images): @@ -4571,13 +4575,11 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: ) ) + images[i] = config = run_configure_scripts(config) + if args.verb != Verb.build and args.force == 0: continue - if tools and not (tools.output_dir_or_cwd() / tools.output).exists(): - fork_and_wait(run_sync, args, tools, resources=resources) - fork_and_wait(run_build, args, tools, resources=resources) - if (config.output_dir_or_cwd() / config.output_with_compression).exists(): continue diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index ebb2cfc02..db34c6485 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -2102,11 +2102,15 @@ in the current working directory. `$SRCDIR` is set to point to the current working directory. The following scripts are supported: * If **`mkosi.configure`** (`ConfigureScripts=`) exists, it is executed - after parsing the configuration files. This script may be used to - dynamically modify the configuration. It receives the configuration - serialized as JSON on stdin and should output the modified - configuration serialized as JSON on stdout. Note that this script does - not use the tools tree even if one is configured. + before building the image. This script may be used to dynamically + modify the configuration. It receives the configuration serialized as + JSON on stdin and should output the modified configuration serialized + as JSON on stdout. Note that this script only runs when building or + booting the image (`build`, `qemu`, `boot` and `shell` verbs). If a + default tools tree is configured, it will be built before running the + configure scripts and the configure scripts will run with the tools + tree available. This also means that the modifications made by + configure scripts will not be visible in the `summary` output. * If **`mkosi.sync`** (`SyncScripts=`) exists, it is executed before the image is built. This script may be used to update various sources that -- 2.47.2