From: Daan De Meyer Date: Sat, 13 Apr 2024 19:42:44 +0000 (+0200) Subject: Reuse tools tree on incremental builds X-Git-Tag: v23~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=025b30c749639ea8b6299f951e97869b3d1dcc17;p=thirdparty%2Fmkosi.git Reuse tools tree on incremental builds 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 4649f0c2b..8e97685c1 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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)