From e3bfd4151f6199ab03c6090e85a4f0e36cdbede0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 30 Jul 2021 13:28:00 +0200 Subject: [PATCH] mkosi: refactor creation of FIRMWARE_LOCATIONS lists It's nicer to make it more "declarative" by creating the lists directly, instead of appending items one by one. The newline is dropped from the error message: it's generally nicer to make error messages one line. On a terminal, output will get wrapped anyway. Blame black, not me, for the ugly list formatting. --- mkosi/__init__.py | 62 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index c04710c5f..4c30d1cc9 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -6742,46 +6742,44 @@ def find_qemu_binary() -> str: def find_qemu_firmware() -> Tuple[str, bool]: - # UEFI firmware blobs are found in a variety of locations, - # depending on distribution and package. - FIRMWARE_LOCATIONS = [] - - if platform.machine() == "x86_64": - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/x64/OVMF_CODE.secboot.fd") - elif platform.machine() == "i386": - FIRMWARE_LOCATIONS.append("/usr/share/edk2/ovmf-ia32/OVMF_CODE.secboot.fd") - - FIRMWARE_LOCATIONS.append("/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd") - FIRMWARE_LOCATIONS.append("/usr/share/qemu/OVMF_CODE.secboot.fd") - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/OVMF.secboot.fd") + FIRMWARE_LOCATIONS = [ + # UEFI firmware blobs are found in a variety of locations, + # depending on distribution and package. + *{ + "x86_64": ["/usr/share/ovmf/x64/OVMF_CODE.secboot.fd"], + "i386": ["/usr/share/edk2/ovmf-ia32/OVMF_CODE.secboot.fd"], + }.get(platform.machine(), []), + "/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd", + "/usr/share/qemu/OVMF_CODE.secboot.fd", + "/usr/share/ovmf/OVMF.secboot.fd", + ] for firmware in FIRMWARE_LOCATIONS: if os.path.exists(firmware): return firmware, True warn( - """\ - Couldn't find OVMF firmware blob with secure boot support, - falling back to OVMF firmware blobs without secure boot support. - """ + "Couldn't find OVMF firmware blob with secure boot support, " + "falling back to OVMF firmware blobs without secure boot support." ) - FIRMWARE_LOCATIONS = [] - - # First, we look in paths that contain the architecture – - # if they exist, they’re almost certainly correct. - if platform.machine() == "x86_64": - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/ovmf_code_x64.bin") - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/x64/OVMF_CODE.fd") - FIRMWARE_LOCATIONS.append("/usr/share/qemu/ovmf-x86_64.bin") - elif platform.machine() == "i386": - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/ovmf_code_ia32.bin") - FIRMWARE_LOCATIONS.append("/usr/share/edk2/ovmf-ia32/OVMF_CODE.fd") - # After that, we try some generic paths and hope that if they exist, - # they’ll correspond to the current architecture, thanks to the package manager. - FIRMWARE_LOCATIONS.append("/usr/share/edk2/ovmf/OVMF_CODE.fd") - FIRMWARE_LOCATIONS.append("/usr/share/qemu/OVMF_CODE.fd") - FIRMWARE_LOCATIONS.append("/usr/share/ovmf/OVMF.fd") + FIRMWARE_LOCATIONS = [ + # First, we look in paths that contain the architecture – + # if they exist, they’re almost certainly correct. + *{ + "x86_64": [ + "/usr/share/ovmf/ovmf_code_x64.bin", + "/usr/share/ovmf/x64/OVMF_CODE.fd", + "/usr/share/qemu/ovmf-x86_64.bin", + ], + "i386": ["/usr/share/ovmf/ovmf_code_ia32.bin", "/usr/share/edk2/ovmf-ia32/OVMF_CODE.fd"], + }.get(platform.machine(), []), + # After that, we try some generic paths and hope that if they exist, + # they’ll correspond to the current architecture, thanks to the package manager. + "/usr/share/edk2/ovmf/OVMF_CODE.fd", + "/usr/share/qemu/OVMF_CODE.fd", + "/usr/share/ovmf/OVMF.fd", + ] for firmware in FIRMWARE_LOCATIONS: if os.path.exists(firmware): -- 2.47.2