From: Daan De Meyer Date: Mon, 17 Jul 2023 16:06:33 +0000 (+0200) Subject: Revert "Rename various "root" arguments to "tools"" X-Git-Tag: v15~73^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d5dc1b05987d19ebdef818e6f4261e9ffc66eb2;p=thirdparty%2Fmkosi.git Revert "Rename various "root" arguments to "tools"" This reverts commit 41ef3c05e1d1caec39c9917b2776aee4f0c29599. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1e33c36dd..7ff1650b8 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -368,7 +368,7 @@ def run_finalize_script(state: MkosiState) -> None: with complete_step("Running finalize script…"): bwrap([state.config.finalize_script], - tools=state.config.tools_tree, + root=state.config.tools_tree, env={**state.environment, "BUILDROOT": str(state.root), "OUTPUTDIR": str(state.staging)}) @@ -380,7 +380,7 @@ def certificate_common_name(state: MkosiState, certificate: Path) -> str: "-subject", "-nameopt", "multiline", "-in", certificate, - ], tools=state.config.tools_tree, stdout=subprocess.PIPE).stdout + ], root=state.config.tools_tree, stdout=subprocess.PIPE).stdout for line in output.splitlines(): if not line.strip().startswith("commonName"): @@ -418,14 +418,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], - tools=state.config.tools_tree) + root=state.config.tools_tree) bwrap(["pk12util", "-K", "", "-W", "", "-i", state.workspace / "secure-boot.p12", "-d", state.workspace / "pesign"], - tools=state.config.tools_tree) + root=state.config.tools_tree) def install_boot_loader(state: MkosiState) -> None: @@ -466,7 +466,7 @@ def install_boot_loader(state: MkosiState) -> None: "--cert", state.config.secure_boot_certificate, "--output", output, input], - tools=state.config.tools_tree) + root=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): @@ -478,13 +478,13 @@ def install_boot_loader(state: MkosiState) -> None: "--force", "--in", input, "--out", output], - tools=state.config.tools_tree) + root=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"}, tools=state.config.tools_tree) + env={"SYSTEMD_ESP_PATH": "/efi"}, root=state.config.tools_tree) if state.config.secure_boot: assert state.config.secure_boot_key @@ -500,13 +500,13 @@ def install_boot_loader(state: MkosiState) -> None: "-outform", "DER", "-in", state.config.secure_boot_certificate, "-out", state.workspace / "mkosi.der"], - tools=state.config.tools_tree) + root=state.config.tools_tree) bwrap(["sbsiglist", "--owner", str(uuid.uuid4()), "--type", "x509", "--output", state.workspace / "mkosi.esl", state.workspace / "mkosi.der"], - tools=state.config.tools_tree) + root=state.config.tools_tree) # We reuse the key for all secure boot databases to keep things simple. for db in ["PK", "KEK", "db"]: @@ -518,7 +518,7 @@ def install_boot_loader(state: MkosiState) -> None: "--output", keys / f"{db}.auth", db, state.workspace / "mkosi.esl"], - tools=state.config.tools_tree) + root=state.config.tools_tree) def install_base_trees(state: MkosiState) -> None: @@ -533,7 +533,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], - tools=state.config.tools_tree) + root=state.config.tools_tree) else: die(f"Unsupported base tree source {path}") @@ -551,7 +551,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, tools=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -569,7 +569,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, tools=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -587,7 +587,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, tools=state.config.tools_tree) + copy_path(source, t, preserve_owner=False, root=state.config.tools_tree) else: shutil.unpack_archive(source, t) @@ -597,7 +597,7 @@ def install_build_dest(state: MkosiState) -> None: return with complete_step("Copying in build tree…"): - copy_path(state.install_dir, state.root, tools=state.config.tools_tree) + copy_path(state.install_dir, state.root, root=state.config.tools_tree) def gzip_binary() -> str: @@ -630,7 +630,7 @@ def make_tar(state: MkosiState) -> None: ] with complete_step("Creating archive…"): - bwrap(cmd, tools=state.config.tools_tree) + bwrap(cmd, root=state.config.tools_tree) def find_files(dir: Path, root: Path) -> Iterator[Path]: @@ -647,7 +647,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(tools=state.config.tools_tree) as bwrap: + with complete_step(f"Creating cpio {output}…"), bwrap_cmd(root=state.config.tools_tree) as bwrap: cmd: list[PathString] = [ *bwrap, "cpio", @@ -739,7 +739,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, tools=state.config.tools_tree).stdout + stdout=subprocess.PIPE, root=state.config.tools_tree).stdout moddep = {} firmwaredep = {} @@ -1002,7 +1002,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, tools=state.config.tools_tree) + bwrap(cmd, root=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) @@ -1040,7 +1040,7 @@ def maybe_compress(state: MkosiState, compression: Compression, src: Path, dst: src.unlink() # if src == dst, make sure dst doesn't truncate the src file but creates a new file. with dst.open("wb") as o: - bwrap(compressor_command(compression), stdin=i, stdout=o, tools=state.config.tools_tree) + bwrap(compressor_command(compression), stdin=i, stdout=o, root=state.config.tools_tree) os.chown(dst, uid=state.uid, gid=state.gid) @@ -1108,7 +1108,7 @@ def calculate_signature(state: MkosiState) -> None: Path(os.environ['HOME']).joinpath('.gnupg') ) }, - tools=state.config.tools_tree, + root=state.config.tools_tree, ) @@ -1518,23 +1518,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], tools=state.config.tools_tree) + bwrap(["depmod", "--all", "--basedir", state.root, kver], root=state.config.tools_tree) def run_sysusers(state: MkosiState) -> None: with complete_step("Generating system users"): - bwrap(["systemd-sysusers", "--root", state.root], tools=state.config.tools_tree) + bwrap(["systemd-sysusers", "--root", state.root], root=state.config.tools_tree) def run_preset(state: MkosiState) -> None: with complete_step("Applying presets…"): - bwrap(["systemctl", "--root", state.root, "preset-all"], tools=state.config.tools_tree) + bwrap(["systemctl", "--root", state.root, "preset-all"], root=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"], - tools=state.config.tools_tree) + root=state.config.tools_tree) def run_firstboot(state: MkosiState) -> None: @@ -1569,7 +1569,7 @@ def run_firstboot(state: MkosiState) -> None: with complete_step("Applying first boot settings"): bwrap(["systemd-firstboot", "--root", state.root, "--force", *options], - tools=state.config.tools_tree) + root=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. @@ -1589,7 +1589,7 @@ def run_selinux_relabel(state: MkosiState) -> None: return policy = bwrap(["sh", "-c", f". {selinux} && echo $SELINUXTYPE"], - stdout=subprocess.PIPE, tools=state.config.tools_tree).stdout.strip() + stdout=subprocess.PIPE, root=state.config.tools_tree).stdout.strip() if not policy: return @@ -1744,7 +1744,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, - tools=state.config.tools_tree).stdout) + root=state.config.tools_tree).stdout) roothash = usrhash = None for p in output: @@ -1919,7 +1919,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}", "-"], - tools=config.tools_tree, + root=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())]) @@ -1937,7 +1937,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, - tools=config.tools_tree, + root=config.tools_tree, ).stdout if not has_acl and not always: @@ -2033,7 +2033,7 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: "--dry-run=no", "--offline=no", fname], - tools=config.tools_tree) + root=config.tools_tree) if config.output_format == OutputFormat.directory: cmdline += ["--directory", fname] @@ -2062,7 +2062,7 @@ def run_shell(args: MkosiArgs, config: MkosiConfig) -> None: stdout=sys.stdout, env=os.environ, log=False, - tools=config.tools_tree) + root=config.tools_tree) def run_ssh(args: MkosiArgs, config: MkosiConfig) -> None: @@ -2078,7 +2078,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, tools=config.tools_tree) + bwrap(cmd, stdin=sys.stdin, stdout=sys.stdout, env=os.environ, log=False, root=config.tools_tree) def run_serve(config: MkosiConfig) -> None: diff --git a/mkosi/btrfs.py b/mkosi/btrfs.py index 5b18a2f7a..552a638cf 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], - tools=config.tools_tree, stdout=subprocess.PIPE).stdout.strip()) + root=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, - tools=config.tools_tree).returncode + root=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, tools=config.tools_tree) + return copy_path(src, dst, root=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, - tools=config.tools_tree).returncode + root=config.tools_tree).returncode else: result = 1 if result != 0: - copy_path(src, dst, tools=config.tools_tree) + copy_path(src, dst, root=config.tools_tree) diff --git a/mkosi/distributions/arch.py b/mkosi/distributions/arch.py index 4be0767a5..e582d2f84 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, - tools=state.config.tools_tree) + root=state.config.tools_tree) diff --git a/mkosi/distributions/debian.py b/mkosi/distributions/debian.py index 36ede4b64..b5ce0f025 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, tools=state.config.tools_tree) + bwrap(["dpkg-deb", "--fsys-tarfile", deb], stdout=f, root=state.config.tools_tree) bwrap(["tar", "-C", state.root, "--keep-directory-symlink", "--extract", "--file", f.name], - tools=state.config.tools_tree) + root=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, *packages], apivfs=state.root if apivfs else None, env=env | state.environment, - tools=state.config.tools_tree) + root=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 1b2cdea78..f69ef195f 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, - tools=state.config.tools_tree) + root=state.config.tools_tree) fixup_rpmdb_location(state.root) diff --git a/mkosi/distributions/gentoo.py b/mkosi/distributions/gentoo.py index e5a7c93d3..77595a011 100644 --- a/mkosi/distributions/gentoo.py +++ b/mkosi/distributions/gentoo.py @@ -124,7 +124,7 @@ class GentooInstaller(DistributionInstaller): if stage3_tar.exists(): cmd += ["--time-cond", stage3_tar] - bwrap(cmd, tools=state.config.tools_tree) + bwrap(cmd, root=state.config.tools_tree) if stage3_tar.stat().st_mtime > old: unlink_try_hard(stage3) @@ -141,12 +141,12 @@ class GentooInstaller(DistributionInstaller): "--exclude", "./dev/*", "--exclude", "./proc/*", "--exclude", "./sys/*"], - tools=state.config.tools_tree) + root=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, tools=state.config.tools_tree) + copy_path(state.pkgmngr, stage3, preserve_owner=False, root=state.config.tools_tree) bwrap( cmd=["chroot", "emerge-webrsync"], diff --git a/mkosi/distributions/opensuse.py b/mkosi/distributions/opensuse.py index 6b4ff8a82..6e9c17499 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, - tools=state.config.tools_tree) + root=state.config.tools_tree) fixup_rpmdb_location(state.root) diff --git a/mkosi/install.py b/mkosi/install.py index d0a60c317..26c5b734c 100644 --- a/mkosi/install.py +++ b/mkosi/install.py @@ -48,7 +48,7 @@ def copy_path( *, dereference: bool = False, preserve_owner: bool = True, - tools: Optional[Path] = None, + root: Optional[Path] = None, ) -> None: bwrap([ "cp", @@ -58,4 +58,4 @@ def copy_path( "--no-target-directory", "--reflink=auto", src, dst, - ], tools=tools) + ], root=root) diff --git a/mkosi/manifest.py b/mkosi/manifest.py index 1f5b199b3..a0a5de155 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, - tools=self.config.tools_tree) + root=self.config.tools_tree) packages = sorted(c.stdout.splitlines()) @@ -154,7 +154,7 @@ class Manifest: nevra], stdout=PIPE, stderr=DEVNULL, - tools=self.config.tools_tree) + root=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, - tools=self.config.tools_tree) + root=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, tools=self.config.tools_tree) + result = bwrap(cmd, stdout=PIPE, root=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 38d3c0a9a..a4dd0bb9a 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(tools=config.tools_tree) as bwrap: + with tempfile.TemporaryDirectory() as state, bwrap_cmd(root=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, - tools=config.tools_tree) + root=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 a1e5291c6..5176a9b29 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -312,7 +312,7 @@ def spawn( @contextlib.contextmanager def bwrap_cmd( *, - tools: Optional[Path] = None, + root: Optional[Path] = None, apivfs: Optional[Path] = None, scripts: Mapping[str, Sequence[PathString]] = {}, ) -> Iterator[list[PathString]]: @@ -321,7 +321,7 @@ def bwrap_cmd( "--dev-bind", "/", "/", "--chdir", Path.cwd(), "--die-with-parent", - "--ro-bind", (tools or Path("/")) / "usr", "/usr", + "--ro-bind", (root or Path("/")) / "usr", "/usr", ] for d in ("/etc", "/opt", "/srv", "/boot", "/efi"): @@ -378,7 +378,7 @@ def bwrap_cmd( make_executable(Path(d) / name) # We modify the PATH via --setenv so that bwrap itself is looked up in PATH before we change it. - if tools: + if root: # 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 @@ -412,7 +412,7 @@ def bwrap_cmd( def bwrap( cmd: Sequence[PathString], *, - tools: Optional[Path] = None, + root: Optional[Path] = None, apivfs: Optional[Path] = None, log: bool = True, scripts: Mapping[str, Sequence[PathString]] = {}, @@ -424,7 +424,7 @@ def bwrap( check: bool = True, env: Mapping[str, PathString] = {}, ) -> CompletedProcess: - with bwrap_cmd(tools=tools, apivfs=apivfs, scripts=scripts) as bwrap: + with bwrap_cmd(root=root, apivfs=apivfs, scripts=scripts) as bwrap: try: result = run( [*bwrap, *cmd],