From: Daan De Meyer Date: Wed, 1 Nov 2023 11:49:52 +0000 (+0100) Subject: Fix incremental caching X-Git-Tag: v19~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4087f24b3328db57bb88b7c909c8d4a054e6eac;p=thirdparty%2Fmkosi.git Fix incremental caching - 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. --- diff --git a/mkosi.conf.d/10-common.conf b/mkosi.conf.d/10-common.conf index 5b88de6ca..e0e2f521d 100644 --- a/mkosi.conf.d/10-common.conf +++ b/mkosi.conf.d/10-common.conf @@ -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 index c90d8a8e7..000000000 --- a/mkosi.conf.d/30-dirs.conf +++ /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 diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 41ae721a4..0c54b19c9 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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 diff --git a/mkosi/config.py b/mkosi/config.py index d14fc242c..f22d9e4a5 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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,