forked from Mirror/pmbootstrap
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:
parent
8526631589
commit
fa804c9453
9 changed files with 29 additions and 19 deletions
|
@ -62,7 +62,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native()):
|
||||||
key = key.relative_to(chroot.path)
|
key = key.relative_to(chroot.path)
|
||||||
pmb.chroot.root(args, ["cp", key, "/etc/apk/keys/"], chroot)
|
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
|
# Add apk wrapper that runs native apk and lies about arch
|
||||||
if pmb.parse.arch.cpu_emulation_required(apk_arch) and \
|
if pmb.parse.arch.cpu_emulation_required(apk_arch) and \
|
||||||
|
|
|
@ -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.
|
:param verify: internally used to test if changing the config has worked.
|
||||||
"""
|
"""
|
||||||
# Check if the settings have been set already
|
# 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"
|
path = pmb.config.work / f"cache_ccache_{arch}" / "ccache.conf"
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
with open(path, encoding="utf-8") as handle:
|
with open(path, encoding="utf-8") as handle:
|
||||||
|
|
|
@ -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
|
# will be the systemd version if building for systemd) and run
|
||||||
# it from there.
|
# it from there.
|
||||||
apk_static = Chroot.native() / "sbin/apk.static"
|
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}"
|
apk_cache = pmb.config.work / f"cache_apk_{arch}"
|
||||||
|
|
||||||
for (i, command) in enumerate(commands):
|
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
|
special case that all packages are expected to be in Alpine's
|
||||||
repositories, set this to False for performance optimization.
|
repositories, set this to False for performance optimization.
|
||||||
"""
|
"""
|
||||||
arch = pmb.parse.arch.from_chroot_suffix(args, chroot)
|
arch = chroot.arch
|
||||||
|
|
||||||
if not packages:
|
if not packages:
|
||||||
logging.verbose("pmb.chroot.apk.install called with empty packages list,"
|
logging.verbose("pmb.chroot.apk.install called with empty packages list,"
|
||||||
|
|
|
@ -57,7 +57,7 @@ def mark_in_chroot(args: PmbArgs, chroot: Chroot=Chroot.native()):
|
||||||
|
|
||||||
|
|
||||||
def setup_qemu_emulation(args: PmbArgs, chroot: Chroot):
|
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):
|
if not pmb.parse.arch.cpu_emulation_required(arch):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ def init(args: PmbArgs, chroot: Chroot=Chroot.native(), usr_merge=UsrMerge.AUTO,
|
||||||
:param postmarketos_mirror: add postmarketos mirror URLs
|
:param postmarketos_mirror: add postmarketos mirror URLs
|
||||||
"""
|
"""
|
||||||
# When already initialized: just prepare the chroot
|
# 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"]
|
already_setup = str(chroot) in pmb.helpers.other.cache["pmb.chroot.init"]
|
||||||
if already_setup:
|
if already_setup:
|
||||||
|
|
|
@ -72,6 +72,23 @@ class Chroot:
|
||||||
return Path(pmb.config.work, self.dirname)
|
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:
|
def __eq__(self, other: object) -> bool:
|
||||||
if isinstance(other, str):
|
if isinstance(other, str):
|
||||||
return str(self) == other or self.path == Path(other) or self.name() == other
|
return str(self) == other or self.path == Path(other) or self.name() == other
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
"""Global runtime context"""
|
"""Global runtime context"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import pmb.config
|
import pmb.config
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ class Context():
|
||||||
command_timeout: float
|
command_timeout: float
|
||||||
sudo_timer: bool
|
sudo_timer: bool
|
||||||
log: Path
|
log: Path
|
||||||
|
# The architecture of the selected device
|
||||||
|
device_arch: Optional[str]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.details_to_stdout = False
|
self.details_to_stdout = False
|
||||||
|
@ -20,3 +23,4 @@ class Context():
|
||||||
self.sudo_timer = False
|
self.sudo_timer = False
|
||||||
self.log = pmb.config.work / "log.txt"
|
self.log = pmb.config.work / "log.txt"
|
||||||
self.quiet = False
|
self.quiet = False
|
||||||
|
self.device_arch = None
|
||||||
|
|
|
@ -138,6 +138,7 @@ def init(args: PmbArgs) -> PmbArgs:
|
||||||
pmb.config.pmaports.read_config(args)
|
pmb.config.pmaports.read_config(args)
|
||||||
add_deviceinfo(args)
|
add_deviceinfo(args)
|
||||||
pmb.helpers.git.parse_channels_cfg(args)
|
pmb.helpers.git.parse_channels_cfg(args)
|
||||||
|
context.device_arch = args.deviceinfo["arch"]
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,6 @@ def alpine_native():
|
||||||
return machine_type_to_alpine(machine)
|
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):
|
def alpine_to_qemu(arch):
|
||||||
"""
|
"""
|
||||||
Convert the architecture to the string used in the QEMU packaging.
|
Convert the architecture to the string used in the QEMU packaging.
|
||||||
|
|
|
@ -41,7 +41,7 @@ def package_provider(args: PmbArgs, pkgname, pkgnames_install, suffix: Chroot=Ch
|
||||||
or None (no provider found)
|
or None (no provider found)
|
||||||
"""
|
"""
|
||||||
# Get all providers
|
# Get all providers
|
||||||
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
arch = suffix.arch
|
||||||
providers = pmb.parse.apkindex.providers(args, pkgname, arch, False)
|
providers = pmb.parse.apkindex.providers(args, pkgname, arch, False)
|
||||||
|
|
||||||
# 0. No provider
|
# 0. No provider
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue