]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make --preset into a configuration option
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 8 Sep 2023 19:00:29 +0000 (21:00 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 9 Sep 2023 12:37:35 +0000 (14:37 +0200)
Let's allow specifying Presets= in global configuration files to
specify which presets to build.

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

index 3cc3836f04225cf26e8ac699d9340757032c99eb..1c310ae2d16f0bf536d7795c39f8c85864f1351c 100644 (file)
@@ -597,7 +597,6 @@ class MkosiArgs:
     genkey_valid_days: str
     genkey_common_name: str
     auto_bump: bool
-    presets: list[str]
     doc_format: DocFormat
 
     @classmethod
@@ -617,6 +616,7 @@ class MkosiConfig:
     access the value from state.
     """
 
+    presets: tuple[str]
     dependencies: tuple[str]
 
     distribution: Distribution
@@ -876,6 +876,13 @@ def parse_ini(path: Path, only_sections: Sequence[str] = ()) -> Iterator[tuple[s
 
 
 SETTINGS = (
+    MkosiConfigSetting(
+        dest="presets",
+        long="--preset",
+        section="Preset",
+        parse=config_make_list_parser(delimiter=","),
+        help="Specify which presets to build",
+    ),
     MkosiConfigSetting(
         dest="dependencies",
         long="--dependency",
@@ -1746,14 +1753,6 @@ def create_argument_parser(*, settings: bool) -> argparse.ArgumentParser:
         action="store_true",
         default=False,
     )
-    parser.add_argument(
-        "--preset",
-        action="append",
-        dest="presets",
-        metavar="PRESET",
-        default=[],
-        help="Build the specified presets and their dependencies",
-    )
     parser.add_argument(
         "--doc-format",
         help="The format to show documentation in",
@@ -1844,15 +1843,15 @@ def backward_compat_stubs(namespace: argparse.Namespace) -> None:
         logging.warning("--cache is no longer supported")
 
 
-def resolve_deps(args: MkosiArgs, presets: Sequence[MkosiConfig]) -> list[MkosiConfig]:
+def resolve_deps(presets: Sequence[MkosiConfig], include: Sequence[str]) -> list[MkosiConfig]:
     graph = {p.preset: p.dependencies for p in presets}
 
-    if args.presets:
-        if any((missing := p) not in graph for p in args.presets):
+    if include:
+        if any((missing := p) not in graph for p in include):
             die(f"No preset found with name {missing}")
 
         deps = set()
-        queue = [*args.presets]
+        queue = [*include]
 
         while queue:
             if (preset := queue.pop(0)) not in deps:
@@ -2034,9 +2033,13 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
     if args.verb == Verb.help:
         PagerHelpAction.__call__(None, argparser, namespace)  # type: ignore
 
+    include = ()
+
     if args.directory != "":
         parse_config(Path("."), namespace, defaults)
 
+        include = getattr(namespace, "presets", ())
+
         if Path("mkosi.presets").exists():
             for p in Path("mkosi.presets").iterdir():
                 if not p.is_dir() and not p.suffix == ".conf":
@@ -2070,7 +2073,7 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
     backward_compat_stubs(namespace)
 
     presets = [load_config(ns) for ns in presets]
-    presets = resolve_deps(args, presets)
+    presets = resolve_deps(presets, include)
 
     return args, tuple(presets)
 
index d3e84b2e4aed984b6e27d88d60f8c2e3666f840e..e5d7c88706a5b67a40357d0f23dbd261adbc75ed 100644 (file)
@@ -201,13 +201,6 @@ Those settings cannot be configured in the configuration files.
   each build in a series will have a version number one higher then
   the previous one.
 
-`--preset=`
-
-: If specified, only build the given presets. Can be specified multiple
-  times to build multiple presets. All the given presets and their
-  dependencies are built. If not specified, all presets are built. See
-  the **Presets** section for more information.
-
 `--doc-format`
 
 : The format to show the documentation in. Supports the values `markdown`,
@@ -341,12 +334,23 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 
 ### [Preset] Section
 
+`Presets=`, `--preset=`
+
+: If specified, only build the given presets. Can be specified multiple
+  times to build multiple presets. All the given presets and their
+  dependencies are built. If not specified, all presets are built. See
+  the **Presets** section for more information.
+
+: Note that this section only takes effect when specified in the global
+  configuration files. It has no effect if specified as a preset
+  specific setting.
+
 `Dependencies=`, `--dependency=`
 
 : The presets that this preset depends on specified as a comma-separated
   list. All presets configured in this option will be built before this
   preset and will be pulled in as dependencies of this preset when
-  `--preset` is used.
+  `Presets=` is used.
 
 ### [Distribution] Section
 
@@ -1523,7 +1527,7 @@ the `.conf` extension.
 
 When presets are found in `mkosi.presets/`, mkosi will build the
 configured preset and its dependencies (or all of them if no presets
-were explicitly configured using `--preset=`). To add dependencies
+were explicitly configured using `Presets=`). To add dependencies
 between presets, the `Dependencies=` setting can be used.
 
 When presets are defined, mkosi will first read the global configuration