]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make Linux= support delayed specifiers 3509/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 14 Feb 2025 12:39:48 +0000 (13:39 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 14 Feb 2025 14:03:05 +0000 (15:03 +0100)
In mkosi-kernel, I want to add the following:

```
Linux=&b/kernel/arch/x86_64/boot/bzImage
```

So that I can run `mkosi -t none` to rebuild the kernel image and
`mkosi qemu` to boot into it. To make this work, let's add support
for a delayed specifier to Linux= that expands to the finalized
build directory.

mkosi/config.py
mkosi/qemu.py
mkosi/resources/man/mkosi.1.md
mkosi/vmspawn.py

index 21675e6431ca1571a4b4a20b7911d352edd51505..040f8676ef650ececc0cc152bc1a2867e0e1275a 100644 (file)
@@ -1986,7 +1986,7 @@ class Config:
     removable: bool
     firmware: Firmware
     firmware_variables: Optional[Path]
-    linux: Optional[Path]
+    linux: Optional[str]
     drives: list[Drive]
     qemu_args: list[str]
 
@@ -2208,6 +2208,16 @@ class Config:
 
         return expand_delayed_specifiers(specifiers, key)
 
+    def expand_linux_specifiers(self) -> Path:
+        assert self.linux
+
+        specifiers = {
+            "&": "&",
+            "b": os.fspath(self.build_subdir) if self.build_dir else "",
+        }
+
+        return parse_path(expand_delayed_specifiers(specifiers, self.linux))
+
     def to_dict(self) -> dict[str, Any]:
         d = dataclasses.asdict(self, dict_factory=dict_with_capitalised_keys_factory)
 
@@ -3894,7 +3904,7 @@ SETTINGS: list[ConfigSetting[Any]] = [
         dest="linux",
         metavar="PATH",
         section="Runtime",
-        parse=config_make_path_parser(),
+        parse=config_parse_string,
         help="Specify the kernel to use for direct kernel boot",
         compat_longs=("--qemu-kernel",),
         compat_names=("QemuKernel",),
index 0fedb9a9898d2d2fd7568c5cd2ad01f01e07493b..67fcdd29b667d33392c991f52302fd8c657c90da 100644 (file)
@@ -1156,7 +1156,7 @@ def run_qemu(args: Args, config: Config) -> None:
         die(f"Console mode {config.console} requested but systemd-pty-forward not found")
 
     if config.linux:
-        kernel = config.linux
+        kernel = config.expand_linux_specifiers()
     elif "-kernel" in args.cmdline:
         kernel = Path(args.cmdline[args.cmdline.index("-kernel") + 1])
     else:
index d1363bf5e86f55edc53c1fe7c1c44c6a502fe4da..d1afa882bdbd9e7f930df4dc8f39fd004d656bc3 100644 (file)
@@ -1729,7 +1729,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 `Linux=`, `--linux=`
 :   Set the kernel image to use for **qemu** direct kernel boot. If not
     specified, **mkosi** will use the kernel provided via the command line
-    (`-kernel` option) or latest the kernel that was installed into
+    (`-kernel` option) or the latest kernel that was installed into
     the image (or fail if no kernel was installed into the image).
 
     Note that when the `cpio` output format is used, direct kernel boot is
@@ -1737,6 +1737,18 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     configured firmware, **qemu** might boot the kernel itself or using the
     configured firmware.
 
+    This setting may include both the regular specifiers (see
+    **Specifiers**) and special delayed specifiers, that are expanded
+    after config parsing has finished, instead of during config parsing,
+    which are described below.
+
+    The following specifiers may be used:
+
+    | Specifier | Value                                              |
+    |-----------|----------------------------------------------------|
+    | `&&`      | `&` character                                      |
+    | `&b`      | The final build directory (including subdirectory) |
+
 `Drives=`, `--drive=`
 :   Add a drive. Takes a colon-delimited string of format
     `<id>:<size>[:<directory>[:<options>[:<file-id>]]]`. `id` specifies
index a96ff2b0347adca0d2763abb964e4a638823e9c2..dd56232563fce2c598c4e137838e17197cdcf328 100644 (file)
@@ -39,7 +39,7 @@ def run_vmspawn(args: Args, config: Config) -> None:
     if config.firmware_variables and config.firmware_variables != Path("microsoft"):
         die("mkosi vmspawn does not support FirmwareVariables=")
 
-    kernel = config.linux
+    kernel = config.expand_linux_specifiers() if config.linux else None
     firmware = finalize_firmware(config, kernel)
 
     if not kernel and firmware == Firmware.linux: