From: Joerg Behrmann Date: Wed, 23 Nov 2022 13:57:06 +0000 (+0100) Subject: Move Gentoo to DistributionInstaller X-Git-Tag: v15~384^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4873bb94bc659bafc85aa3f043fb53882394e31;p=thirdparty%2Fmkosi.git Move Gentoo to DistributionInstaller --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a22742c0a..c5b2eb2cf 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1396,8 +1396,6 @@ def mount_cache(state: MkosiState) -> Iterator[None]: # We mount both the YUM and the DNF cache in this case, as YUM might # just be redirected to DNF even if we invoke the former cache_paths = ["var/cache/yum", "var/cache/dnf"] - elif state.config.distribution == Distribution.gentoo: - cache_paths = ["var/cache/binpkgs"] else: cache_paths = [] @@ -2158,29 +2156,6 @@ def install_centos_variant(state: MkosiState) -> None: run_workspace_command(state, cmdline) -@complete_step("Installing Gentoo…") -def install_gentoo(state: MkosiState) -> None: - from .gentoo import Gentoo - - # this will fetch/fix stage3 tree and portage confgired for mkosi - gentoo = Gentoo(state) - - if gentoo.pkgs_fs: - gentoo.invoke_emerge(state, pkgs=gentoo.pkgs_fs) - - if not state.do_run_build_script and state.config.bootable: - # The gentoo stage3 tarball includes packages that may block chosen - # pkgs_boot. Using Gentoo.EMERGE_UPDATE_OPTS for opts allows the - # package manager to uninstall blockers. - gentoo.invoke_emerge(state, pkgs=gentoo.pkgs_boot, opts=Gentoo.EMERGE_UPDATE_OPTS) - - if state.config.packages: - gentoo.invoke_emerge(state, pkgs=state.config.packages) - - if state.do_run_build_script: - gentoo.invoke_emerge(state, pkgs=state.config.build_packages) - - def install_distribution(state: MkosiState, cached: bool) -> None: if cached: return @@ -2196,7 +2171,6 @@ def install_distribution(state: MkosiState, cached: bool) -> None: Distribution.fedora: install_fedora, Distribution.mageia: install_mageia, Distribution.openmandriva: install_openmandriva, - Distribution.gentoo: install_gentoo, }[state.config.distribution] with mount_cache(state): @@ -3109,12 +3083,6 @@ def gen_kernel_images(state: MkosiState) -> Iterator[Tuple[str, Path]]: if state.installer is not None: kimg = state.installer.kernel_image(kver.name, state.config.architecture) - elif state.config.distribution == Distribution.gentoo: - from .gentoo import ARCHITECTURES - - _, kimg_path = ARCHITECTURES[state.config.architecture] - - kimg = Path(f"usr/src/linux-{kver.name}") / kimg_path else: kimg = Path("lib/modules") / kver.name / "vmlinuz" diff --git a/mkosi/gentoo.py b/mkosi/distributions/gentoo.py similarity index 94% rename from mkosi/gentoo.py rename to mkosi/distributions/gentoo.py index 8b8cf90a0..bb262cb8b 100644 --- a/mkosi/gentoo.py +++ b/mkosi/distributions/gentoo.py @@ -20,11 +20,13 @@ from mkosi.backend import ( MkosiState, OutputFormat, PartitionIdentifier, + complete_step, die, root_home, run_workspace_command, safe_tar_extract, ) +from mkosi.distributions import DistributionInstaller from mkosi.install import copy_path, open_close ARCHITECTURES = { @@ -546,3 +548,35 @@ class Gentoo: network=True, nspawn_params=self.DEFAULT_NSPAWN_PARAMS, ) + + +class GentooInstaller(DistributionInstaller): + @classmethod + def cache_path(cls) -> List[str]: + return ["var/cache/binpkgs"] + + @staticmethod + def kernel_image(name: str, architecture: str) -> Path: + _, kimg_path = ARCHITECTURES[architecture] + return Path(f"usr/src/linux-{name}") / kimg_path + + @classmethod + @complete_step("Installing Gentoo…") + def install(cls, state: "MkosiState") -> None: + # this will fetch/fix stage3 tree and portage confgired for mkosi + gentoo = Gentoo(state) + + if gentoo.pkgs_fs: + gentoo.invoke_emerge(state, pkgs=gentoo.pkgs_fs) + + if not state.do_run_build_script and state.config.bootable: + # The gentoo stage3 tarball includes packages that may block chosen + # pkgs_boot. Using Gentoo.EMERGE_UPDATE_OPTS for opts allows the + # package manager to uninstall blockers. + gentoo.invoke_emerge(state, pkgs=gentoo.pkgs_boot, opts=Gentoo.EMERGE_UPDATE_OPTS) + + if state.config.packages: + gentoo.invoke_emerge(state, pkgs=state.config.packages) + + if state.do_run_build_script: + gentoo.invoke_emerge(state, pkgs=state.config.build_packages)