]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Stop using subdirectories of cache and build dirs automatically
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 20 Oct 2023 19:21:18 +0000 (21:21 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 28 Oct 2023 09:08:12 +0000 (11:08 +0200)
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.

NEWS.md
mkosi.conf.d/10-common.conf
mkosi.conf.d/30-dirs.conf [new file with mode: 0644]
mkosi/__init__.py
mkosi/config.py

diff --git a/NEWS.md b/NEWS.md
index c69036a420abc6be6a68b3ec5634c3a850b6d984..5a122c60c8ad63a6a9856c17ad0adfcc9908df0b 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 - 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
 
index 2dfd35f1a1fe9e37277f80edd60ade7f3fdb9688..5b88de6caf46738a7ef314a2dfe071f31f1faff8 100644 (file)
@@ -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 (file)
index 0000000..c90d8a8
--- /dev/null
@@ -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
index 3f2510a9c51c1ef0741ef814c9be5d768a6ff2c1..b133b4dda5e9c0a38b301726295a03fdee933505 100644 (file)
@@ -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",
index c45f2d2b754588f2297e1fcb2496999059e3f8c2..72a781c08fd9d830a389c1c670eada3c641cc84d 100644 (file)
@@ -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