]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't remove duplicates from QemuArgs
authorJacob Emmert-Aronson <jacob@roadnottaken2718.com>
Sun, 24 Jul 2022 05:23:21 +0000 (22:23 -0700)
committerJacob Emmert-Aronson <jacob@roadnottaken2718.com>
Thu, 28 Jul 2022 02:41:51 +0000 (19:41 -0700)
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.

mkosi/__init__.py
tests/test_config_parser.py

index 91db08e717124b8dbedf34853c1c76d82c6e2870..0755e1060dace69b1d45b2533e7fb37c3720c6ed 100644 (file)
@@ -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.
index 743bc8ae9cbdf0414b0ca16c189eb603d582ff20..d68e0ed62ee31fb905c3df4122a0af3188b412c4 100644 (file)
@@ -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,
             },
         }