From: Joerg Behrmann Date: Mon, 24 Apr 2023 15:41:43 +0000 (+0200) Subject: config: Add Match on ImageId X-Git-Tag: v15~200^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18b5fb7e98e527f3bd8c4107a91b63992dad3432;p=thirdparty%2Fmkosi.git config: Add Match on ImageId --- diff --git a/mkosi.md b/mkosi.md index 0d0de76cb..971d644c2 100644 --- 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` diff --git a/mkosi/config.py b/mkosi/config.py index 187ed2094..107665288 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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( diff --git a/tests/test_parse_load_args.py b/tests/test_parse_load_args.py index 9c680022f..128a290bb 100644 --- a/tests/test_parse_load_args.py +++ b/tests/test_parse_load_args.py @@ -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