)
-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
# 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)