From: Daan De Meyer Date: Mon, 22 Jan 2024 19:51:00 +0000 (+0100) Subject: Only use tools trees for verbs that need a build X-Git-Tag: v21~96^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2316%2Fhead;p=thirdparty%2Fmkosi.git Only use tools trees for verbs that need a build 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 4d15cde2c..736d8f798 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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) diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 7c3a83e60..4177ced9a 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -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