forked from Mirror/pmbootstrap
TEMP: chroot: apk: run apk through QEMU again (MR 2351)
This revers b82c4eb167
("chroot: always run apk static (MR 2252)")
since the current iteration of the apk-tools /usr merge patches
don't handle --root properly and will behave differently based on your
host systems directory structure (specifially for /usr merge).
This commit can be reverted once we fix apk-tools.
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
0a60750684
commit
f512242073
2 changed files with 34 additions and 27 deletions
|
@ -199,17 +199,6 @@ def install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[st
|
||||||
if to_del:
|
if to_del:
|
||||||
commands += [["del"] + to_del]
|
commands += [["del"] + to_del]
|
||||||
|
|
||||||
# For systemd we use a fork of apk-tools, to easily handle this
|
|
||||||
# we expect apk.static to be installed in the native chroot (which
|
|
||||||
# will be the systemd version if building for systemd) and run
|
|
||||||
# it from there.
|
|
||||||
# pmb.chroot.init(Chroot.native())
|
|
||||||
# if chroot != Chroot.native():
|
|
||||||
# pmb.chroot.init(chroot)
|
|
||||||
apk_static = Chroot.native() / "sbin/apk.static"
|
|
||||||
arch = chroot.arch
|
|
||||||
apk_cache = work / f"cache_apk_{arch}"
|
|
||||||
|
|
||||||
channel = pmb.config.pmaports.read_config()["channel"]
|
channel = pmb.config.pmaports.read_config()["channel"]
|
||||||
user_repo = work / "packages" / channel
|
user_repo = work / "packages" / channel
|
||||||
|
|
||||||
|
@ -227,12 +216,6 @@ def install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[st
|
||||||
# gets confused
|
# gets confused
|
||||||
command += ["--no-interactive"]
|
command += ["--no-interactive"]
|
||||||
command = [
|
command = [
|
||||||
"--root",
|
|
||||||
chroot.path,
|
|
||||||
"--arch",
|
|
||||||
arch,
|
|
||||||
"--cache-dir",
|
|
||||||
apk_cache,
|
|
||||||
"--repository",
|
"--repository",
|
||||||
user_repo,
|
user_repo,
|
||||||
] + command
|
] + command
|
||||||
|
@ -244,12 +227,12 @@ 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_static] + command)
|
pmb.helpers.apk.apk_with_progress(["apk"] + 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.
|
||||||
# They finish up almost instantly, so don't display a progress bar.
|
# They finish up almost instantly, so don't display a progress bar.
|
||||||
pmb.helpers.run.root([apk_static, "--no-progress"] + command)
|
pmb.chroot.root(["apk", "--no-progress"] + command, chroot)
|
||||||
|
|
||||||
|
|
||||||
def install(packages, chroot: Chroot, build=True):
|
def install(packages, chroot: Chroot, build=True):
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
import os
|
import os
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import pmb.chroot
|
import pmb.chroot
|
||||||
import pmb.config.pmaports
|
import pmb.config.pmaports
|
||||||
from pmb.core.arch import Arch
|
from pmb.core.arch import Arch
|
||||||
|
from pmb.core.chroot import Chroot
|
||||||
from pmb.types import PathString
|
from pmb.types import PathString
|
||||||
import pmb.helpers.cli
|
import pmb.helpers.cli
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
|
@ -14,7 +17,23 @@ import pmb.parse.version
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
|
|
||||||
|
|
||||||
def _prepare_fifo():
|
def _run(command, chroot: Optional[Chroot], output="log"):
|
||||||
|
"""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: Optional[Chroot]):
|
||||||
"""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
|
||||||
|
@ -25,11 +44,16 @@ def _prepare_fifo():
|
||||||
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 = fifo_outside = get_context().config.work / "tmp/apk_progress_fifo"
|
||||||
if os.path.exists(fifo_outside):
|
if os.path.exists(fifo_outside):
|
||||||
pmb.helpers.run.root(["rm", "-f", fifo_outside])
|
pmb.helpers.run.root(["rm", "-f", fifo_outside])
|
||||||
pmb.helpers.run.root(["mkfifo", fifo_outside])
|
|
||||||
|
_run(["mkfifo", fifo], chroot)
|
||||||
return (fifo, fifo_outside)
|
return (fifo, fifo_outside)
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +87,7 @@ def _compute_progress(line):
|
||||||
return cur / tot if tot > 0 else 0
|
return cur / tot if tot > 0 else 0
|
||||||
|
|
||||||
|
|
||||||
def apk_with_progress(command: Sequence[PathString]):
|
def apk_with_progress(command: Sequence[PathString], chroot: Optional[Chroot] = None):
|
||||||
"""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
|
||||||
|
@ -72,7 +96,7 @@ def apk_with_progress(command: Sequence[PathString]):
|
||||||
set to True.
|
set to True.
|
||||||
:raises RuntimeError: when the apk command fails
|
:raises RuntimeError: when the apk command fails
|
||||||
"""
|
"""
|
||||||
fifo, fifo_outside = _prepare_fifo()
|
fifo, _ = _prepare_fifo(chroot)
|
||||||
_command: list[str] = []
|
_command: list[str] = []
|
||||||
for c in command:
|
for c in command:
|
||||||
if isinstance(c, Arch):
|
if isinstance(c, Arch):
|
||||||
|
@ -81,8 +105,8 @@ def apk_with_progress(command: Sequence[PathString]):
|
||||||
_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 pmb.helpers.run.root(["cat", fifo], output="pipe") as p_cat:
|
with _run(["cat", fifo], chroot, output="pipe") as p_cat:
|
||||||
with pmb.helpers.run.root(command_with_progress, output="background") as p_apk:
|
with _run(command_with_progress, chroot, 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