]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only use a single default tools tree per build
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 8 May 2024 12:41:06 +0000 (14:41 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 8 May 2024 18:16:10 +0000 (20:16 +0200)
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.

mkosi/__init__.py
mkosi/resources/mkosi.md

index ed9e3e7d59debbcb2caa89434a709a6c980c8427..9a2af80fe8691d2ec8148366c0bd23a65e41f79b 100644 (file)
@@ -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():
index 0aeee7c624895231223da5b6f45f492f92080ac3..d34a7c4ffc07a6290a1c53851274f51e2555a208 100644 (file)
@@ -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 |
   |-------------------------|--------|--------|--------|--------|------|----------|