]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Introduce --append argument
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 5 Apr 2024 19:01:56 +0000 (21:01 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 8 Apr 2024 10:05:50 +0000 (12:05 +0200)
In systemd, we want to have a default set of kernel command line
arguments and override a few of them via the command line. Introduce
--append so that we can specify settings via the command line that
are parsed after all configuration have files have been parsed to
make this possible.

mkosi/config.py
mkosi/resources/mkosi.md

index 4a8c92d1ab2c150dcdb9d586ddd55ebe5705449c..1a7bae4f7053bc7df6eb58412b37d68f072e3d53 100644 (file)
@@ -3098,6 +3098,11 @@ def create_argument_parser(action: type[argparse.Action]) -> argparse.ArgumentPa
         action="store_true",
         default=False,
     )
+    parser.add_argument(
+        "--append",
+        help="All settings passed after this argument will be parsed after all configuration files are parsed",
+        action="store_true",
+    )
     # These can be removed once mkosi v15 is available in LTS distros and compatibility with <= v14
     # is no longer needed in build infrastructure (e.g.: OBS).
     parser.add_argument(
@@ -3196,6 +3201,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
     defaults = argparse.Namespace()
     parsed_includes: set[tuple[int, int]] = set()
     immutable_settings: set[str] = set()
+    append = False
 
     def expand_specifiers(text: str, path: Path) -> str:
         percent = False
@@ -3273,6 +3279,9 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
         ) -> None:
             assert option_string is not None
 
+            if getattr(namespace, "append", False) != append:
+                return
+
             if values is None and self.nargs == "?":
                 values = self.const or "yes"
 
@@ -3548,6 +3557,11 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
         finalize_defaults()
         images = [namespace]
 
+    append = True
+
+    for ns in images:
+        argparser.parse_args(argv, ns)
+
     for s in vars(cli_ns):
         if s not in SETTINGS_LOOKUP_BY_DEST:
             continue
index 04953b64a420d483dcd933218c75f1dacbf5774f..762955c7df6fa30b0840f26ed91153e3142cd01b 100644 (file)
@@ -255,6 +255,15 @@ Those settings cannot be configured in the configuration files.
 
 : Show the summary output as JSON-SEQ.
 
+`--append`
+
+: All settings passed after this argument will be parsed after all
+  configuration files have been parsed.
+
+: Note that any setting passed this way will not have any affect on
+  `[Match]` sections as they will only be parsed after all `[Match]`
+  sections have already been evaluated.
+
 ## Supported output formats
 
 The following output formats are supported: