From: Daan De Meyer Date: Wed, 8 May 2024 12:41:06 +0000 (+0200) Subject: Only use a single default tools tree per build X-Git-Tag: v23.1~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59ba84f31dd51378d4efcd4dd9a9205bf778b0ef;p=thirdparty%2Fmkosi.git Only use a single default tools tree per build Currently, if multiple images are defined, each with a default tools tree, if they use the same distribution, all the various ToolsTreeXXX= settings for the later images will be ignored since we'll only build one tools tree. Also, if any of the images set Incremental=no, we will remove the default tools tree outputs even if Incremental=yes is enabled for other images. To keep ourselves sane, let's avoid dealing with multiple defaults tools trees and only look at the last image to figure out whether we should build a default tools tree and what to put in it. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index ed9e3e7d5..9a2af80fe 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4530,17 +4530,21 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: if args.verb == Verb.build and not args.force: check_outputs(config) + last = images[-1] + + if last.tools_tree and last.tools_tree == Path("default"): + tools = finalize_default_tools(args, last, resources=resources) + + # If we're doing an incremental tools tree and the cache is not out of date, don't clean up the tools tree + # so that we can reuse the previous one. + if not tools.incremental or not have_cache(tools) or needs_clean(args, tools, force=2): + fork_and_wait(run_clean, args, tools, resources=resources) + else: + tools = None + # First, process all directory removals because otherwise if different images share directories a later # image build could end up deleting the output generated by an earlier image build. for config in images: - if config.tools_tree and config.tools_tree == Path("default"): - toolsconfig = finalize_default_tools(args, config, resources=resources) - - # If we're doing an incremental tools tree and the cache is not out of date, don't clean up the tools tree - # so that we can reuse the previous one. - if not toolsconfig.incremental or not have_cache(toolsconfig) or needs_clean(args, toolsconfig, force=2): - fork_and_wait(run_clean, args, toolsconfig, resources=resources) - fork_and_wait(run_clean, args, config, resources=resources) if args.verb == Verb.clean: @@ -4558,21 +4562,19 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: build = False for i, config in enumerate(images): - tools = ( - finalize_default_tools(args, config, resources=resources) - if config.tools_tree and config.tools_tree == Path("default") - else None - ) - images[i] = config = dataclasses.replace( config, - tools_tree=tools.output_dir_or_cwd() / tools.output if tools else config.tools_tree, + tools_tree=( + tools.output_dir_or_cwd() / tools.output + if tools and config.tools_tree == Path("default") + else config.tools_tree + ) ) if args.verb != Verb.build and args.force == 0: continue - if tools and not (tools.output_dir_or_cwd() / tools.output_with_compression).exists(): + if tools and not (tools.output_dir_or_cwd() / tools.output).exists(): fork_and_wait(run_sync, args, tools, resources=resources) fork_and_wait(run_build, args, tools, resources=resources) @@ -4591,6 +4593,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: if args.verb == Verb.build: return + # The images array has been modified so we need to reevaluate last again. last = images[-1] if not (last.output_dir_or_cwd() / last.output_with_compression).exists(): diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 0aeee7c62..d34a7c4ff 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -1551,9 +1551,17 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `ExtraSearchPaths=`, the binary will be executed on the host. : If set to `default`, mkosi will automatically add an extra tools tree - image and use it as the tools tree. The following table shows for - which distributions default tools tree packages are defined and which - packages are included in those default tools trees: + image and use it as the tools tree. + +: Note that mkosi will only build a single default tools tree per build, + even if multiple images are defined in `mkosi.images` with + `ToolsTree=default`. The settings of the "last" image will apply to + the default tools tree (usually the image defined last in + mkosi.images and without any dependencies on other images). + +: The following table shows for which distributions default tools tree + packages are defined and which packages are included in those default + tools trees: | | Fedora | CentOS | Debian | Ubuntu | Arch | openSUSE | |-------------------------|--------|--------|--------|--------|------|----------|