]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Always use a distro~release subdirectory for output, cache, builddir
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 9 Aug 2022 18:18:12 +0000 (20:18 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 Aug 2022 13:49:35 +0000 (15:49 +0200)
Let's be consistent and always use a distro~release subdirectory for
these directories, instead of only using these when the correct directory
exists in the directory mkosi is invoked from.

NEWS.md
mkosi.md
mkosi/__init__.py

diff --git a/NEWS.md b/NEWS.md
index 09cb3fcce78f10881223684655f171f9bd8f2f72..d92ef976825a15a9791a94518a14918c9e94e948 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -10,10 +10,10 @@ for more information.
 wants to use them, they can be found [here](https://github.com/systemd/mkosi/tree/v13/mkosi/resources/arch).
 When building a bios image, /boot/vmlinuz-kver and /boot/initramfs-kver.img are
 now symlinks to the actual files as installed by kernel-install.
-- When mkosi.output/ or mkosi.builddir/ are used, mkosi now creates distro~release
-subdirectories inside these directories for each distro~release combination that
-is built. This allows building for multiple distros without throwing away the results
-of a previous distro build every time.
+- mkosi now creates distro~release subdirectories inside the build, cache and output
+directories for each distro~release combination that is built. This allows building
+for multiple distros without throwing away the results of a previous distro build every
+time.
 - The preferred names for mkosi configuration files and directories are now mkosi.conf
 and mkosi.conf.d/ respectively. The old names (mkosi.default and mkosi.default.d) have
 been removed from the docs but are still supported for backwards compatibility.
index 8b2df72635d0e0a3ae3999fa512e19db5c4678b3..08a6e82ba5bdf74e6393c1453a216f80855d20b4 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -398,7 +398,9 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
   exists in the local directory, it is automatically used for this
   purpose. If the setting is not used and `mkosi.output/` does not
   exist, all output artifacts are placed adjacent to the output image
-  file.
+  file. If an output directory is configured, mkosi will create
+  `distro~release` subdirectories in it to store the artfifacts per
+  distro, release combination that's built.
 
 `WorkspaceDirectory=`, `--workspace-dir=`
 
index 3f7909520432902e6ddedba008c5ec826a4bb5ae..f0f4e09758ccf9b58091f9df39c1b77f51e10c92 100644 (file)
@@ -6180,29 +6180,42 @@ def args_find_path(args: argparse.Namespace, name: str, path: str, *, as_list: b
 
 
 def find_output(args: argparse.Namespace) -> None:
+    subdir = f"{args.distribution}~{args.release}"
+
     if args.output_dir is not None:
+        args.output_dir = Path(args.output_dir, subdir)
+    elif os.path.exists("mkosi.output/"):
+        args.output_dir = Path("mkosi.output", subdir)
+    else:
         return
 
-    if os.path.exists("mkosi.output/"):
-        args.output_dir = Path("mkosi.output", f"{args.distribution}~{args.release}")
-        args.output_dir.mkdir(exist_ok=True)
+    args.output_dir.mkdir(parents=True, exist_ok=True)
 
 
 def find_builddir(args: argparse.Namespace) -> None:
+    subdir = f"{args.distribution}~{args.release}"
+
     if args.build_dir is not None:
+        args.build_dir = Path(args.build_dir, subdir)
+    elif os.path.exists("mkosi.builddir/"):
+        args.build_dir = Path("mkosi.builddir", subdir)
+    else:
         return
 
-    if os.path.exists("mkosi.builddir/"):
-        args.build_dir = Path("mkosi.builddir", f"{args.distribution}~{args.release}")
-        args.build_dir.mkdir(exist_ok=True)
+    args.build_dir.mkdir(parents=True, exist_ok=True)
 
 
 def find_cache(args: argparse.Namespace) -> None:
+    subdir = f"{args.distribution}~{args.release}"
+
     if args.cache_path is not None:
+        args.cache_path = Path(args.cache_path, subdir)
+    elif os.path.exists("mkosi.cache/"):
+        args.cache_path = Path("mkosi.cache", subdir)
+    else:
         return
 
-    if os.path.exists("mkosi.cache/"):
-        args.cache_path = Path("mkosi.cache", f"{args.distribution}~{args.release}")
+    args.cache_path.mkdir(parents=True, exist_ok=True)
 
 
 def require_private_file(name: str, description: str) -> None: