Skip to content

Commit

Permalink
Add CacheKey config to override cache_tree_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dzil123 authored and DaanDeMeyer committed Jul 17, 2024
1 parent 18dc79b commit 4c8af43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4c8af43

Please sign in to comment.