chroot: replace arch.from_chroot_suffix() with chroot.arch (MR 2252)

Another usage of args dropped!

Although the device_arch variable thing is not very ideal...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-05-24 19:22:35 +02:00 committed by Oliver Smith
parent 8526631589
commit fa804c9453
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
9 changed files with 29 additions and 19 deletions

View file

@ -62,7 +62,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native()):
key = key.relative_to(chroot.path)
pmb.chroot.root(args, ["cp", key, "/etc/apk/keys/"], chroot)
apk_arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
apk_arch = chroot.arch
# Add apk wrapper that runs native apk and lies about arch
if pmb.parse.arch.cpu_emulation_required(apk_arch) and \

View file

@ -161,7 +161,7 @@ def configure_ccache(args: PmbArgs, chroot: Chroot=Chroot.native(), verify=False
:param verify: internally used to test if changing the config has worked.
"""
# Check if the settings have been set already
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
arch = chroot.arch
path = pmb.config.work / f"cache_ccache_{arch}" / "ccache.conf"
if os.path.exists(path):
with open(path, encoding="utf-8") as handle:

View file

@ -208,7 +208,7 @@ def install_run_apk(args: PmbArgs, to_add, to_add_local, to_del, chroot: Chroot)
# will be the systemd version if building for systemd) and run
# it from there.
apk_static = Chroot.native() / "sbin/apk.static"
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
arch = chroot.arch
apk_cache = pmb.config.work / f"cache_apk_{arch}"
for (i, command) in enumerate(commands):
@ -245,7 +245,7 @@ def install(args: PmbArgs, packages, chroot: Chroot, build=True):
special case that all packages are expected to be in Alpine's
repositories, set this to False for performance optimization.
"""
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
arch = chroot.arch
if not packages:
logging.verbose("pmb.chroot.apk.install called with empty packages list,"

View file

@ -57,7 +57,7 @@ def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()):
def setup_qemu_emulation(args: PmbArgs, chroot: Chroot):
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
arch = chroot.arch
if not pmb.parse.arch.cpu_emulation_required(arch):
return
@ -123,7 +123,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native(), usr_merge=UsrMerge.AUTO,
:param postmarketos_mirror: add postmarketos mirror URLs
"""
# When already initialized: just prepare the chroot
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
arch = chroot.arch
already_setup = str(chroot) in pmb.helpers.other.cache["pmb.chroot.init"]
if already_setup:

View file

@ -72,6 +72,23 @@ class Chroot:
return Path(pmb.config.work, self.dirname)
@property
# FIXME: make an Arch type
def arch(self) -> str:
if self.type == ChrootType.NATIVE:
return pmb.config.arch_native
if self.type == ChrootType.BUILDROOT:
return self.name()
# FIXME: this is quite delicate as it will only be valid
# for certain pmbootstrap commands... It was like this
# before but it should be fixed.
arch = pmb.core.get_context().device_arch
if arch is not None:
return arch
raise ValueError(f"Invalid chroot suffix: {self}"
" (wrong device chosen in 'init' step?)")
def __eq__(self, other: object) -> bool:
if isinstance(other, str):
return str(self) == other or self.path == Path(other) or self.name() == other

View file

@ -3,6 +3,7 @@
"""Global runtime context"""
from typing import Optional
import pmb.config
from pathlib import Path
@ -13,6 +14,8 @@ class Context():
command_timeout: float
sudo_timer: bool
log: Path
# The architecture of the selected device
device_arch: Optional[str]
def __init__(self):
self.details_to_stdout = False
@ -20,3 +23,4 @@ class Context():
self.sudo_timer = False
self.log = pmb.config.work / "log.txt"
self.quiet = False
self.device_arch = None

View file

@ -138,6 +138,7 @@ def init(args: PmbArgs) -> PmbArgs:
pmb.config.pmaports.read_config(args)
add_deviceinfo(args)
pmb.helpers.git.parse_channels_cfg(args)
context.device_arch = args.deviceinfo["arch"]
return args

View file

@ -14,18 +14,6 @@ def alpine_native():
return machine_type_to_alpine(machine)
def from_chroot_suffix(args: PmbArgs, chroot: Chroot) -> str:
if chroot == Chroot.native():
return pmb.config.arch_native
if chroot.name() == args.device:
return args.deviceinfo["arch"]
if chroot.type == ChrootType.BUILDROOT:
return chroot.name()
raise ValueError(f"Invalid chroot suffix: {chroot}"
" (wrong device chosen in 'init' step?)")
def alpine_to_qemu(arch):
"""
Convert the architecture to the string used in the QEMU packaging.

View file

@ -41,7 +41,7 @@ def package_provider(args: PmbArgs, pkgname, pkgnames_install, suffix: Chroot=Ch
or None (no provider found)
"""
# Get all providers
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
arch = suffix.arch
providers = pmb.parse.apkindex.providers(args, pkgname, arch, False)
# 0. No provider