]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
config: Add Match on ImageId
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 24 Apr 2023 15:41:43 +0000 (17:41 +0200)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 24 Apr 2023 20:41:57 +0000 (22:41 +0200)
mkosi.md
mkosi/config.py
tests/test_parse_load_args.py

index 0d0de76cbb14a0b722fb57687d0d8de744a41191..971d644c29a36ec71f3ac307923f86fe4d44fd51 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -234,6 +234,14 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
   interpreted relative to the parent directory of the config file that the
   condition is read from.
 
+`ImageId=`
+
+: Matches against the configured image ID. If this condition is used and no
+  image ID has been explicitly configured yet, this condition fails. Multiple
+  image IDs may be specified, separated by spaces. If multiple image IDs are
+  specified, the condition is satisfied if the configured image ID equals any of
+  the specified image IDs.
+
 ### [Distribution] Section
 
 `Distribution=`, `--distribution=`, `-d`
index 187ed2094a54bbc64278b4b662fe189c77ee0c92..107665288c58b43164d3dc9a77589c3427b7b90c 100644 (file)
@@ -244,6 +244,7 @@ def config_make_list_parser(delimiter: str, unescape: bool = False, parse: Calla
 
 def config_make_list_matcher(
     delimiter: str,
+    *,
     unescape: bool = False,
     all: bool = False,
     parse: Callable[[str], Any] = str,
@@ -522,6 +523,7 @@ class MkosiConfigParser:
         ),
         MkosiConfigSetting(
             dest="image_id",
+            match=config_make_list_matcher(delimiter=" "),
             section="Output",
         ),
         MkosiConfigSetting(
index 9c680022f7ec63d4583d2ae9fee9a208df7dee0c..128a290bbfe562c953d4b509f82a953a3d476c63 100644 (file)
@@ -211,3 +211,67 @@ def test_match_release(release1: int, release2: int) -> None:
         if release1 == release2:
             assert "testpkg2" in conf.packages
         assert "testpkg3" in conf.packages
+
+
+@pytest.mark.parametrize(
+    "image1,image2", itertools.combinations_with_replacement(
+        ["image_a", "image_b", "image_c"], 2
+    )
+)
+def test_match_imageid(image1: str, image2: str) -> None:
+    with cd_temp_dir():
+        parent = Path("mkosi.conf")
+        parent.write_text(
+            dedent(
+                f"""\
+                [Distribution]
+                Distribution=fedora
+                ImageId={image1}
+                """
+            )
+        )
+
+        Path("mkosi.conf.d").mkdir()
+
+        child1 = Path("mkosi.conf.d/child1.conf")
+        child1.write_text(
+            dedent(
+                f"""\
+                [Match]
+                ImageId={image1}
+
+                [Content]
+                Packages=testpkg1
+                """
+            )
+        )
+        child2 = Path("mkosi.conf.d/child2.conf")
+        child2.write_text(
+            dedent(
+                f"""\
+                [Match]
+                ImageId={image2}
+
+                [Content]
+                Packages=testpkg2
+                """
+            )
+        )
+        child3 = Path("mkosi.conf.d/child3.conf")
+        child3.write_text(
+            dedent(
+                f"""\
+                [Match]
+                ImageId={image1} {image2}
+
+                [Content]
+                Packages=testpkg3
+                """
+            )
+        )
+
+        conf = parse([])
+        assert "testpkg1" in conf.packages
+        if image1 == image2:
+            assert "testpkg2" in conf.packages
+        assert "testpkg3" in conf.packages