Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CacheKey config to override cache_tree_paths #2862

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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