# "--force".
if args.verb == Verb.clean:
- remove_build_cache = args.force > 0
+ remove_output_dir = config.output_format != OutputFormat.none
+ remove_build_cache = args.force > 0 or args.wipe_build_dir
+ remove_image_cache = args.force > 0
remove_package_cache = args.force > 1
else:
- remove_build_cache = args.force > 1
+ remove_output_dir = config.output_format != OutputFormat.none or args.force > 0
+ remove_build_cache = args.force > 1 or args.wipe_build_dir
+ remove_image_cache = args.force > 1
remove_package_cache = args.force > 2
- if config.output_format != OutputFormat.none or args.force:
+ if remove_output_dir:
outputs = {
config.output_dir_or_cwd() / output
for output in config.outputs
):
rmtree(*outputs)
- if remove_build_cache:
- if config.cache_dir:
- initrd = (
- cache_tree_paths(finalize_default_initrd(args, config, resources=resources))
- if config.distribution != Distribution.custom
- else []
- )
+ if remove_build_cache and config.build_dir and config.build_dir.exists() and any(config.build_dir.iterdir()):
+ with complete_step(f"Clearing out build directory of {config.name()} image…"):
+ rmtree(*config.build_dir.iterdir())
- if any(p.exists() for p in itertools.chain(cache_tree_paths(config), initrd)):
- with complete_step(f"Removing cache entries of {config.name()} image…"):
- rmtree(*(p for p in itertools.chain(cache_tree_paths(config), initrd) if p.exists()))
+ if remove_image_cache and config.cache_dir:
+ initrd = (
+ cache_tree_paths(finalize_default_initrd(args, config, resources=resources))
+ if config.distribution != Distribution.custom
+ else []
+ )
- if config.build_dir and config.build_dir.exists() and any(config.build_dir.iterdir()):
- with complete_step(f"Clearing out build directory of {config.name()} image…"):
- rmtree(*config.build_dir.iterdir())
+ if any(p.exists() for p in itertools.chain(cache_tree_paths(config), initrd)):
+ with complete_step(f"Removing cache entries of {config.name()} image…"):
+ rmtree(*(p for p in itertools.chain(cache_tree_paths(config), initrd) if p.exists()))
- if (
- remove_package_cache and
- any(config.package_cache_dir_or_default().glob("*"))
- ):
+ if remove_package_cache and any(config.package_cache_dir_or_default().glob("*")):
subdir = config.distribution.package_manager(config).subdir(config)
with (
# 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 needs_clean(args, config):
+ if needs_clean(args, config) or args.wipe_build_dir:
fork_and_wait(run_clean, args, config, resources=resources)
if args.verb == Verb.clean:
"GenkeyValidDays": "100",
"Json": false,
"Pager": true,
- "Verb": "build"
+ "Verb": "build",
+ "WipeBuildDir": true
}}
"""
)
args = Args(
- auto_bump = False,
- cmdline = ["foo", "bar"],
- debug = False,
- debug_shell = False,
- debug_workspace = False,
- directory = Path(path) if path is not None else None,
- doc_format = DocFormat.auto,
- force = 9001,
- genkey_common_name = "test",
- genkey_valid_days = "100",
- json = False,
- pager = True,
- verb = Verb.build,
+ auto_bump=False,
+ cmdline=["foo", "bar"],
+ debug=False,
+ debug_shell=False,
+ debug_workspace=False,
+ directory=Path(path) if path is not None else None,
+ doc_format=DocFormat.auto,
+ force=9001,
+ genkey_common_name="test",
+ genkey_valid_days="100",
+ json=False,
+ pager=True,
+ verb=Verb.build,
+ wipe_build_dir=True,
)
assert args.to_json(indent=4, sort_keys=True) == dump.rstrip()