]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add %I specifier for subimages
authorMichael Ferrari <nekkodroid404@gmail.com>
Mon, 11 Nov 2024 12:30:57 +0000 (13:30 +0100)
committerMichael Ferrari <nekkodroid404@gmail.com>
Tue, 12 Nov 2024 12:22:51 +0000 (13:22 +0100)
This expands to the name of the subimage (and an empty string for the
main image) and is the same value that is used for Dependencies=.

Fixes: #2566
mkosi/config.py
mkosi/resources/man/mkosi.1.md
mkosi/resources/man/mkosi.news.7.md
tests/test_config.py

index 8653bf9a0b0da8afe5ddca044509cbef3fad7b72..a3504ae33b99b0fdc90531a2e8cf7e77f872da78 100644 (file)
@@ -3595,6 +3595,10 @@ SPECIFIERS = (
         callback=lambda ns, config: ns.distribution.filesystem(),
         depends=("distribution",),
     ),
+    Specifier(
+        char="I",
+        callback=lambda ns, config: ns.image or "",
+    ),
 )
 
 SPECIFIERS_LOOKUP_BY_CHAR = {s.char: s for s in SPECIFIERS}
index 9625ed22eed73d38f44ee80b21fc9e707f47340c..16f6dca2f9aa292308c7fffff4b73b12ea2ae29b 100644 (file)
@@ -2031,11 +2031,12 @@ use `%%`. The following specifiers are understood:
 
 There are also specifiers that are independent of settings:
 
-| Specifier | Value                                   |
-|-----------|-----------------------------------------|
-| `%C`      | Parent directory of current config file |
-| `%P`      | Current working directory               |
-| `%D`      | Directory that mkosi was invoked in     |
+| Specifier | Value                                          |
+|-----------|------------------------------------------------|
+| `%C`      | Parent directory of current config file        |
+| `%P`      | Current working directory                      |
+| `%D`      | Directory that mkosi was invoked in            |
+| `%I`      | Name of the current subimage in `mkosi.images` |
 
 Finally, there are specifiers that are derived from a setting:
 
index 20076a162e544deadac946eafb722daeefc8c523..5f55dc45efcee63e90996e2e70db7358e98648a1 100644 (file)
   (qemu, nspawn, ...), we now keep $PATH entries inside the user's home
   intact. Note that this may cause issues if a PATH entry in your home contains
   binaries linked against libraries in `/usr` from the host.
+- Introduced new specifier `%I` which resolves to the name of the current
+  subimage when used in a config under `mkosi.images/`. This differs to `%o`
+  as it is always the name of the config file without extension (or the name
+  of the directory).
 
 ## v24
 
index dd1dcd990889c1157f0349439706668c378ab31d..13765dcedeecdcaaba74966db794d7dada8f0f07 100644 (file)
@@ -1104,6 +1104,7 @@ def test_specifiers(tmp_path: Path) -> None:
         Environment=Distribution=%d
                     Release=%r
                     Architecture=%a
+                    Image=%I
                     ImageId=%i
                     ImageVersion=%v
                     OutputDirectory=%O
@@ -1134,13 +1135,22 @@ def test_specifiers(tmp_path: Path) -> None:
         """
     )
 
+    (d / "mkosi.images").mkdir()
+    (d / "mkosi.images/subimage.conf").write_text(
+        """
+        [Build]
+        Environment=Image=%I
+        """
+    )
+
     with chdir(d):
-        _, [config] = parse_config()
+        _, [subimage, config] = parse_config()
 
         expected = {
             "Distribution": "ubuntu",
             "Release": "lunar",
             "Architecture": "arm64",
+            "Image": "",
             "ImageId": "my-image-id",
             "ImageVersion": "1.2.3",
             "OutputDirectory": str(Path.cwd() / "abcde"),
@@ -1159,6 +1169,8 @@ def test_specifiers(tmp_path: Path) -> None:
 
         assert {k: v for k, v in config.environment.items() if k in expected} == expected
 
+        assert subimage.environment["Image"] == "subimage"
+
 
 def test_kernel_specifiers(tmp_path: Path) -> None:
     kver = "13.0.8-5.10.0-1057-oem"  # taken from reporter of #1638