]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Support matching against architectures with uefi support
authorDaanDeMeyer <daan.j.demeyer@gmail.com>
Sat, 5 Jul 2025 07:49:18 +0000 (09:49 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 5 Jul 2025 09:29:21 +0000 (10:29 +0100)
mkosi.conf.d/30-azure-centos-fedora/mkosi.conf.d/20-uefi.conf
mkosi/config.py
mkosi/resources/man/mkosi.1.md
mkosi/resources/mkosi-vm/mkosi.conf.d/azure-centos-fedora/mkosi.conf.d/uefi.conf
tests/test_config.py

index 061284455e570178092d5521cf1769c69d5782be..fbae092e4f1a85e256c5f18b84255646c29dbab3 100644 (file)
@@ -1,8 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
 [Match]
-Architecture=|x86-64
-Architecture=|arm64
+Architecture=uefi
 
 [Content]
 Packages=
index e7da3fde6836c095f1aeea9e4762c5e7a22a05e1..b30e94a0b561ea0f51646939fa2c4a00461cfe33 100644 (file)
@@ -479,10 +479,11 @@ class Architecture(StrEnum):
 
     def to_efi(self) -> Optional[str]:
         return {
-            Architecture.x86_64:      "x64",
             Architecture.x86:         "ia32",
-            Architecture.arm64:       "aa64",
+            Architecture.x86_64:      "x64",
             Architecture.arm:         "arm",
+            Architecture.arm64:       "aa64",
+            Architecture.riscv32:     "riscv32",
             Architecture.riscv64:     "riscv64",
             Architecture.loongarch64: "loongarch64",
         }.get(self)  # fmt: skip
@@ -1103,6 +1104,13 @@ def config_make_enum_matcher(type: type[SE]) -> ConfigMatchCallback[SE]:
     return config_match_enum
 
 
+def config_match_architecture(match: str, value: Architecture) -> bool:
+    if match == "uefi":
+        return value.to_efi() is not None
+
+    return config_make_enum_matcher(Architecture)(match, value)
+
+
 def package_sort_key(package: str) -> tuple[int, str]:
     """Sorts packages: normal first, paths second, conditional third"""
 
@@ -2632,7 +2640,7 @@ SETTINGS: list[ConfigSetting[Any]] = [
         section="Distribution",
         specifier="a",
         parse=config_make_enum_parser(Architecture),
-        match=config_make_enum_matcher(Architecture),
+        match=config_match_architecture,
         default=Architecture.native(),
         choices=Architecture.choices(),
         help="Override the architecture of installation",
index d7b4671d6de8e1fc6cc73578725a290aa602e31f..ca01b7cbda911cddc357a0dafc2d224dc1bf5392 100644 (file)
@@ -1985,6 +1985,8 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     and no architecture has been explicitly configured yet, the host
     architecture is used.
 
+:   `Architecture=uefi` can be used to match against any architecture that supports UEFI.
+
 `Repositories=`
 :   Matches against repositories enabled with the `Repositories=` setting.
     Takes a single repository name.
index da92e2ab43ba8ae8f728cfee0926e09ff0aaa6a9..9299df0ed9f24d81e25edf198d0141eaa0dd3806 100644 (file)
@@ -1,8 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
 [Match]
-Architecture=|x86-64
-Architecture=|arm64
+Architecture=uefi
 
 [Content]
 Packages=
index d9c537e08a0d7eec08943b6e5038e181764f5d9b..409d4e05034c056b511920895c4cab0a910320dd 100644 (file)
@@ -902,6 +902,25 @@ def test_match_repositories(tmp_path: Path) -> None:
     assert config.output == "qed"
 
 
+def test_match_architecture(tmp_path: Path) -> None:
+    d = tmp_path
+
+    (d / "mkosi.conf").write_text(
+        """\
+        [Match]
+        Architecture=uefi
+
+        [Content]
+        Output=qed
+        """
+    )
+
+    with chdir(d):
+        _, _, [config] = parse_config(["--architecture", "arm64"])
+
+    assert config.output == "qed"
+
+
 @pytest.mark.parametrize("image1,image2", itertools.combinations_with_replacement(["image_a", "image_b"], 2))
 def test_match_imageid(tmp_path: Path, image1: str, image2: str) -> None:
     with chdir(tmp_path):