From: Daan De Meyer Date: Fri, 20 Oct 2023 19:21:18 +0000 (+0200) Subject: Stop using subdirectories of cache and build dirs automatically X-Git-Tag: v19~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b17810b4b571d0acbb307a6f7cd5c6456a45e4d3;p=thirdparty%2Fmkosi.git Stop using subdirectories of cache and build dirs automatically In some cases, for example mkosi-initrd running as a kernel-install script, we want to reuse the system package cache. Currently this is impossible as we unconditionally create a subdirectory beneath the provided cache directory. Let's stop doing that, as users can now explicitly configure this behavior themselves by specifying the cache directory or build directory as follows: ``` CacheDirectory=mkosi.cache/%d~%r~%a BuildDirectory=mkosi.builddir/%d~%r~%a ``` Additionally, make sure the default tools tree only reuses the same cache as the preset it's used for when the distribution, release and architecture are the same as the preset's. --- diff --git a/NEWS.md b/NEWS.md index c69036a42..5a122c60c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -36,6 +36,14 @@ - We now automatically configure the qemu firmware, kernel cmdline and initrd based on what type of kernel is passed by the user via `-kernel` or `QemuKernel=` +- We don't create subdirectories beneath the configured cache or build + directories anymore. To get back the previous behavior, configure the + cache and build directories as follows: + + ```conf + CacheDirectory=mkosi.cache/%d~%r~%a + BuildDirectory=mkosi.builddir/%d~%r~%a + ``` ## v18 diff --git a/mkosi.conf.d/10-common.conf b/mkosi.conf.d/10-common.conf index 2dfd35f1a..5b88de6ca 100644 --- a/mkosi.conf.d/10-common.conf +++ b/mkosi.conf.d/10-common.conf @@ -4,8 +4,6 @@ # 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 -@OutputDirectory=mkosi.output [Content] Autologin=yes diff --git a/mkosi.conf.d/30-dirs.conf b/mkosi.conf.d/30-dirs.conf new file mode 100644 index 000000000..c90d8a8e7 --- /dev/null +++ b/mkosi.conf.d/30-dirs.conf @@ -0,0 +1,8 @@ +# 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 3f2510a9c..b133b4dda 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -21,6 +21,7 @@ from collections.abc import Iterator, Mapping, Sequence from pathlib import Path from typing import Optional, TextIO, Union +from mkosi.architecture import Architecture from mkosi.archive import extract_tar, make_cpio, make_tar from mkosi.config import ( BiosBootloader, @@ -1087,7 +1088,7 @@ def build_initrd(state: MkosiState) -> Path: "--cache-only", str(state.config.cache_only), "--output-dir", str(state.workspace / "initrd"), *(["--workspace-dir", str(state.config.workspace_dir)] if state.config.workspace_dir else []), - "--cache-dir", str(state.cache_dir.parent), + "--cache-dir", str(state.cache_dir), *(["--local-mirror", str(state.config.local_mirror)] if state.config.local_mirror else []), "--incremental", str(state.config.incremental), "--acl", str(state.config.acl), @@ -2440,6 +2441,14 @@ def finalize_tools(args: MkosiArgs, images: Sequence[MkosiConfig]) -> Sequence[M release = p.tools_tree_release or distribution.default_release() mirror = p.tools_tree_mirror or (p.mirror if p.mirror and p.distribution == distribution else None) + if p.cache_dir: + if p.distribution == distribution and p.release == release and p.architecture == Architecture.native(): + cache = p.cache_dir + else: + cache = p.cache_dir / "tools" + else: + cache = None + cmdline = [ "--directory", "", "--distribution", str(distribution), @@ -2449,7 +2458,7 @@ def finalize_tools(args: MkosiArgs, images: Sequence[MkosiConfig]) -> Sequence[M "--cache-only", str(p.cache_only), *(["--output-dir", str(p.output_dir)] if p.output_dir else []), *(["--workspace-dir", str(p.workspace_dir)] if p.workspace_dir else []), - *(["--cache-dir", str(p.cache_dir.parent)] if p.cache_dir else []), + *(["--cache-dir", str(cache)] if cache else []), "--incremental", str(p.incremental), "--acl", str(p.acl), "--format", "directory", diff --git a/mkosi/config.py b/mkosi/config.py index c45f2d2b7..72a781c08 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -2595,11 +2595,6 @@ def load_config(args: argparse.Namespace) -> MkosiConfig: if args.cmdline and not args.verb.supports_cmdline(): die(f"Arguments after verb are not supported for {args.verb}.") - if args.cache_dir: - args.cache_dir = args.cache_dir / f"{args.distribution}~{args.release}~{args.architecture}" - if args.build_dir: - args.build_dir = args.build_dir / f"{args.distribution}~{args.release}~{args.architecture}" - if args.sign: args.checksum = True