forked from Mirror/pmbootstrap
chroot: always run apk static v2 (MR 2423)
Now that we don't need weird apk-tools hacks for systemd, we can re-implement this optimisation and always run apk static rather than running apk through the chroot. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
521628ba50
commit
0b4fb9119f
3 changed files with 16 additions and 37 deletions
|
@ -221,7 +221,7 @@ def install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[st
|
||||||
# FIXME: use /mnt/pmb… until MR 2351 is reverted (pmb#2388)
|
# FIXME: use /mnt/pmb… until MR 2351 is reverted (pmb#2388)
|
||||||
user_repo = []
|
user_repo = []
|
||||||
for channel in pmb.config.pmaports.all_channels():
|
for channel in pmb.config.pmaports.all_channels():
|
||||||
user_repo += ["--repository", Path("/mnt/pmbootstrap/packages") / channel]
|
user_repo += ["--repository", context.config.work / "packages" / channel]
|
||||||
|
|
||||||
for i, command in enumerate(commands):
|
for i, command in enumerate(commands):
|
||||||
# --no-interactive is a parameter to `add`, so it must be appended or apk
|
# --no-interactive is a parameter to `add`, so it must be appended or apk
|
||||||
|
@ -236,7 +236,7 @@ def install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[st
|
||||||
if context.offline:
|
if context.offline:
|
||||||
command = ["--no-network"] + command
|
command = ["--no-network"] + command
|
||||||
if i == 0:
|
if i == 0:
|
||||||
pmb.helpers.apk.apk_with_progress(["apk"] + command, chroot)
|
pmb.helpers.apk.apk_with_progress(command, chroot)
|
||||||
else:
|
else:
|
||||||
# Virtual package related commands don't actually install or remove
|
# Virtual package related commands don't actually install or remove
|
||||||
# packages, but only mark the right ones as explicitly installed.
|
# packages, but only mark the right ones as explicitly installed.
|
||||||
|
|
|
@ -182,4 +182,4 @@ def run(parameters):
|
||||||
|
|
||||||
if get_context().offline:
|
if get_context().offline:
|
||||||
parameters = ["--no-network"] + parameters
|
parameters = ["--no-network"] + parameters
|
||||||
pmb.helpers.apk.apk_with_progress([get_context().config.work / "apk.static"] + parameters)
|
pmb.helpers.apk.apk_with_progress(parameters)
|
||||||
|
|
|
@ -16,23 +16,7 @@ import pmb.parse.version
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
|
|
||||||
|
|
||||||
def _run(command, chroot: Chroot | None, output="log"):
|
def _prepare_fifo() -> Path:
|
||||||
"""Run a command.
|
|
||||||
|
|
||||||
:param command: command in list form
|
|
||||||
:param chroot: whether to run the command inside the chroot or on the host
|
|
||||||
:param suffix: chroot suffix. Only applies if the "chroot" parameter is
|
|
||||||
set to True.
|
|
||||||
|
|
||||||
See pmb.helpers.run_core.core() for a detailed description of all other
|
|
||||||
arguments and the return value.
|
|
||||||
"""
|
|
||||||
if chroot:
|
|
||||||
return pmb.chroot.root(command, output=output, chroot=chroot, disable_timeout=True)
|
|
||||||
return pmb.helpers.run.root(command, output=output)
|
|
||||||
|
|
||||||
|
|
||||||
def _prepare_fifo(chroot: Chroot | None):
|
|
||||||
"""Prepare the progress fifo for reading / writing.
|
"""Prepare the progress fifo for reading / writing.
|
||||||
|
|
||||||
:param chroot: whether to run the command inside the chroot or on the host
|
:param chroot: whether to run the command inside the chroot or on the host
|
||||||
|
@ -43,17 +27,13 @@ def _prepare_fifo(chroot: Chroot | None):
|
||||||
path of the fifo as needed by cat to read from it (always
|
path of the fifo as needed by cat to read from it (always
|
||||||
relative to the host)
|
relative to the host)
|
||||||
"""
|
"""
|
||||||
if chroot:
|
|
||||||
fifo = Path("tmp/apk_progress_fifo")
|
|
||||||
fifo_outside = chroot / fifo
|
|
||||||
else:
|
|
||||||
pmb.helpers.run.root(["mkdir", "-p", get_context().config.work / "tmp"])
|
pmb.helpers.run.root(["mkdir", "-p", get_context().config.work / "tmp"])
|
||||||
fifo = fifo_outside = get_context().config.work / "tmp/apk_progress_fifo"
|
fifo = get_context().config.work / "tmp/apk_progress_fifo"
|
||||||
if os.path.exists(fifo_outside):
|
if os.path.exists(fifo):
|
||||||
pmb.helpers.run.root(["rm", "-f", fifo_outside])
|
pmb.helpers.run.root(["rm", "-f", fifo])
|
||||||
|
|
||||||
_run(["mkfifo", fifo], chroot)
|
pmb.helpers.run.root(["mkfifo", fifo])
|
||||||
return (fifo, fifo_outside)
|
return fifo
|
||||||
|
|
||||||
|
|
||||||
def _create_command_with_progress(command, fifo):
|
def _create_command_with_progress(command, fifo):
|
||||||
|
@ -90,13 +70,12 @@ def apk_with_progress(command: Sequence[PathString], chroot: Chroot | None = Non
|
||||||
"""Run an apk subcommand while printing a progress bar to STDOUT.
|
"""Run an apk subcommand while printing a progress bar to STDOUT.
|
||||||
|
|
||||||
:param command: apk subcommand in list form
|
:param command: apk subcommand in list form
|
||||||
:param chroot: whether to run commands inside the chroot or on the host
|
|
||||||
:param suffix: chroot suffix. Only applies if the "chroot" parameter is
|
|
||||||
set to True.
|
|
||||||
:raises RuntimeError: when the apk command fails
|
:raises RuntimeError: when the apk command fails
|
||||||
"""
|
"""
|
||||||
fifo, _ = _prepare_fifo(chroot)
|
fifo = _prepare_fifo()
|
||||||
_command: list[str] = []
|
_command: list[str] = [str(get_context().config.work / "apk.static")]
|
||||||
|
if chroot:
|
||||||
|
_command.extend(["--root", str(chroot.path), "--arch", str(chroot.arch)])
|
||||||
for c in command:
|
for c in command:
|
||||||
if isinstance(c, Arch):
|
if isinstance(c, Arch):
|
||||||
_command.append(str(c))
|
_command.append(str(c))
|
||||||
|
@ -104,8 +83,8 @@ def apk_with_progress(command: Sequence[PathString], chroot: Chroot | None = Non
|
||||||
_command.append(os.fspath(c))
|
_command.append(os.fspath(c))
|
||||||
command_with_progress = _create_command_with_progress(_command, fifo)
|
command_with_progress = _create_command_with_progress(_command, fifo)
|
||||||
log_msg = " ".join(_command)
|
log_msg = " ".join(_command)
|
||||||
with _run(["cat", fifo], chroot, output="pipe") as p_cat:
|
with pmb.helpers.run.root(["cat", fifo], output="pipe") as p_cat:
|
||||||
with _run(command_with_progress, chroot, output="background") as p_apk:
|
with pmb.helpers.run.root(command_with_progress, output="background") as p_apk:
|
||||||
while p_apk.poll() is None:
|
while p_apk.poll() is None:
|
||||||
line = p_cat.stdout.readline().decode("utf-8")
|
line = p_cat.stdout.readline().decode("utf-8")
|
||||||
progress = _compute_progress(line)
|
progress = _compute_progress(line)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue