From 4c8af43dbdce43793f5a4f8867c63e7ca8e3ac7b Mon Sep 17 00:00:00 2001 From: dzil123 <5725958+dzil123@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:15:54 -0700 Subject: [PATCH] Add CacheKey config to override cache_tree_paths --- mkosi/__init__.py | 2 +- mkosi/config.py | 10 ++++++++++ tests/test_json.py | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 81b9f26a4..c2b08b71d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2805,7 +2805,7 @@ def print_output_size(path: Path) -> None: def cache_tree_paths(config: Config) -> tuple[Path, Path, Path]: - fragments = [config.distribution, config.release, config.architecture] + fragments = [config.cache_key] if config.image: fragments += [config.image] diff --git a/mkosi/config.py b/mkosi/config.py index c4dde5bfd..d88065962 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1400,6 +1400,7 @@ class Config: output_dir: Optional[Path] workspace_dir: Optional[Path] cache_dir: Optional[Path] + cache_key: str package_cache_dir: Optional[Path] build_dir: Optional[Path] image_id: Optional[str] @@ -2065,6 +2066,14 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple help="Incremental cache directory", universal=True, ), + ConfigSetting( + dest="cache_key", + section="Output", + default_factory=lambda ns: f"{ns.distribution}~{ns.release}~{ns.architecture}", + default_factory_depends=("distribution", "release", "architecture"), + help="Key to use inside incremental cache directory", + universal=True, + ), ConfigSetting( dest="package_cache_dir", metavar="PATH", @@ -4073,6 +4082,7 @@ def bold(s: Any) -> str: Output Directory: {config.output_dir_or_cwd()} Workspace Directory: {config.workspace_dir_or_default()} Cache Directory: {none_to_none(config.cache_dir)} + Cache Key: {config.cache_key} Package Cache Directory: {none_to_default(config.package_cache_dir)} Build Directory: {none_to_none(config.build_dir)} Image ID: {config.image_id} diff --git a/tests/test_json.py b/tests/test_json.py index 43a51f1ab..0e8a5099d 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -109,6 +109,7 @@ def test_config() -> None: ], "BuildSourcesEphemeral": true, "CacheDirectory": "/is/this/the/cachedir", + "CacheKey": "my_cache_key", "CacheOnly": "always", "Checksum": false, "CleanPackageMetadata": "auto", @@ -374,6 +375,7 @@ def test_config() -> None: build_sources=[ConfigTree(Path("/qux"), Path("/frob"))], build_sources_ephemeral=True, cache_dir=Path("/is/this/the/cachedir"), + cache_key="my_cache_key", cacheonly=Cacheonly.always, checksum= False, clean_package_metadata=ConfigFeature.auto,