From: Jacob Emmert-Aronson Date: Sun, 24 Jul 2022 05:23:21 +0000 (-0700) Subject: Don't remove duplicates from QemuArgs X-Git-Tag: v14~99^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7e4eb16a6cd4d35565f2a7ecd193e1d2928dab1;p=thirdparty%2Fmkosi.git Don't remove duplicates from QemuArgs Repeated arguments are valid in a QEMU command line (for example, setting multiple `-device` flags to attach several devices to the VM), and removing these duplicate tokens breaks the QEMU invocation. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 91db08e71..0755e1060 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4719,6 +4719,7 @@ def remove_duplicates(items: List[T]) -> List[T]: class ListAction(argparse.Action): delimiter: str + deduplicate: bool = True def __init__(self, *args: Any, choices: Optional[Iterable[Any]] = None, **kwargs: Any) -> None: self.list_choices = choices @@ -4762,7 +4763,8 @@ class ListAction(argparse.Action): else: ary.append(values) - ary = remove_duplicates(ary) + if self.deduplicate: + ary = remove_duplicates(ary) setattr(namespace, self.dest, ary) @@ -4778,6 +4780,10 @@ class SpaceDelimitedListAction(ListAction): delimiter = " " +class RepeatableSpaceDelimitedListAction(SpaceDelimitedListAction): + deduplicate = False + + class BooleanAction(argparse.Action): """Parse boolean command line arguments @@ -5688,7 +5694,7 @@ def create_parser() -> ArgumentParserMkosi: ) group.add_argument( "--qemu-args", - action=SpaceDelimitedListAction, + action=RepeatableSpaceDelimitedListAction, default=[], # Suppress the command line option because it's already possible to pass qemu args as normal # arguments. diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index 743bc8ae9..d68e0ed62 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -174,7 +174,7 @@ class MkosiConfig: is_eq = False return is_eq - def _append_list(self, ref_entry: str, new_args: Any, job_name: str = DEFAULT_JOB_NAME, separator: str = ",") -> None: + def _append_list(self, ref_entry: str, new_args: Any, job_name: str = DEFAULT_JOB_NAME, separator: str = ",", with_duplicates: bool = False) -> None: """Helper function handling comma separated list as supported by mkosi""" args_list = [] if isinstance(new_args, str): @@ -189,7 +189,7 @@ class MkosiConfig: if isinstance(arg, str) and arg.startswith("!"): if arg[1:] in self.reference_config[job_name][ref_entry]: self.reference_config[job_name][ref_entry].remove(arg[1:]) - elif arg not in self.reference_config[job_name][ref_entry]: + elif with_duplicates or arg not in self.reference_config[job_name][ref_entry]: self.reference_config[job_name][ref_entry].append(arg) @staticmethod @@ -378,6 +378,8 @@ class MkosiConfig: self._append_list("extra_search_paths", mk_config_host["ExtraSearchPaths"], job_name, ":") if "QemuHeadless" in mk_config_host: self.reference_config[job_name]["qemu_headless"] = mk_config_host["QemuHeadless"] + if "QemuArgs" in mk_config_host: + self._append_list("qemu_args", mk_config_host["QemuArgs"], job_name, " ", with_duplicates=True) if "Netdev" in mk_config_host: self.reference_config[job_name]["netdev"] = mk_config_host["Netdev"] if "Ephemeral" in mk_config_host: @@ -598,6 +600,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/here:search/there", "QemuHeadless": True, + "QemuArgs": "-vga none -device virtio-vga-gl", "Netdev": True, }, } @@ -664,6 +667,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/ubu", "QemuHeadless": True, + "QemuArgs": "-vga virtio -device usb-kbd -device usb-mouse", "Netdev": True, }, } @@ -730,6 +734,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/debi", "QemuHeadless": True, + "QemuArgs": "-nic user,model=virtio-net-pci", "Netdev": True, }, }