]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only run configure scripts for verbs that need a build 2698/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 10 May 2024 09:27:50 +0000 (11:27 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 10 May 2024 10:04:52 +0000 (12:04 +0200)
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
mkosi/resources/mkosi.md

index 37c0598233f154bd9540f84db4103c7a06d1f2b5..8f4e75372bd97dd0263b70dd6374fea7ca51f152 100644 (file)
@@ -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
 
index ebb2cfc02eb88fa9ed2682c25dadbf83e84816a3..db34c64854915e79f216a4b3d5b75d8a698ea34f 100644 (file)
@@ -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