]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only use tools trees for verbs that need a build 2316/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 22 Jan 2024 19:51:00 +0000 (20:51 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 23 Jan 2024 10:53:02 +0000 (11:53 +0100)
Currently we try to use a tools tree that isn't there for verbs
that don't need a build. Let's instead opt to not use one altogether
since building an entire image just to run ssh is kind of overkill.

mkosi/__init__.py
mkosi/resources/mkosi.md

index 4d15cde2cfd074235bf05caf3cd5b7a102af9b7b..736d8f7988735254ed48dc7755b64d3084310dcd 100644 (file)
@@ -3518,18 +3518,16 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
         page(text, args.pager)
         return
 
-    for config in images:
-        if not config.minimum_version or config.minimum_version <= __version__:
-            continue
-
-        die(f"mkosi {config.minimum_version} or newer is required to build this configuration (found {__version__})")
+    if args.verb in (Verb.journalctl, Verb.coredumpctl, Verb.ssh):
+        # We don't use a tools tree for verbs that don't need an image build.
+        last = dataclasses.replace(images[-1], tools_tree=None)
+        return {
+            Verb.ssh: run_ssh,
+            Verb.journalctl: run_journalctl,
+            Verb.coredumpctl: run_coredumpctl,
+        }[args.verb](args, last)
 
-    for config in images:
-        if not config.repart_offline and os.getuid() != 0:
-            die(f"Must be root to build {config.name()} image configured with RepartOffline=no")
-
-    for config in images:
-        check_workspace_directory(config)
+    assert args.verb.needs_build() or args.verb == Verb.clean
 
     for config in images:
         if args.verb == Verb.build and not args.force:
@@ -3537,12 +3535,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
 
     # First, process all directory removals because otherwise if different images share directories a later
     # image build could end up deleting the output generated by an earlier image build.
-    tools: Optional[Config]
-
     for config in images:
-        if not args.verb.needs_build() and args.verb != Verb.clean:
-            continue
-
         if config.tools_tree and config.tools_tree == Path("default"):
             fork_and_wait(run_clean, args, finalize_default_tools(args, config, resources=resources))
 
@@ -3551,12 +3544,18 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
     if args.verb == Verb.clean:
         return
 
+    for config in images:
+        if (minversion := config.minimum_version) and minversion <= __version__:
+            die(f"mkosi {minversion} or newer is required to build this configuration (found {__version__})")
+
+        if not config.repart_offline and os.getuid() != 0:
+            die(f"Must be root to build {config.name()} image configured with RepartOffline=no")
+
+        check_workspace_directory(config)
+
     build = False
 
     for i, config in enumerate(images):
-        if not args.verb.needs_build():
-            continue
-
         tools = (
             finalize_default_tools(args, config, resources=resources)
             if config.tools_tree and config.tools_tree == Path("default")
@@ -3598,9 +3597,6 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
                 Verb.shell: run_shell,
                 Verb.boot: run_shell,
                 Verb.qemu: run_qemu,
-                Verb.ssh: run_ssh,
                 Verb.serve: run_serve,
-                Verb.journalctl: run_journalctl,
-                Verb.coredumpctl: run_coredumpctl,
                 Verb.burn: run_burn,
             }[args.verb](args, last)
index 7c3a83e60772cff39c4c56022a42bd51e0a5fff3..4177ced9a6c1894b7ecc8ac5016411118783ef5f 100644 (file)
@@ -1486,12 +1486,12 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 
 `ToolsTree=`, `--tools-tree=`
 
-: If specified, programs executed by mkosi are looked up inside the
-  given tree instead of in the host system. Use this option to make
-  image builds more reproducible by always using the same versions of
-  programs to build the final image instead of whatever version is
-  installed on the host system. If this option is not used, but the
-  `mkosi.tools/` directory is found in the local directory it is
+: If specified, programs executed by mkosi to build and boot an image
+  are looked up inside the given tree instead of in the host system. Use
+  this option to make image builds more reproducible by always using the
+  same versions of programs to build the final image instead of whatever
+  version is installed on the host system. If this option is not used,
+  but the `mkosi.tools/` directory is found in the local directory it is
   automatically used for this purpose with the root directory as target.
   Note that when looking up binaries in `--tools-tree=`, only `/usr/bin`
   and `/usr/sbin` are considered. Specifically, paths specified by