]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add Incremental=relaxed
authorDaan De Meyer <daan@amutable.com>
Fri, 13 Feb 2026 16:01:44 +0000 (17:01 +0100)
committerDaan De Meyer <daan@amutable.com>
Fri, 13 Feb 2026 20:42:19 +0000 (21:42 +0100)
In systemd, we have some test subimages that we want to build once
and keep intact instead of constantly rebuilding them. Let's add
Incremental=relaxed which will only remove the outputs from those
images if -ff is used and not a regular -f.

mkosi/__init__.py
mkosi/config.py
mkosi/resources/man/mkosi.1.md

index 146db0a75ceb1e66492eb607c420d9ebb4fa4e55..f92ec1b5ec8294178cee07b4f0152bfbd6d483a9 100644 (file)
@@ -4745,7 +4745,10 @@ def run_clean(args: Args, config: Config) -> None:
         remove_image_cache = args.force > 0
         remove_package_cache = args.force > 1
     else:
-        remove_outputs = args.force > 0 or (config.is_incremental() and not have_cache(config))
+        # Rely on the fact that True is 1 and False is 0 in numeric contexts.
+        remove_outputs = args.force > (config.incremental == Incremental.relaxed) or (
+            config.is_incremental() and not have_cache(config)
+        )
         remove_build_cache = args.force > 1 or args.wipe_build_dir
         remove_image_cache = args.force > 1 or not have_cache(config)
         remove_package_cache = args.force > 2
@@ -5254,12 +5257,16 @@ def run_verb(args: Args, tools: Config | None, images: Sequence[Config], *, reso
             ikd = imd = None
 
             for config in images:
-                # If the output format is "none" or we're rebuilding and there are no build scripts, there's
-                # nothing to do so exit early.
-                if (
-                    config.output_format == OutputFormat.none
-                    or (args.rerun_build_scripts and (config.output_dir_or_cwd() / config.output).exists())
-                ) and not config.build_scripts:
+                # If the output format is "none" and there are no build scripts, there's nothing to do so
+                # exit early.
+                if config.output_format == OutputFormat.none and not config.build_scripts:
+                    continue
+
+                # If the image already exists and we're not rerunning build scripts, there's nothing to do so
+                # exit early.
+                if (config.output_dir_or_cwd() / config.output).exists() and (
+                    not args.rerun_build_scripts or not config.build_scripts
+                ):
                     continue
 
                 check_tools(config, Verb.build)
index 3101cecbbdfd50fe28e1edf44860f97f3fd30aeb..94ed5a965faaae8882f9b6aa22920973fc66ccfa 100644 (file)
@@ -400,6 +400,7 @@ class Incremental(StrEnum):
     yes = enum.auto()
     no = enum.auto()
     strict = enum.auto()
+    relaxed = enum.auto()
 
     def __bool__(self) -> bool:
         return self != Incremental.no
@@ -3818,7 +3819,7 @@ SETTINGS: list[ConfigSetting[Any]] = [
         parse=config_make_enum_parser_with_boolean(Incremental, yes=Incremental.yes, no=Incremental.no),
         default=Incremental.no,
         help="Make use of and generate intermediary cache images",
-        scope=SettingScope.universal,
+        scope=SettingScope.inherit,
         choices=Incremental.values(),
     ),
     ConfigSetting(
index bf518811eaf4add600e5e32c4ebd4594a9c39668..86fe39aa3430d204b350d4f8179076096d069609 100644 (file)
@@ -1553,6 +1553,9 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     If set to `strict`, the build fails if previously built cached image does
     not exist.
 
+    If set to `relaxed`, images are only rebuilt when `-ff` is specified or
+    if the cached imaged is out of date.
+
 `CacheOnly=`, `--cache-only=`
 :   Takes one of `auto`, `metadata`, `always` or `never`. Defaults to
     `auto`. If `always`, the package manager is instructed not to contact