mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
Meta/run.py: Use if/elif instead of match
Less code, less indentation, and works with Py3.9. (In return, the checked variable name is repeated in each conditional.)
This commit is contained in:
parent
b7dbdb4cd2
commit
a659d7a4c2
1 changed files with 112 additions and 118 deletions
46
Meta/run.py
46
Meta/run.py
|
@ -292,14 +292,13 @@ def determine_qemu_kind() -> QEMUKind:
|
|||
|
||||
|
||||
def determine_serenity_arch() -> Arch:
|
||||
match environ.get("SERENITY_ARCH"):
|
||||
case "aarch64":
|
||||
arch = environ.get("SERENITY_ARCH")
|
||||
if arch == "aarch64":
|
||||
return Arch.Aarch64
|
||||
case "riscv64":
|
||||
if arch == "riscv64":
|
||||
return Arch.RISCV64
|
||||
case "x86_64":
|
||||
if arch == "x86_64":
|
||||
return Arch.x86_64
|
||||
case _:
|
||||
raise RunError("Please specify a valid SerenityOS architecture")
|
||||
|
||||
|
||||
|
@ -327,12 +326,11 @@ def setup_qemu_binary(config: Configuration):
|
|||
if "SERENITY_QEMU_BIN" in environ:
|
||||
qemu_binary_basename = environ.get("SERENITY_QEMU_BIN")
|
||||
else:
|
||||
match config.architecture:
|
||||
case Arch.Aarch64:
|
||||
if config.architecture == Arch.Aarch64:
|
||||
qemu_binary_basename = "qemu-system-aarch64"
|
||||
case Arch.RISCV64:
|
||||
elif config.architecture == Arch.RISCV64:
|
||||
qemu_binary_basename = "qemu-system-riscv64"
|
||||
case Arch.x86_64:
|
||||
elif config.architecture == Arch.x86_64:
|
||||
qemu_binary_basename = "qemu-system-x86_64"
|
||||
if qemu_binary_basename is None:
|
||||
raise RunError("QEMU binary could not be determined")
|
||||
|
@ -532,12 +530,11 @@ def setup_audio_backend(config: Configuration):
|
|||
|
||||
def setup_audio_hardware(config: Configuration):
|
||||
provided_audio_hardware = environ.get("SERENITY_AUDIO_HARDWARE", "intelhda")
|
||||
match provided_audio_hardware:
|
||||
case "ac97":
|
||||
if provided_audio_hardware == "ac97":
|
||||
config.audio_devices = ["ac97,audiodev=snd0"]
|
||||
case "intelhda":
|
||||
elif provided_audio_hardware == "intelhda":
|
||||
config.audio_devices = ["ich9-intel-hda", "hda-output,audiodev=snd0"]
|
||||
case _:
|
||||
else:
|
||||
raise RunError(f"Unknown audio hardware {provided_audio_hardware}. Supported values: ac97, intelhda")
|
||||
|
||||
if config.machine_type.supports_pc_speaker() and config.architecture == Arch.x86_64:
|
||||
|
@ -690,12 +687,11 @@ hostfwd=tcp:{config.host_ip}:2222-10.0.2.15:22"
|
|||
|
||||
|
||||
def setup_kernel(config: Configuration):
|
||||
match config.architecture:
|
||||
case Arch.Aarch64:
|
||||
if config.architecture == Arch.Aarch64:
|
||||
config.kernel_and_initrd_arguments = ["-kernel", "Kernel/Kernel"]
|
||||
case Arch.RISCV64:
|
||||
elif config.architecture == Arch.RISCV64:
|
||||
config.kernel_and_initrd_arguments = ["-kernel", "Kernel/Kernel.bin"]
|
||||
case Arch.x86_64:
|
||||
elif config.architecture == Arch.x86_64:
|
||||
config.kernel_and_initrd_arguments = ["-kernel", "Kernel/Prekernel/Prekernel", "-initrd", "Kernel/Kernel"]
|
||||
|
||||
|
||||
|
@ -733,8 +729,7 @@ def setup_machine_devices(config: Configuration):
|
|||
return
|
||||
|
||||
# Machine specific base setups
|
||||
match config.machine_type:
|
||||
case MachineType.QEMU35Grub | MachineType.QEMU35:
|
||||
if config.machine_type in [MachineType.QEMU35Grub, MachineType.QEMU35]:
|
||||
config.qemu_machine = "q35"
|
||||
config.vga_type = None
|
||||
# We set up our own custom display devices.
|
||||
|
@ -768,7 +763,7 @@ def setup_machine_devices(config: Configuration):
|
|||
)
|
||||
config.character_devices.append("stdio,id=stdout,mux=on")
|
||||
config.enable_usb = True
|
||||
case MachineType.MicroVM | MachineType.ISAPC:
|
||||
elif config.machine_type in [MachineType.MicroVM, MachineType.ISAPC]:
|
||||
config.character_devices.append("stdio,id=stdout,mux=on")
|
||||
config.qemu_cpu = "qemu64"
|
||||
config.cpu_count = None
|
||||
|
@ -783,7 +778,7 @@ def setup_machine_devices(config: Configuration):
|
|||
else: # ISAPC
|
||||
config.qemu_machine = "isapc"
|
||||
|
||||
case MachineType.CI:
|
||||
elif config.machine_type == MachineType.CI:
|
||||
config.display_backend = "none"
|
||||
config.audio_backend = None
|
||||
config.audio_devices = []
|
||||
|
@ -795,7 +790,7 @@ def setup_machine_devices(config: Configuration):
|
|||
config.add_device("ich9-ahci")
|
||||
config.extra_arguments.extend(["-debugcon", "file:debug.log"])
|
||||
|
||||
case _:
|
||||
else:
|
||||
# Default machine
|
||||
config.network_default_device = f"{config.network_default_device},bus=bridge1"
|
||||
config.add_devices(
|
||||
|
@ -817,15 +812,14 @@ def setup_machine_devices(config: Configuration):
|
|||
|
||||
# Modifications for machine types that are *mostly* like the default,
|
||||
# but not entirely (especially in terms of networking).
|
||||
match config.machine_type:
|
||||
case MachineType.QEMUWithoutNetwork | MachineType.QEMU35Grub:
|
||||
if config.machine_type in [MachineType.QEMUWithoutNetwork, MachineType.QEMU35Grub]:
|
||||
config.network_backend = None
|
||||
config.network_default_device = config.ethernet_device_type
|
||||
config.packet_logging_arguments = []
|
||||
case MachineType.QEMUTap:
|
||||
elif config.machine_type == MachineType.QEMUTap:
|
||||
config.network_backend = "tap,ifname=tap0,id=br0"
|
||||
config.network_default_device = f"{config.ethernet_device_type},netdev=br0"
|
||||
case MachineType.QEMUGrub | MachineType.QEMUExtLinux:
|
||||
elif config.machine_type in [MachineType.QEMUGrub, MachineType.QEMUExtLinux]:
|
||||
config.kernel_cmdline = []
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue