check_root_populated(context)
run_build_scripts(context)
- if context.config.output_format == OutputFormat.none or (
- context.args.run_build_scripts
- and (context.config.output_dir_or_cwd() / context.config.output).exists()
- ):
+ if context.config.output_format == OutputFormat.none or context.args.rerun_build_scripts:
return
if wantrepo:
Verb.sandbox: run_sandbox,
}[args.verb](args, last)
+ if last.output_format == OutputFormat.none:
+ if args.verb != Verb.build:
+ die(f"Cannot run '{args.verb}' verb on image with output format 'none'")
+
+ if args.rerun_build_scripts:
+ die("Cannot use --run-build-scripts on image with output format 'none'")
+
output = last.output_dir_or_cwd() / last.output_with_compression
if (
and output.exists()
and not output.is_symlink()
and last.output_format != OutputFormat.none
- and not args.run_build_scripts
+ and not args.rerun_build_scripts
):
logging.info(f"Output path {output} exists already. (Use --force to rebuild.)")
return
+ if args.rerun_build_scripts 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'",
+ )
+
if args.verb != Verb.build and not args.force and not output.exists():
die(
f"Image '{last.image}' has not been built yet",
check_workspace_directory(last)
+ if args.rerun_build_scripts and not last.is_incremental():
+ die("Incremental= must be enabled to be able to use --rerun-build-scripts")
+
if last.is_incremental():
for a, b in itertools.combinations(images, 2):
if a.expand_key_specifiers(a.cache_key) == b.expand_key_specifiers(b.cache_key):
hint="Add the &I specifier to the cache key to avoid this issue",
)
- if last.is_incremental() and last.incremental == Incremental.strict:
+ if last.is_incremental() and (last.incremental == Incremental.strict or args.rerun_build_scripts):
if args.force > 1:
die(
"Cannot remove incremental caches when building with Incremental=strict",
hint="Build once with '-i yes' to update the image cache",
)
- for config in images:
- if have_cache(config):
- continue
-
- die(
- f"Strict incremental mode is enabled and cache for image {config.image} is out-of-date",
- hint="Build once with '-i yes' to update the image cache",
- )
+ if any((c := config).is_incremental() and not have_cache(config) for config in images):
+ if args.rerun_build_scripts:
+ die(
+ f"Cannot use --rerun-build-scripts as the cache for image {c.image} is out-of-date",
+ hint="Rebuild the image to update the image cache",
+ )
+ else:
+ die(
+ f"Strict incremental mode is enabled and cache for image {c.image} is out-of-date",
+ hint="Build once with '-i yes' to update the image cache",
+ )
# 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.
images = resolve_deps(images[:-1], last.dependencies) + [last]
if (
- args.run_build_scripts
+ args.rerun_build_scripts
or last.output_format == OutputFormat.none
or not (last.output_dir_or_cwd() / last.output).exists()
):
# nothing to do so exit early.
if (
config.output_format == OutputFormat.none
- or (args.run_build_scripts and (config.output_dir_or_cwd() / config.output).exists())
+ or (args.rerun_build_scripts and (config.output_dir_or_cwd() / config.output).exists())
) and not config.build_scripts:
continue
if args.auto_bump:
bump_image_version()
- if last.history:
+ if last.history and not args.rerun_build_scripts:
Path(".mkosi-private/history").mkdir(parents=True, exist_ok=True)
Path(".mkosi-private/history/latest.json").write_text(
json.dumps(
doc_format: DocFormat
json: bool
wipe_build_dir: bool
- run_build_scripts: bool
+ rerun_build_scripts: bool
@classmethod
def default(cls) -> "Args":
)
parser.add_argument(
"-R",
- "--run-build-scripts",
+ "--rerun-build-scripts",
help="Run build scripts even if the image is not rebuilt",
action="store_true",
default=False,
return (
args.directory is not None
and args.verb.needs_build()
- and args.verb != Verb.build
+ and (args.verb != Verb.build or args.rerun_build_scripts)
and not args.force
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)