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 committed Jul 11, 2024
1 parent 4723d55 commit ecf2da7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ def finalize_default_initrd(
*(["--output-dir", str(output_dir)] if output_dir else []),
*(["--workspace-dir", str(config.workspace_dir)] if config.workspace_dir else []),
*(["--cache-dir", str(config.cache_dir)] if config.cache_dir else []),
*(["--cache-key", config.cache_key]),
*(["--package-cache-dir", str(config.package_cache_dir)] if config.package_cache_dir else []),
*(["--local-mirror", str(config.local_mirror)] if config.local_mirror else []),
"--incremental", str(config.incremental),
Expand Down Expand Up @@ -2776,7 +2777,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
14 changes: 14 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ class ConfigSetting:
default: Any = None
default_factory: Optional[ConfigDefaultCallback] = None
default_factory_depends: tuple[str, ...] = tuple()
default_expand_specifiers: bool = False
paths: tuple[str, ...] = ()
path_read_text: bool = False
path_secret: bool = False
Expand Down Expand Up @@ -1399,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 @@ -2057,6 +2059,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="%d~%r~%a",
default_expand_specifiers=True,
help="Key to use inside incremental cache directory",
universal=True,
),
ConfigSetting(
dest="package_cache_dir",
metavar="PATH",
Expand Down Expand Up @@ -3525,6 +3535,9 @@ def finalize_value(setting: ConfigSetting) -> Optional[Any]:
else:
default = setting.parse(None, None)

if setting.default_expand_specifiers:
default = expand_specifiers(default, ParseContext.cli.directory)

setattr(ParseContext.config, setting.dest, default)

return default
Expand Down Expand Up @@ -4046,6 +4059,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 @@ -371,6 +372,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 ecf2da7

Please sign in to comment.