]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use default_factory for tools tree options defaults
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 Jan 2024 16:15:46 +0000 (17:15 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 Jan 2024 16:17:58 +0000 (17:17 +0100)
mkosi/__init__.py
mkosi/config.py

index 749f028af930e3f13f52b812fc9de676abefb4d8..a043a6b9eb599ac71a13fe635bfacf8644828ef1 100644 (file)
@@ -3249,22 +3249,15 @@ def prepend_to_environ_path(config: Config) -> Iterator[None]:
 
 @contextlib.contextmanager
 def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]:
-    distribution = config.tools_tree_distribution or config.distribution.default_tools_tree_distribution()
-    if not distribution:
+    if not config.tools_tree_distribution:
         die(f"{config.distribution} does not have a default tools tree distribution",
             hint="use ToolsTreeDistribution= to set one explicitly")
 
-    release = config.tools_tree_release or distribution.default_release()
-    mirror = (
-        config.tools_tree_mirror or
-        (config.mirror if config.mirror and config.distribution == distribution else None)
-    )
-
     cmdline = [
         "--directory", "",
-        "--distribution", str(distribution),
-        *(["--release", release] if release else []),
-        *(["--mirror", mirror] if mirror else []),
+        "--distribution", str(config.tools_tree_distribution),
+        *(["--release", config.tools_tree_release] if config.tools_tree_release else []),
+        *(["--mirror", config.tools_tree_mirror] if config.tools_tree_mirror else []),
         "--repository-key-check", str(config.repository_key_check),
         "--cache-only", str(config.cache_only),
         *(["--output-dir", str(config.output_dir)] if config.output_dir else []),
@@ -3273,7 +3266,7 @@ def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]:
         "--incremental", str(config.incremental),
         "--acl", str(config.acl),
         *([f"--package={package}" for package in config.tools_tree_packages]),
-        "--output", f"{distribution}-tools",
+        "--output", f"{config.tools_tree_distribution}-tools",
         *(["--source-date-epoch", str(config.source_date_epoch)] if config.source_date_epoch is not None else []),
         *([f"--environment={k}='{v}'" for k, v in config.environment.items()]),
         *([f"--extra-search-path={p}" for p in config.extra_search_paths]),
@@ -3290,7 +3283,7 @@ def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]:
             *tools.build_scripts,
         )
 
-        tools = dataclasses.replace(tools, image=f"{distribution}-tools")
+        tools = dataclasses.replace(tools, image=f"{config.tools_tree_distribution}-tools")
 
         yield tools
 
index 46b0c7ba39120c832f5bdff1f93939fb51bf7289..b06bc0aa827cb88a24434aa46add86e86c1e2663 100644 (file)
@@ -2281,6 +2281,8 @@ SETTINGS = (
         metavar="DISTRIBUTION",
         section="Host",
         parse=config_make_enum_parser(Distribution),
+        default_factory_depends=("distribution",),
+        default_factory=lambda ns: ns.distribution.default_tools_tree_distribution(),
         help="Set the distribution to use for the default tools tree",
     ),
     ConfigSetting(
@@ -2288,12 +2290,16 @@ SETTINGS = (
         metavar="RELEASE",
         section="Host",
         parse=config_parse_string,
+        default_factory_depends=("tools_tree_distribution",),
+        default_factory=lambda ns: d.default_release() if (d := ns.tools_tree_distribution) else None,
         help="Set the release to use for the default tools tree",
     ),
     ConfigSetting(
         dest="tools_tree_mirror",
         metavar="MIRROR",
         section="Host",
+        default_factory_depends=("distribution", "tools_tree_distribution"),
+        default_factory=lambda ns: ns.mirror if ns.mirror and ns.distribution == ns.tools_tree_distribution else None,
         help="Set the mirror to use for the default tools tree",
     ),
     ConfigSetting(