]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix incremental caching
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 1 Nov 2023 11:49:52 +0000 (12:49 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Nov 2023 10:33:55 +0000 (11:33 +0100)
- Make sure the distribution, release and architecture are also part
of the cache manifest
- Remove the output name from the cache key and use the distribution,
release, architecture and optionally image name instead.
- Use MkosiEncoder to serialize the cache manifest.

mkosi.conf.d/10-common.conf
mkosi.conf.d/30-dirs.conf [deleted file]
mkosi/__init__.py
mkosi/config.py

index 5b88de6caf46738a7ef314a2dfe071f31f1faff8..e0e2f521dd1ce043c497081bdff6c41551672918 100644 (file)
@@ -4,6 +4,7 @@
 # These images are (among other things) used for running mkosi which means we need some disk space available so
 # default to directory output where disk space isn't a problem.
 @Format=directory
+@CacheDirectory=mkosi.cache
 
 [Content]
 Autologin=yes
diff --git a/mkosi.conf.d/30-dirs.conf b/mkosi.conf.d/30-dirs.conf
deleted file mode 100644 (file)
index c90d8a8..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-# These depend on the configured distribution, release and architecture
-# so we order this drop-in after all the other drop-ins.
-
-[Output]
-@CacheDirectory=mkosi.cache/%d~%r~%a
-@BuildDirectory=mkosi.builddir/%d~%r~%a
index 41ae721a439fa6217437a9d6015bc5a0ac51b7f8..0c54b19c909ddf86f6653a523db7af97e545c87b 100644 (file)
@@ -1120,6 +1120,8 @@ def build_initrd(state: MkosiState) -> Path:
     ]
 
     args, [config] = parse_config(cmdline)
+
+    config = dataclasses.replace(config, image="default-initrd")
     assert config.output_dir
 
     config.output_dir.mkdir(exist_ok=True)
@@ -1563,11 +1565,18 @@ def unlink_output(args: MkosiArgs, config: MkosiConfig) -> None:
 
 
 def cache_tree_paths(config: MkosiConfig) -> tuple[Path, Path, Path]:
+    fragments = [config.distribution, config.release, config.architecture]
+
+    if config.image:
+        fragments += [config.image]
+
+    key = '~'.join(str(s) for s in fragments)
+
     assert config.cache_dir
     return (
-        config.cache_dir / f"{config.output}.cache",
-        config.cache_dir / f"{config.output}.build.cache",
-        config.cache_dir / f"{config.output}.manifest",
+        config.cache_dir / f"{key}.cache",
+        config.cache_dir / f"{key}.build.cache",
+        config.cache_dir / f"{key}.manifest",
     )
 
 
@@ -1861,7 +1870,14 @@ def save_cache(state: MkosiState) -> None:
             rmtree(build)
             move_tree(state.config, state.workspace / "build-overlay", build)
 
-        manifest.write_text(json.dumps(state.config.cache_manifest()))
+        manifest.write_text(
+            json.dumps(
+                state.config.cache_manifest(),
+                cls=MkosiJsonEncoder,
+                indent=4,
+                sort_keys=True,
+            )
+        )
 
 
 def reuse_cache(state: MkosiState) -> bool:
@@ -1874,7 +1890,7 @@ def reuse_cache(state: MkosiState) -> bool:
 
     if manifest.exists():
         prev = json.loads(manifest.read_text())
-        if prev != state.config.cache_manifest():
+        if prev != json.loads(json.dumps(state.config.cache_manifest(), cls=MkosiJsonEncoder)):
             return False
     else:
         return False
index d14fc242cb3f35b7c94cd403adee3399f969c3bb..f22d9e4a5d239b7d02487c86bebd1e7f4bdba547 100644 (file)
@@ -929,6 +929,9 @@ class MkosiConfig:
 
     def cache_manifest(self) -> dict[str, Any]:
         return {
+            "distribution": self.distribution,
+            "release": self.release,
+            "architecture": self.architecture,
             "packages": self.packages,
             "build_packages": self.build_packages,
             "repositories": self.repositories,