From: Michael Ferrari Date: Mon, 11 Nov 2024 12:30:57 +0000 (+0100) Subject: Add %I specifier for subimages X-Git-Tag: v25~178^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f0cd1cc4cfa219df4493f21cf6f0b311e54d1e2;p=thirdparty%2Fmkosi.git Add %I specifier for subimages 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 --- diff --git a/mkosi/config.py b/mkosi/config.py index 8653bf9a0..a3504ae33 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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} diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 9625ed22e..16f6dca2f 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -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: diff --git a/mkosi/resources/man/mkosi.news.7.md b/mkosi/resources/man/mkosi.news.7.md index 20076a162..5f55dc45e 100644 --- a/mkosi/resources/man/mkosi.news.7.md +++ b/mkosi/resources/man/mkosi.news.7.md @@ -86,6 +86,10 @@ (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 diff --git a/tests/test_config.py b/tests/test_config.py index dd1dcd990..13765dced 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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