From: DaanDeMeyer Date: Sat, 5 Jul 2025 07:49:18 +0000 (+0200) Subject: Support matching against architectures with uefi support X-Git-Tag: v26~188 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9131877d605086b315abcf6bfbeb3b6beb18cda5;p=thirdparty%2Fmkosi.git Support matching against architectures with uefi support --- diff --git a/mkosi.conf.d/30-azure-centos-fedora/mkosi.conf.d/20-uefi.conf b/mkosi.conf.d/30-azure-centos-fedora/mkosi.conf.d/20-uefi.conf index 061284455..fbae092e4 100644 --- a/mkosi.conf.d/30-azure-centos-fedora/mkosi.conf.d/20-uefi.conf +++ b/mkosi.conf.d/30-azure-centos-fedora/mkosi.conf.d/20-uefi.conf @@ -1,8 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -Architecture=|x86-64 -Architecture=|arm64 +Architecture=uefi [Content] Packages= diff --git a/mkosi/config.py b/mkosi/config.py index e7da3fde6..b30e94a0b 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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", diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index d7b4671d6..ca01b7cbd 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -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. diff --git a/mkosi/resources/mkosi-vm/mkosi.conf.d/azure-centos-fedora/mkosi.conf.d/uefi.conf b/mkosi/resources/mkosi-vm/mkosi.conf.d/azure-centos-fedora/mkosi.conf.d/uefi.conf index da92e2ab4..9299df0ed 100644 --- a/mkosi/resources/mkosi-vm/mkosi.conf.d/azure-centos-fedora/mkosi.conf.d/uefi.conf +++ b/mkosi/resources/mkosi-vm/mkosi.conf.d/azure-centos-fedora/mkosi.conf.d/uefi.conf @@ -1,8 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Match] -Architecture=|x86-64 -Architecture=|arm64 +Architecture=uefi [Content] Packages= diff --git a/tests/test_config.py b/tests/test_config.py index d9c537e08..409d4e050 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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):