From: Daan De Meyer Date: Sun, 16 Jul 2023 15:56:25 +0000 (+0200) Subject: Rename various "root" arguments to "tools" X-Git-Tag: v15~76^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41ef3c05e1d1caec39c9917b2776aee4f0c29599;p=thirdparty%2Fmkosi.git Rename various "root" arguments to "tools" "tools" is more descriptive than "root" about indicating that we're passing a tree of tools. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 3a87a8438..9cc3d3100 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -361,7 +361,7 @@ def run_finalize_script(state: MkosiState) -> None: with complete_step("Running finalize script…"): bwrap([state.config.finalize_script], - root=state.config.tools_tree, + tools=state.config.tools_tree, env={**state.environment, "BUILDROOT": str(state.root), "OUTPUTDIR": str(state.staging)}) @@ -373,7 +373,7 @@ def certificate_common_name(state: MkosiState, certificate: Path) -> str: "-subject", "-nameopt", "multiline", "-in", certificate, - ], root=state.config.tools_tree, stdout=subprocess.PIPE).stdout + ], tools=state.config.tools_tree, stdout=subprocess.PIPE).stdout for line in output.splitlines(): if not line.strip().startswith("commonName"): @@ -411,14 +411,14 @@ def pesign_prepare(state: MkosiState) -> None: "-out", state.workspace / "secure-boot.p12", "-inkey", state.config.secure_boot_key, "-in", state.config.secure_boot_certificate], - root=state.config.tools_tree) + tools=state.config.tools_tree) bwrap(["pk12util", "-K", "", "-W", "", "-i", state.workspace / "secure-boot.p12", "-d", state.workspace / "pesign"], - root=state.config.tools_tree) + tools=state.config.tools_tree) def install_boot_loader(state: MkosiState) -> None: @@ -459,7 +459,7 @@ def install_boot_loader(state: MkosiState) -> None: "--cert", state.config.secure_boot_certificate, "--output", output, input], - root=state.config.tools_tree) + tools=state.config.tools_tree) elif (state.config.secure_boot_sign_tool == SecureBootSignTool.pesign or state.config.secure_boot_sign_tool == SecureBootSignTool.auto and shutil.which("pesign") is not None): @@ -471,13 +471,13 @@ def install_boot_loader(state: MkosiState) -> None: "--force", "--in", input, "--out", output], - root=state.config.tools_tree) + tools=state.config.tools_tree) else: die("One of sbsign or pesign is required to use SecureBoot=") with complete_step("Installing boot loader…"): bwrap(["bootctl", "install", "--root", state.root, "--all-architectures"], - env={"SYSTEMD_ESP_PATH": "/efi"}, root=state.config.tools_tree) + env={"SYSTEMD_ESP_PATH": "/efi"}, tools=state.config.tools_tree) if state.config.secure_boot: assert state.config.secure_boot_key @@ -493,13 +493,13 @@ def install_boot_loader(state: MkosiState) -> None: "-outform", "DER", "-in", state.config.secure_boot_certificate, "-out", state.workspace / "mkosi.der"], - root=state.config.tools_tree) + tools=state.config.tools_tree) bwrap(["sbsiglist", "--owner", str(uuid.uuid4()), "--type", "x509", "--output", state.workspace / "mkosi.esl", state.workspace / "mkosi.der"], - root=state.config.tools_tree) + tools=state.config.tools_tree) # We reuse the key for all secure boot databases to keep things simple. for db in ["PK", "KEK", "db"]: @@ -511,7 +511,7 @@ def install_boot_loader(state: MkosiState) -> None: "--output", keys / f"{db}.auth", db, state.workspace / "mkosi.esl"], - root=state.config.tools_tree) + tools=state.config.tools_tree) def install_base_trees(state: MkosiState) -> None: @@ -526,7 +526,7 @@ def install_base_trees(state: MkosiState) -> None: shutil.unpack_archive(path, state.root) elif path.suffix == ".raw": bwrap(["systemd-dissect", "--copy-from", path, "/", state.root], - root=state.config.tools_tree) + tools=state.config.tools_tree) else: die(f"Unsupported base tree source {path}") @@ -544,7 +544,7 @@ def install_skeleton_trees(state: MkosiState) -> None: t.parent.mkdir(mode=0o755, parents=True, exist_ok=True) if source.is_dir() or target: - copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, tools=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -562,7 +562,7 @@ def install_package_manager_trees(state: MkosiState) -> None: t.parent.mkdir(mode=0o755, parents=True, exist_ok=True) if source.is_dir() or target: - copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, tools=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -580,7 +580,7 @@ def install_extra_trees(state: MkosiState) -> None: t.parent.mkdir(mode=0o755, parents=True, exist_ok=True) if source.is_dir() or target: - copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, tools=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -590,7 +590,7 @@ def install_build_dest(state: MkosiState) -> None: return with complete_step("Copying in build tree…"): - copy_path(state.install_dir, state.root, root=state.config.tools_tree) + copy_path(state.install_dir, state.root, tools=state.config.tools_tree) def gzip_binary() -> str: @@ -623,7 +623,7 @@ def make_tar(state: MkosiState) -> None: ] with complete_step("Creating archive…"): - bwrap(cmd, root=state.config.tools_tree) + bwrap(cmd, tools=state.config.tools_tree) def find_files(dir: Path, root: Path) -> Iterator[Path]: @@ -640,7 +640,7 @@ def make_initrd(state: MkosiState) -> None: def make_cpio(state: MkosiState, files: Iterator[Path], output: Path) -> None: - with complete_step(f"Creating cpio {output}…"), bwrap_cmd(root=state.config.tools_tree) as bwrap: + with complete_step(f"Creating cpio {output}…"), bwrap_cmd(tools=state.config.tools_tree) as bwrap: cmd: list[PathString] = [ *bwrap, "cpio", @@ -732,7 +732,7 @@ def resolve_module_dependencies(state: MkosiState, kver: str, modules: Sequence[ # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build two maps # that map the path of the module to its module dependencies and its firmware dependencies respectively. info = bwrap(["modinfo", "--basedir", state.root, "--set-version", kver, "--null", *nametofile.keys(), *builtin], - stdout=subprocess.PIPE, root=state.config.tools_tree).stdout + stdout=subprocess.PIPE, tools=state.config.tools_tree).stdout moddep = {} firmwaredep = {} @@ -994,7 +994,7 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None: if state.config.kernel_modules_initrd: cmd += [gen_kernel_modules_initrd(state, kver)] - bwrap(cmd, root=state.config.tools_tree) + bwrap(cmd, tools=state.config.tools_tree) if not state.staging.joinpath(state.config.output_split_uki).exists(): shutil.copy(boot_binary, state.staging / state.config.output_split_uki) @@ -1033,7 +1033,7 @@ def maybe_compress(state: MkosiState, compression: Compression, src: Path, dst: with dst.open("wb") as o: bwrap(compressor_command(compression), user=state.uid, group=state.gid, stdin=i, stdout=o, - root=state.config.tools_tree) + tools=state.config.tools_tree) def copy_nspawn_settings(state: MkosiState) -> None: @@ -1100,7 +1100,7 @@ def calculate_signature(state: MkosiState) -> None: Path(os.environ['HOME']).joinpath('.gnupg') ) }, - root=state.config.tools_tree, + tools=state.config.tools_tree, ) @@ -1510,23 +1510,23 @@ def run_depmod(state: MkosiState) -> None: process_kernel_modules(state, kver) with complete_step(f"Running depmod for {kver}"): - bwrap(["depmod", "--all", "--basedir", state.root, kver], root=state.config.tools_tree) + bwrap(["depmod", "--all", "--basedir", state.root, kver], tools=state.config.tools_tree) def run_sysusers(state: MkosiState) -> None: with complete_step("Generating system users"): - bwrap(["systemd-sysusers", "--root", state.root], root=state.config.tools_tree) + bwrap(["systemd-sysusers", "--root", state.root], tools=state.config.tools_tree) def run_preset(state: MkosiState) -> None: with complete_step("Applying presets…"): - bwrap(["systemctl", "--root", state.root, "preset-all"], root=state.config.tools_tree) + bwrap(["systemctl", "--root", state.root, "preset-all"], tools=state.config.tools_tree) def run_hwdb(state: MkosiState) -> None: with complete_step("Generating hardware database"): bwrap(["systemd-hwdb", "--root", state.root, "--usr", "--strict", "update"], - root=state.config.tools_tree) + tools=state.config.tools_tree) def run_firstboot(state: MkosiState) -> None: @@ -1561,7 +1561,7 @@ def run_firstboot(state: MkosiState) -> None: with complete_step("Applying first boot settings"): bwrap(["systemd-firstboot", "--root", state.root, "--force", *options], - root=state.config.tools_tree) + tools=state.config.tools_tree) # Initrds generally don't ship with only /usr so there's not much point in putting the credentials in # /usr/lib/credstore. @@ -1581,7 +1581,7 @@ def run_selinux_relabel(state: MkosiState) -> None: return policy = bwrap(["sh", "-c", f". {selinux} && echo $SELINUXTYPE"], - stdout=subprocess.PIPE, root=state.config.tools_tree).stdout.strip() + stdout=subprocess.PIPE, tools=state.config.tools_tree).stdout.strip() if not policy: return @@ -1730,7 +1730,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False) with complete_step("Generating disk image"): output = json.loads(bwrap(cmdline, stdout=subprocess.PIPE, env=env, - root=state.config.tools_tree).stdout) + tools=state.config.tools_tree).stdout) roothash = usrhash = None for p in output: @@ -1899,7 +1899,7 @@ def setfacl(config: MkosiConfig, root: Path, uid: int, allow: bool) -> None: "--modify" if allow else "--remove", f"user:{uid}:rwx" if allow else f"user:{uid}", "-"], - root=config.tools_tree, + tools=config.tools_tree, # Supply files via stdin so we don't clutter --debug run output too much input="\n".join([str(root), *(e.path for e in cast(Iterator[os.DirEntry[str]], scandir_recursive(root)) if e.is_dir())]) @@ -1917,7 +1917,7 @@ def acl_maybe_toggle(config: MkosiConfig, root: Path, uid: int, *, always: bool) has_acl = f"user:{uid}:rwx" in bwrap([ "getfacl", "-n", root.relative_to(Path.cwd())], stdout=subprocess.PIPE, - root=config.tools_tree, + tools=config.tools_tree, ).stdout if not has_acl and not always: @@ -2013,7 +2013,7 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: "--dry-run=no", "--offline=no", fname], - root=config.tools_tree) + tools=config.tools_tree) if config.output_format == OutputFormat.directory: cmdline += ["--directory", fname] @@ -2042,7 +2042,7 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: stdout=sys.stdout, env=os.environ, log=False, - root=config.tools_tree) + tools=config.tools_tree) def run_ssh(args: MkosiArgs, config: MkosiConfig) -> None: @@ -2058,7 +2058,7 @@ def run_ssh(args: MkosiArgs, config: MkosiConfig) -> None: cmd += args.cmdline - bwrap(cmd, stdin=sys.stdin, stdout=sys.stdout, env=os.environ, log=False, root=config.tools_tree) + bwrap(cmd, stdin=sys.stdin, stdout=sys.stdout, env=os.environ, log=False, tools=config.tools_tree) def run_serve(config: MkosiConfig) -> None: diff --git a/mkosi/btrfs.py b/mkosi/btrfs.py index 552a638cf..5b18a2f7a 100644 --- a/mkosi/btrfs.py +++ b/mkosi/btrfs.py @@ -13,7 +13,7 @@ from mkosi.run import bwrap def statfs(config: MkosiConfig, path: Path) -> str: return cast(str, bwrap(["stat", "--file-system", "--format", "%T", path.parent], - root=config.tools_tree, stdout=subprocess.PIPE).stdout.strip()) + tools=config.tools_tree, stdout=subprocess.PIPE).stdout.strip()) def btrfs_maybe_make_subvolume(config: MkosiConfig, path: Path, mode: int) -> None: @@ -30,7 +30,7 @@ def btrfs_maybe_make_subvolume(config: MkosiConfig, path: Path, mode: int) -> No if config.use_subvolumes != ConfigFeature.disabled and shutil.which("btrfs") is not None: result = bwrap(["btrfs", "subvolume", "create", path], check=config.use_subvolumes == ConfigFeature.enabled, - root=config.tools_tree).returncode + tools=config.tools_tree).returncode else: result = 1 @@ -49,7 +49,7 @@ def btrfs_maybe_snapshot_subvolume(config: MkosiConfig, src: Path, dst: Path) -> # Subvolumes always have inode 256 so we can use that to check if a directory is a subvolume. if not subvolume or statfs(config, src) != "btrfs" or src.stat().st_ino != 256 or (dst.exists() and any(dst.iterdir())): - return copy_path(src, dst, root=config.tools_tree) + return copy_path(src, dst, tools=config.tools_tree) # btrfs can't snapshot to an existing directory so make sure the destination does not exist. if dst.exists(): @@ -58,9 +58,9 @@ def btrfs_maybe_snapshot_subvolume(config: MkosiConfig, src: Path, dst: Path) -> if shutil.which("btrfs"): result = bwrap(["btrfs", "subvolume", "snapshot", src, dst], check=config.use_subvolumes == ConfigFeature.enabled, - root=config.tools_tree).returncode + tools=config.tools_tree).returncode else: result = 1 if result != 0: - copy_path(src, dst, root=config.tools_tree) + copy_path(src, dst, tools=config.tools_tree) diff --git a/mkosi/distributions/arch.py b/mkosi/distributions/arch.py index e582d2f84..4be0767a5 100644 --- a/mkosi/distributions/arch.py +++ b/mkosi/distributions/arch.py @@ -136,4 +136,4 @@ def invoke_pacman(state: MkosiState, packages: Sequence[str], apivfs: bool = Tru bwrap(cmdline, apivfs=state.root if apivfs else None, env=dict(KERNEL_INSTALL_BYPASS="1") | state.environment, - root=state.config.tools_tree) + tools=state.config.tools_tree) diff --git a/mkosi/distributions/debian.py b/mkosi/distributions/debian.py index cb196c9ba..769d194dd 100644 --- a/mkosi/distributions/debian.py +++ b/mkosi/distributions/debian.py @@ -93,9 +93,9 @@ class DebianInstaller(DistributionInstaller): for deb in essential: with tempfile.NamedTemporaryFile(dir=state.workspace) as f: - bwrap(["dpkg-deb", "--fsys-tarfile", deb], stdout=f, root=state.config.tools_tree) + bwrap(["dpkg-deb", "--fsys-tarfile", deb], stdout=f, tools=state.config.tools_tree) bwrap(["tar", "-C", state.root, "--keep-directory-symlink", "--extract", "--file", f.name], - root=state.config.tools_tree) + tools=state.config.tools_tree) # Finally, run apt to properly install packages in the chroot without having to worry that maintainer # scripts won't find basic tools that they depend on. @@ -247,7 +247,7 @@ def invoke_apt( return bwrap(["apt-get", *options, operation, *extra], apivfs=state.root if apivfs else None, env=env | state.environment, - root=state.config.tools_tree) + tools=state.config.tools_tree) def install_apt_sources(state: MkosiState, repos: Sequence[str]) -> None: diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index f69ef195f..1b2cdea78 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -221,7 +221,7 @@ def invoke_dnf( bwrap(cmdline, apivfs=state.root if apivfs else None, env=dict(KERNEL_INSTALL_BYPASS="1") | env | state.environment, - root=state.config.tools_tree) + tools=state.config.tools_tree) fixup_rpmdb_location(state.root) diff --git a/mkosi/distributions/gentoo.py b/mkosi/distributions/gentoo.py index 0ded5e53c..fef5e0a71 100644 --- a/mkosi/distributions/gentoo.py +++ b/mkosi/distributions/gentoo.py @@ -117,7 +117,7 @@ class GentooInstaller(DistributionInstaller): if stage3_tar.exists(): cmd += ["--time-cond", stage3_tar] - bwrap(cmd, root=state.config.tools_tree) + bwrap(cmd, tools=state.config.tools_tree) if stage3_tar.stat().st_mtime > old: unlink_try_hard(stage3) @@ -134,12 +134,12 @@ class GentooInstaller(DistributionInstaller): "--exclude", "./dev/*", "--exclude", "./proc/*", "--exclude", "./sys/*"], - root=state.config.tools_tree) + tools=state.config.tools_tree) for d in ("binpkgs", "distfiles", "repos/gentoo"): (state.cache_dir / d).mkdir(parents=True, exist_ok=True) - copy_path(state.pkgmngr, stage3, preserve_owner=False, root=state.config.tools_tree) + copy_path(state.pkgmngr, stage3, preserve_owner=False, tools=state.config.tools_tree) run_workspace_command( stage3, diff --git a/mkosi/distributions/opensuse.py b/mkosi/distributions/opensuse.py index 6e9c17499..6b4ff8a82 100644 --- a/mkosi/distributions/opensuse.py +++ b/mkosi/distributions/opensuse.py @@ -142,7 +142,7 @@ def invoke_zypper( bwrap(cmdline, apivfs=state.root if apivfs else None, env=dict(ZYPP_CONF=str(state.pkgmngr / "etc/zypp/zypp.conf"), KERNEL_INSTALL_BYPASS="1") | state.environment, - root=state.config.tools_tree) + tools=state.config.tools_tree) fixup_rpmdb_location(state.root) diff --git a/mkosi/install.py b/mkosi/install.py index 106c35b90..57a0bad17 100644 --- a/mkosi/install.py +++ b/mkosi/install.py @@ -53,7 +53,7 @@ def copy_path( *, dereference: bool = False, preserve_owner: bool = True, - root: Optional[Path] = None, + tools: Optional[Path] = None, ) -> None: bwrap([ "cp", @@ -63,4 +63,4 @@ def copy_path( "--no-target-directory", "--reflink=auto", src, dst, - ], root=root) + ], tools=tools) diff --git a/mkosi/manifest.py b/mkosi/manifest.py index a0a5de155..1f5b199b3 100644 --- a/mkosi/manifest.py +++ b/mkosi/manifest.py @@ -111,7 +111,7 @@ class Manifest: "-qa", "--qf", r"%{NEVRA}\t%{SOURCERPM}\t%{NAME}\t%{ARCH}\t%{LONGSIZE}\t%{INSTALLTIME}\n"], stdout=PIPE, - root=self.config.tools_tree) + tools=self.config.tools_tree) packages = sorted(c.stdout.splitlines()) @@ -154,7 +154,7 @@ class Manifest: nevra], stdout=PIPE, stderr=DEVNULL, - root=self.config.tools_tree) + tools=self.config.tools_tree) changelog = c.stdout.strip() source = SourcePackageManifest(srpm, changelog) self.source_packages[srpm] = source @@ -168,7 +168,7 @@ class Manifest: "--showformat", r'${Package}\t${source:Package}\t${Version}\t${Architecture}\t${Installed-Size}\t${db-fsys:Last-Modified}\n'], stdout=PIPE, - root=self.config.tools_tree) + tools=self.config.tools_tree) packages = sorted(c.stdout.splitlines()) @@ -227,7 +227,7 @@ class Manifest: # We have to run from the root, because if we use the RootDir option to make # apt from the host look at the repositories in the image, it will also pick # the 'methods' executables from there, but the ABI might not be compatible. - result = bwrap(cmd, stdout=PIPE, root=self.config.tools_tree) + result = bwrap(cmd, stdout=PIPE, tools=self.config.tools_tree) source_package = SourcePackageManifest(source, result.stdout.strip()) self.source_packages[source] = source_package diff --git a/mkosi/qemu.py b/mkosi/qemu.py index a4dd0bb9a..38d3c0a9a 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -138,7 +138,7 @@ def find_ovmf_vars(config: MkosiConfig) -> Path: @contextlib.contextmanager def start_swtpm(config: MkosiConfig) -> Iterator[Optional[Path]]: - with tempfile.TemporaryDirectory() as state, bwrap_cmd(root=config.tools_tree) as bwrap: + with tempfile.TemporaryDirectory() as state, bwrap_cmd(tools=config.tools_tree) as bwrap: sock = Path(state) / Path("sock") proc = spawn([*bwrap, "swtpm", "socket", "--tpm2", "--tpmstate", f"dir={state}", "--ctrl", f"type=unixio,path={sock}"]) @@ -313,7 +313,7 @@ def run_qemu(args: MkosiArgs, config: MkosiConfig) -> None: stdout=sys.stdout, env=os.environ, log=False, - root=config.tools_tree) + tools=config.tools_tree) if status := int(notifications.get("EXIT_STATUS", 0)): raise subprocess.CalledProcessError(status, cmdline) diff --git a/mkosi/run.py b/mkosi/run.py index 0643a80d6..76e074372 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -298,7 +298,7 @@ def spawn( @contextlib.contextmanager def bwrap_cmd( *, - root: Optional[Path] = None, + tools: Optional[Path] = None, apivfs: Optional[Path] = None, ) -> Iterator[list[PathString]]: cmdline: list[PathString] = [ @@ -306,7 +306,7 @@ def bwrap_cmd( "--dev-bind", "/", "/", "--chdir", Path.cwd(), "--die-with-parent", - "--ro-bind", (root or Path("/")) / "usr", "/usr", + "--ro-bind", (tools or Path("/")) / "usr", "/usr", ] for d in ("/etc", "/opt", "/srv", "/boot", "/efi"): @@ -365,18 +365,18 @@ def bwrap_cmd( def bwrap( cmd: Sequence[PathString], *, - root: Optional[Path] = None, + tools: Optional[Path] = None, apivfs: Optional[Path] = None, env: Mapping[str, PathString] = {}, log: bool = True, **kwargs: Any, ) -> CompletedProcess: - with bwrap_cmd(root=root, apivfs=apivfs) as bwrap: - if root: - # If a root is specified, we should ignore any local modifications made to PATH as any of those - # tools might not work anymore when /usr is replaced wholesale. We also make sure that both - # /usr/bin and /usr/sbin/ are searched so that e.g. if the host is Arch and the root is Debian we - # don't ignore the binaries from /usr/sbin in the Debian root. + with bwrap_cmd(tools=tools, apivfs=apivfs) as bwrap: + if tools: + # If a tools tree is specified, we should ignore any local modifications made to PATH as any of + # those binaries might not work anymore when /usr is replaced wholesale. We also make sure that + # both /usr/bin and /usr/sbin/ are searched so that e.g. if the host is Arch and the root is + # Debian we don't ignore the binaries from /usr/sbin in the Debian root. env = dict(PATH="/usr/bin:/usr/sbin") | env try: