From: Paymon MARANDI Date: Sun, 11 Jun 2023 15:24:06 +0000 (-0400) Subject: gentoo: remove indirections, use state.config.mirror itself X-Git-Tag: v15~103^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=431d6ab7bcc495b46d1c48f47201c8d42dba8a80;p=thirdparty%2Fmkosi.git gentoo: remove indirections, use state.config.mirror itself Signed-off-by: Paymon MARANDI --- diff --git a/mkosi/config.py b/mkosi/config.py index 2d1b009d2..e1b00364e 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -257,6 +257,8 @@ def config_default_mirror(namespace: argparse.Namespace) -> Optional[str]: return "https://download.opensuse.org" elif d == Distribution.fedora and r == "eln": return "https://odcs.fedoraproject.org/composes/production/latest-Fedora-ELN/compose" + elif d == Distribution.gentoo: + return "https://distfiles.gentoo.org" return None diff --git a/mkosi/distributions/gentoo.py b/mkosi/distributions/gentoo.py index 2d18e8212..41ce6b86c 100644 --- a/mkosi/distributions/gentoo.py +++ b/mkosi/distributions/gentoo.py @@ -7,7 +7,6 @@ import urllib.request from collections.abc import Sequence from pathlib import Path from textwrap import dedent -from typing import Optional from mkosi.architecture import Architecture from mkosi.distributions import DistributionInstaller @@ -21,25 +20,21 @@ from mkosi.types import PathString def invoke_emerge( state: MkosiState, - sysroot: Optional[Path] = None, - bwrap_params: list[PathString] = [], + sysroot: Path, pkgs: Sequence[str] = (), actions: Sequence[str] = (), opts: Sequence[str] = (), env: dict[str, str] = {}, ) -> None: thread_counts = (os.cpu_count() or 1) * 2 # * 2 for hyperthreading - bwrap: list[PathString] = [] - root: Optional[Path] = None - if sysroot is not None: - # This is the mount-point inside our sysroot where we mount root - target_root_mntp = "/tmp/mkosi-root" - bwrap += ["--bind", state.root, target_root_mntp] - root = Path(target_root_mntp) - else: - sysroot = state.root - - emerge_default_opts = [ + # This is the mount-point inside our sysroot where we mount root + target_root_mntp = "/tmp/mkosi-root" + bwrap: list[PathString] = ["--bind", state.root, target_root_mntp] + root = Path(target_root_mntp) + + cmd = [ + "emerge", + *pkgs, "--buildpkg=y", "--usepkg=y", "--keep-going=y", @@ -49,15 +44,14 @@ def invoke_emerge( *([f"--root={root}"] if root else []), ] if ARG_DEBUG.get(): - emerge_default_opts += ["--verbose", "--quiet=n", "--quiet-fail=n"] + cmd += ["--verbose", "--quiet=n", "--quiet-fail=n"] else: - emerge_default_opts += ["--quiet-build", "--quiet"] - cmd = ["emerge", *pkgs, *emerge_default_opts, *opts, *actions] + cmd += ["--quiet-build", "--quiet"] + cmd += [*opts, *actions] bwrap += [ "--bind", state.cache_dir / "binpkgs", "/var/cache/binpkgs", "--bind", state.cache_dir / "distfiles", "/var/cache/distfiles", "--bind", state.cache_dir / "repos", "/var/db/repos", - *bwrap_params ] run_workspace_command(sysroot, cmd, bwrap_params=bwrap, network=True, env=env) @@ -89,12 +83,10 @@ class GentooInstaller(DistributionInstaller): """usrmerge tracker bug: https://bugs.gentoo.org/690294""" - gentoo_mirrors = "http://distfiles.gentoo.org" - if state.config.mirror: - gentoo_mirrors = state.config.mirror + assert state.config.mirror # http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3.txt stage3tsf_path_url = urllib.parse.urljoin( - gentoo_mirrors.partition(" ")[0], + state.config.mirror.partition(" ")[0], f"releases/{arch}/autobuilds/latest-stage3.txt", ) @@ -119,31 +111,11 @@ class GentooInstaller(DistributionInstaller): user_config_path = cls.stage3_cache / USER_CONFIG_PATH - emerge_vars = { - "FEATURES": " ".join([ - # -user* are required for access to USER_CONFIG_PATH - "-userfetch", - "-userpriv", - "-usersync", - "-usersandbox", - "-sandbox", - "-pid-sandbox", # for cross-compile scenarios - "-network-sandbox", - "parallel-install", - "getbinpkg", - "-candy", - "noman", - "nodoc", - "noinfo", - ]), - "USE": "initramfs symlink" - } - for d in ("binpkgs", "distfiles", "repos"): state.cache_dir.joinpath(d).mkdir(exist_ok=True) stage3_url_path = urllib.parse.urljoin( - gentoo_mirrors, f"releases/{arch}/autobuilds/{stage3_tar}", + state.config.mirror, f"releases/{arch}/autobuilds/{stage3_tar}", ) if not stage3_tar_path.is_file(): log_step(f"Fetching {stage3_url_path}") @@ -152,18 +124,19 @@ class GentooInstaller(DistributionInstaller): cls.stage3_cache.mkdir(parents=True, exist_ok=True) - log_step(f"Extracting {stage3_tar.name} to {cls.stage3_cache}") - run([ - "tar", - "--numeric-owner", - "-C", cls.stage3_cache, - "--extract", - "--file", stage3_tar_path, - "--exclude", "./dev", - ]) - unlink_try_hard(cls.stage3_cache.joinpath("dev")) - unlink_try_hard(cls.stage3_cache.joinpath("proc")) - unlink_try_hard(cls.stage3_cache.joinpath("sys")) + with complete_step(f"Extracting {stage3_tar.name} to {cls.stage3_cache}"): + run([ + "tar", + "--numeric-owner", + "-C", cls.stage3_cache, + "--extract", + "--file", stage3_tar_path, + "--exclude", "./dev", + ]) + + unlink_try_hard(cls.stage3_cache.joinpath("dev")) + unlink_try_hard(cls.stage3_cache.joinpath("proc")) + unlink_try_hard(cls.stage3_cache.joinpath("sys")) package_use = user_config_path / "package.use" package_use.mkdir(exist_ok=True) @@ -189,15 +162,14 @@ class GentooInstaller(DistributionInstaller): """ ) ) - if state.config.make_initrd: - package_use.joinpath("minimal").write_text( - dedent( - """\ - # MKOSI - */* minimal - """ - ) + package_use.joinpath("minimal").write_text( + dedent( + """\ + # MKOSI + */* minimal + """ ) + ) package_env = user_config_path / "package.env" package_env.mkdir(exist_ok=True) @@ -209,6 +181,23 @@ class GentooInstaller(DistributionInstaller): # we use this so we don't need to touch upstream files. # we also use this for documenting build environment. + emerge_vars = { + "FEATURES": " ".join([ + # -user* are required for access to USER_CONFIG_PATH + "-userfetch", + "-userpriv", + "-usersync", + "-usersandbox", + "-sandbox", + "-pid-sandbox", # for cross-compile scenarios + "-network-sandbox", + "parallel-install", + "getbinpkg", + "-candy", + *(["noman", "nodoc", "noinfo"] if state.config.with_docs else []), + ]), + "USE": "initramfs symlink" + } emerge_vars_str = "" emerge_vars_str += "\n".join(f'{k}="${{{k}}} {v}"' for k, v in emerge_vars.items()) @@ -222,8 +211,7 @@ class GentooInstaller(DistributionInstaller): ) ) - repos_cfg = cls.stage3_cache / BINREPOS_CONF_FILE - with repos_cfg.open(mode='a') as f: + with (cls.stage3_cache / BINREPOS_CONF_FILE).open(mode='a') as f: for repo in state.config.repositories: f.write( dedent( @@ -252,23 +240,27 @@ class GentooInstaller(DistributionInstaller): "--verbose-conflicts", "--changed-use", "--newuse", + "--root-deps=rdeps", ] - env = {} - env.update(emerge_vars) - env.update({"USE": f"{emerge_vars['USE']} build"}) - with complete_step("merging stage2"): - invoke_emerge(state, sysroot=cls.stage3_cache, opts=opts+["--emptytree", "--nodeps"], - pkgs=["sys-apps/baselayout", "sys-apps/util-linux"], env=env) - opts += ["--noreplace", "--root-deps=rdeps"] + with complete_step("Merging stage2"): + invoke_emerge(state, sysroot=cls.stage3_cache, + opts=opts+["--emptytree", "--nodeps"], + pkgs=["sys-apps/baselayout"], + env={**emerge_vars, 'USE': 'build'}) + + opts += ["--noreplace"] + with complete_step("Merging bare minimal atoms"): - invoke_emerge(state, sysroot=cls.stage3_cache, opts=opts+["--exclude", "sys-devel/*"], - pkgs=["app-shells/bash", "sys-apps/systemd"], env=emerge_vars) - with complete_step("Merging atoms required for boot"): - invoke_emerge(state, sysroot=cls.stage3_cache, opts=opts, - pkgs=["sys-kernel/gentoo-kernel-bin"]) + invoke_emerge(state, sysroot=cls.stage3_cache, + opts=opts+["--exclude", "sys-devel/*"], + pkgs=["app-shells/bash", "sys-apps/systemd"], + env=emerge_vars) + if state.config.make_initrd: return + invoke_emerge(state, sysroot=cls.stage3_cache, opts=opts, + pkgs=["sys-kernel/gentoo-kernel-bin"]) invoke_emerge(state, sysroot=cls.stage3_cache, opts=opts, pkgs=["@system"])