From: Daan De Meyer Date: Fri, 8 Sep 2023 19:00:29 +0000 (+0200) Subject: Make --preset into a configuration option X-Git-Tag: v17~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1d2a3c8024b34b9687428823cfb87f779132e5f;p=thirdparty%2Fmkosi.git Make --preset into a configuration option Let's allow specifying Presets= in global configuration files to specify which presets to build. --- diff --git a/mkosi/config.py b/mkosi/config.py index 3cc3836f0..1c310ae2d 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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) diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index d3e84b2e4..e5d7c8870 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -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