check_root_populated(context)
run_build_scripts(context)
- if context.config.output_format == OutputFormat.none or context.args.rerun_build_scripts:
+ if context.config.output_format == OutputFormat.none or (
+ context.args.rerun_build_scripts
+ and (context.config.output_dir_or_cwd() / context.config.output).exists()
+ ):
return
if wantrepo:
def needs_build(args: Args, config: Config, force: int = 1) -> bool:
return (
- args.force >= force
+ (args.force >= force and not args.rerun_build_scripts)
or not (config.output_dir_or_cwd() / config.output_with_compression).exists()
# 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
logging.info(f"Output path {output} exists already. (Use --force to rebuild.)")
return
- if args.rerun_build_scripts and not output.exists():
+ if args.rerun_build_scripts and not args.force and not output.exists():
die(
f"Image '{last.image}' must be built once before --rerun-build-scripts can be used",
hint="Build the image once with 'mkosi build'",
hint="Add the &I specifier to the cache key to avoid this issue",
)
- if last.is_incremental() and (last.incremental == Incremental.strict or args.rerun_build_scripts):
+ if last.is_incremental() and (
+ last.incremental == Incremental.strict or (args.rerun_build_scripts and not args.force)
+ ):
if args.force > 1:
die(
"Cannot remove incremental caches when building with Incremental=strict",
or last.output_format == OutputFormat.none
or not (last.output_dir_or_cwd() / last.output).exists()
):
+ history = (
+ last.output_format == OutputFormat.none or not (last.output_dir_or_cwd() / last.output).exists()
+ )
+
for config in images:
if any(
source.type != KeySourceType.file
if args.auto_bump:
bump_image_version()
- if last.history and not args.rerun_build_scripts:
+ if last.history and history:
Path(".mkosi-private/history").mkdir(parents=True, exist_ok=True)
Path(".mkosi-private/history/latest.json").write_text(
json.dumps(
return (
args.directory is not None
and args.verb.needs_build()
- and (args.verb != Verb.build or args.rerun_build_scripts)
- and not args.force
+ and ((args.verb != Verb.build and not args.force) or args.rerun_build_scripts)
and Path(".mkosi-private/history/latest.json").exists()
)
if args.cmdline and not args.verb.supports_cmdline():
die(f"Arguments after verb are not supported for {args.verb}.")
- if args.rerun_build_scripts and args.force:
- die("--force cannot be used together with --rerun-build-scripts")
-
# If --debug was passed, apply it as soon as possible.
if ARG_DEBUG.get():
logging.getLogger().setLevel(logging.DEBUG)