def invoke_apt(
args: MkosiArgs,
- do_run_build_script: bool,
root: Path,
- command: str,
+ subcommand: str,
+ operation: str,
extra: Iterable[str],
-) -> None:
+ **kwargs: Any,
+) -> CompletedProcess:
- cmdline = ["/usr/bin/apt-get", "--assume-yes", command, *extra]
+ cmdline = [
+ f"/usr/bin/apt-{subcommand}",
+ "-o", f"Dir={root}",
+ "-o", f"DPkg::Chroot-Directory={root}",
+ operation,
+ *extra,
+ ]
env = dict(
DEBIAN_FRONTEND="noninteractive",
DEBCONF_NONINTERACTIVE_SEEN="true",
INITRD="No",
)
- run_workspace_command(args, root, cmdline, network=True, env=env)
+ with mount_api_vfs(args, root):
+ return run(cmdline, env=env, text=True, **kwargs)
def install_debian_or_ubuntu(args: MkosiArgs, root: Path, *, do_run_build_script: bool) -> None:
install_skeleton_trees(args, root, False, late=True)
- invoke_apt(args, do_run_build_script, root, "update", [])
+ invoke_apt(args, root, "get", "update", ["--assume-yes"])
if args.bootable and not do_run_build_script and args.get_partition(PartitionIdentifier.esp):
- if run_workspace_command(args, root, ["apt-cache", "search", "--names-only", "^systemd-boot$"],
- capture_stdout=True).stdout.strip() != "":
+ if invoke_apt(args, root, "cache", "search", ["--names-only", "^systemd-boot$"], stdout=PIPE).stdout.strip() != "":
add_packages(args, extra_packages, "systemd-boot")
- invoke_apt(args, do_run_build_script, root, "install", ["--no-install-recommends", *extra_packages])
+ invoke_apt(args, root, "get", "install", ["--assume-yes", "--no-install-recommends", *extra_packages])
policyrcd.unlink()
dpkg_io_conf.unlink()
if not args.remove_packages:
return
- remove: Callable[[List[str]], None]
+ remove: Callable[[List[str]], Any]
if (args.distribution.package_type == PackageType.rpm):
remove = lambda p: invoke_dnf(args, root, 'remove', p)
elif args.distribution.package_type == PackageType.deb:
- remove = lambda p: invoke_apt(args, False, root, "purge", ["--auto-remove", *p])
+ remove = lambda p: invoke_apt(args, root, "get", "purge", ["--assume-yes", "--auto-remove", *p])
else:
die(f"Removing packages is not supported for {args.distribution}")
from textwrap import dedent
from typing import IO, Any, Dict, List, Optional, Tuple, cast
-from .backend import (
- Distribution,
- ManifestFormat,
- MkosiArgs,
- PackageType,
- run,
- run_workspace_command,
-)
+from .backend import Distribution, ManifestFormat, MkosiArgs, PackageType, run
@dataclasses.dataclass
source.add(package)
def record_deb_packages(self, root: Path) -> None:
- c = run_workspace_command(self.args, root,
- ["dpkg-query", "--admindir=/var/lib/dpkg", "--show", "--showformat",
+ c = run(
+ ["dpkg-query", f"--admindir={root}/var/lib/dpkg", "--show", "--showformat",
r'${Package}\t${source:Package}\t${Version}\t${Architecture}\t${Installed-Size}\t${db-fsys:Last-Modified}\n'],
- capture_stdout=True
+ stdout=PIPE,
+ text=True,
)
packages = sorted(c.stdout.splitlines())
# Yes, --quiet is specified twice, to avoid output about download stats.
# Note that the argument of the 'changelog' verb is the binary package name,
# not the source package name.
- cmd = ["apt-get", "--quiet", "--quiet", "changelog", name]
+ cmd = [
+ "apt-get",
+ "--quiet",
+ "--quiet",
+ "-o", f"Dir={root}",
+ "-o", f"DPkg::Chroot-Directory={root}",
+ "changelog",
+ name,
+ ]
# If we are building with docs then it's easy, as the changelogs are saved
# in the image, just fetch them. Otherwise they will be downloaded from the network.
# 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 = run_workspace_command(self.args, root, cmd, network=not self.args.with_docs, capture_stdout=True)
+ result = run(cmd, text=True, stdout=PIPE)
source_package = SourcePackageManifest(source, result.stdout.strip())
self.source_packages[source] = source_package