]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move Gentoo to DistributionInstaller
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 23 Nov 2022 13:57:06 +0000 (14:57 +0100)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 24 Nov 2022 14:51:33 +0000 (15:51 +0100)
mkosi/__init__.py
mkosi/distributions/gentoo.py [moved from mkosi/gentoo.py with 94% similarity]

index a22742c0aa750de415dadd67cbe7f72ea5924119..c5b2eb2cf68882f7ae085a6b7487f2dc5a9226aa 100644 (file)
@@ -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"
 
similarity index 94%
rename from mkosi/gentoo.py
rename to mkosi/distributions/gentoo.py
index 8b8cf90a0b3caf212fbdfabced2e6e94389c9957..bb262cb8b93098e97dc105d21c39159e17c2878f 100644 (file)
@@ -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)