From: Daan De Meyer Date: Tue, 20 Jun 2023 15:40:49 +0000 (+0200) Subject: Add "none" output format X-Git-Tag: v15~108^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1635%2Fhead;p=thirdparty%2Fmkosi.git Add "none" output format This is a re-implementation of the --skip-final-phase option, but instead of doing it via an option, we do it via a new output format, which feels much more natural. In combination with mounting the staging directory into the build script, this allows using mkosi to produce arbitrary artifacts using the build script. --- diff --git a/mkosi.md b/mkosi.md index 9cc16085f..a4cdbde72 100644 --- a/mkosi.md +++ b/mkosi.md @@ -399,7 +399,9 @@ they should be specified with a boolean argument: either "1", "yes", or "true" t : The image format type to generate. One of `directory` (for generating OS images inside a local directory), `tar` (similar, but a tarball of the image is generated), `cpio` (similar, but a cpio archive is generated), - `disk` (a block device image with a GPT partition table). + `disk` (a block device image with a GPT partition table) or `none` + (the image is solely intended as a build image to produce another + artifact). `ManifestFormat=`, `--manifest-format=` diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 23008cd06..9ee596aff 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1692,6 +1692,14 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False) return f"roothash={roothash}" if roothash else f"usrhash={usrhash}" if usrhash else None, split_paths +def finalize_staging(state: MkosiState) -> None: + for f in state.staging.iterdir(): + if not f.is_dir(): + os.chown(f, state.uid, state.gid) + + shutil.move(f, state.config.output_dir) + + def build_image(args: MkosiArgs, config: MkosiConfig, uid: int, gid: int) -> None: state = MkosiState(args, config, uid, gid) manifest = Manifest(config) @@ -1719,6 +1727,11 @@ def build_image(args: MkosiArgs, config: MkosiConfig, uid: int, gid: int) -> Non configure_autologin(state) configure_initrd(state) run_build_script(state) + + if state.config.output_format == OutputFormat.none: + finalize_staging(state) + return + install_build_dest(state) install_extra_trees(state) install_boot_loader(state) @@ -1759,11 +1772,7 @@ def build_image(args: MkosiArgs, config: MkosiConfig, uid: int, gid: int) -> Non calculate_signature(state) save_manifest(state, manifest) - for f in state.staging.iterdir(): - if not f.is_dir(): - os.chown(f, uid, gid) - - shutil.move(f, state.config.output_dir) + finalize_staging(state) output_base = state.config.output_dir.joinpath(state.config.output) if not output_base.exists() or output_base.is_symlink(): diff --git a/mkosi/util.py b/mkosi/util.py index 546df0cc7..2317e2cab 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -174,6 +174,7 @@ class OutputFormat(str, enum.Enum): tar = "tar" cpio = "cpio" disk = "disk" + none = "none" class ManifestFormat(str, enum.Enum):