]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Reuse tools tree on incremental builds
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 Apr 2024 19:42:44 +0000 (21:42 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Apr 2024 13:47:28 +0000 (15:47 +0200)
Every part of the default tools tree is cached. Thus, we can check
if the cache is out of date on incremental builds and if it isn't,
just reuse the previous tools tree instead of doing unnecessary work.

mkosi/__init__.py

index 4649f0c2b5afc1e590cf4cfa43fc39989dc19936..8e97685c12a756ce5ef712e1d424792c7b866890 100644 (file)
@@ -4177,10 +4177,10 @@ def run_clean_scripts(config: Config) -> None:
                 )
 
 
-def needs_clean(args: Args, config: Config) -> bool:
+def needs_clean(args: Args, config: Config, force: int = 1) -> bool:
     return (
         args.verb == Verb.clean or
-        args.force > 0 or
+        args.force >= force or
         not (config.output_dir_or_cwd() / config.output_with_compression).exists() or
         # When the output is a directory, its name is the same as the symlink we create that points to the actual
         # output when not building a directory. So if the full output path exists, we have to check that it's not
@@ -4429,12 +4429,12 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
     # 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"):
-            fork_and_wait(
-                run_clean,
-                args,
-                finalize_default_tools(args, config, resources=resources),
-                resources=resources,
-            )
+            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)