]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add ImageId= and ImageVersion= specifiers
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Oct 2023 16:50:07 +0000 (18:50 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Oct 2023 18:37:48 +0000 (20:37 +0200)
Also rework the specifier tests a bit.

mkosi/config.py
mkosi/resources/mkosi.md
tests/test_config.py

index 663972687d0a8364d941163beb79011ffa616642..7f1c9de5c813019a4ad9fa086ce325a7b08251f3 100644 (file)
@@ -1204,6 +1204,7 @@ SETTINGS = (
         dest="image_version",
         match=config_match_version,
         section="Output",
+        specifier="v",
         help="Set version for image",
         paths=("mkosi.version",),
         path_read_text=True,
@@ -1212,6 +1213,7 @@ SETTINGS = (
         dest="image_id",
         match=config_make_string_matcher(allow_globs=True),
         section="Output",
+        specifier="i",
         help="Set ID for image",
     ),
     MkosiConfigSetting(
index 46e1a0e304025ba6d4acbac98b16cb619b4b7c48..e0025abc22bb79e035cdb851cab91ac3255590b8 100644 (file)
@@ -1269,6 +1269,8 @@ use `%%`. The following specifiers are understood:
 | `Format=`          | `%t`      |
 | `Output=`          | `%o`      |
 | `OutputDirectory=` | `%O`      |
+| `ImageId=`         | `%i`      |
+| `ImageVersion=`    | `%v`      |
 
 ## Supported distributions
 
index 159aca066b409afac5f9dbfbcc1423df49610dbf..e18dae7b398f04375f5e66f5a2433f2eb116aac3 100644 (file)
@@ -611,19 +611,33 @@ def test_specifiers(tmp_path: Path) -> None:
         Architecture=arm64
 
         [Output]
+        ImageId=my-image-id
+        ImageVersion=1.2.3
         OutputDirectory=abcde
         Output=test
 
-        [Distribution]
-        ImageId=%d~%r~%a
-
-        [Output]
-        CacheDirectory=%O/%o
+        [Content]
+        Environment=Distribution=%d
+                    Release=%r
+                    Architecture=%a
+                    ImageId=%i
+                    ImageVersion=%v
+                    OutputDirectory=%O
+                    Output=%o
         """
     )
 
     with chdir(d):
         _, [config] = parse_config()
-        assert config.distribution == Distribution.ubuntu
-        assert config.image_id == "ubuntu~lunar~arm64"
-        assert config.cache_dir == Path.cwd() / "abcde/test" / config.image_id
+
+        expected = {
+            "Distribution": "ubuntu",
+            "Release": "lunar",
+            "Architecture": "arm64",
+            "ImageId": "my-image-id",
+            "ImageVersion": "1.2.3",
+            "OutputDirectory": str(Path.cwd() / "abcde"),
+            "Output": "test",
+        }
+
+        assert {k: v for k, v in config.environment.items() if k in expected} == expected