@@ -3943,7 +3943,10 @@ def build_image(context: Context) -> None:
3943
3943
check_root_populated (context )
3944
3944
run_build_scripts (context )
3945
3945
3946
- if context .config .output_format == OutputFormat .none or context .args .rerun_build_scripts :
3946
+ if context .config .output_format == OutputFormat .none or (
3947
+ context .args .rerun_build_scripts
3948
+ and (context .config .output_dir_or_cwd () / context .config .output ).exists ()
3949
+ ):
3947
3950
return
3948
3951
3949
3952
if wantrepo :
@@ -4668,7 +4671,7 @@ def validate_certificates_and_keys(config: Config) -> None:
4668
4671
4669
4672
def needs_build (args : Args , config : Config , force : int = 1 ) -> bool :
4670
4673
return (
4671
- args .force >= force
4674
+ ( args .force >= force and not args . rerun_build_scripts )
4672
4675
or not (config .output_dir_or_cwd () / config .output_with_compression ).exists ()
4673
4676
# When the output is a directory, its name is the same as the symlink we create that points to the
4674
4677
# actual output when not building a directory. So if the full output path exists, we have to check
@@ -5121,7 +5124,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
5121
5124
logging .info (f"Output path { output } exists already. (Use --force to rebuild.)" )
5122
5125
return
5123
5126
5124
- if args .rerun_build_scripts and not output .exists ():
5127
+ if args .rerun_build_scripts and not args . force and not output .exists ():
5125
5128
die (
5126
5129
f"Image '{ last .image } ' must be built once before --rerun-build-scripts can be used" ,
5127
5130
hint = "Build the image once with 'mkosi build'" ,
@@ -5149,7 +5152,9 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
5149
5152
hint = "Add the &I specifier to the cache key to avoid this issue" ,
5150
5153
)
5151
5154
5152
- if last .is_incremental () and (last .incremental == Incremental .strict or args .rerun_build_scripts ):
5155
+ if last .is_incremental () and (
5156
+ last .incremental == Incremental .strict or (args .rerun_build_scripts and not args .force )
5157
+ ):
5153
5158
if args .force > 1 :
5154
5159
die (
5155
5160
"Cannot remove incremental caches when building with Incremental=strict" ,
@@ -5197,6 +5202,10 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
5197
5202
or last .output_format == OutputFormat .none
5198
5203
or not (last .output_dir_or_cwd () / last .output ).exists ()
5199
5204
):
5205
+ history = (
5206
+ last .output_format == OutputFormat .none or not (last .output_dir_or_cwd () / last .output ).exists ()
5207
+ )
5208
+
5200
5209
for config in images :
5201
5210
if any (
5202
5211
source .type != KeySourceType .file
@@ -5279,7 +5288,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
5279
5288
if args .auto_bump :
5280
5289
bump_image_version ()
5281
5290
5282
- if last .history and not args . rerun_build_scripts :
5291
+ if last .history and history :
5283
5292
Path (".mkosi-private/history" ).mkdir (parents = True , exist_ok = True )
5284
5293
Path (".mkosi-private/history/latest.json" ).write_text (
5285
5294
json .dumps (
0 commit comments