args.arch_native: remove (MR 2130)
Replace "args.arch_native" with the direct function call in order to avoid passing "args" to all functions. This is a step to get rid of this args-passed-to-all-functions pattern in pmbootstrap.
This commit is contained in:
parent
f2966e62ae
commit
caf7973e24
|
@ -15,7 +15,7 @@ def generate(args, pkgname):
|
|||
fields = {
|
||||
"pkgname": pkgname,
|
||||
"pkgdesc": f"Tools necessary to build programs for {arch} targets",
|
||||
"arch": args.arch_native,
|
||||
"arch": pmb.config.arch_native,
|
||||
"makedepends_build": "",
|
||||
"makedepends_host": "",
|
||||
"makedepends": "gettext libtool autoconf automake bison texinfo",
|
||||
|
|
|
@ -47,7 +47,7 @@ def generate(args, pkgname):
|
|||
|
||||
url="http://busybox.net"
|
||||
license="GPL2"
|
||||
arch="{args.arch_native}"
|
||||
arch="{pmb.config.arch_native}"
|
||||
options="!check !strip"
|
||||
pkgdesc="Statically linked Busybox for $_arch"
|
||||
_target="$(arch_to_hostspec $_arch)"
|
||||
|
|
|
@ -28,7 +28,7 @@ def generate(args, pkgname):
|
|||
fields = {
|
||||
"pkgname": pkgname,
|
||||
"pkgdesc": f"Stage2 cross-compiler for {arch}",
|
||||
"arch": args.arch_native,
|
||||
"arch": pmb.config.arch_native,
|
||||
"depends": f"isl binutils-{arch} mpc1",
|
||||
"makedepends_build": "gcc g++ bison flex texinfo gawk zip"
|
||||
" gmp-dev mpfr-dev mpc1-dev zlib-dev",
|
||||
|
|
|
@ -43,7 +43,7 @@ def generate(args, pkgname):
|
|||
pkgdesc="GRUB $_arch EFI files for every architecture"
|
||||
url="https://www.gnu.org/software/grub/"
|
||||
license="GPL-3.0-or-later"
|
||||
arch="{args.arch_native}"
|
||||
arch="{pmb.config.arch_native}"
|
||||
source="grub-efi-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/grub-efi-$pkgver-r$pkgrel.apk"
|
||||
|
||||
package() {{
|
||||
|
|
|
@ -42,7 +42,7 @@ def generate(args, pkgname):
|
|||
pkgname={pkgname}
|
||||
pkgver={pkgver}
|
||||
pkgrel={pkgrel}
|
||||
arch="{args.arch_native}"
|
||||
arch="{pmb.config.arch_native}"
|
||||
subpackages="musl-dev-{arch}:package_dev"
|
||||
|
||||
_arch="{arch}"
|
||||
|
|
|
@ -196,7 +196,7 @@ def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
|
|||
|
||||
depends_arch = arch
|
||||
if cross == "native":
|
||||
depends_arch = args.arch_native
|
||||
depends_arch = pmb.config.arch_native
|
||||
|
||||
# Build dependencies
|
||||
depends, built = build_depends(args, apkbuild, depends_arch, strict)
|
||||
|
@ -236,7 +236,7 @@ def get_gcc_version(args, arch):
|
|||
:returns: a string like "6.4.0-r5"
|
||||
"""
|
||||
return pmb.parse.apkindex.package(args, "gcc-" + arch,
|
||||
args.arch_native)["version"]
|
||||
pmb.config.arch_native)["version"]
|
||||
|
||||
|
||||
def get_pkgver(original_pkgver, original_source=False, now=None):
|
||||
|
@ -493,7 +493,7 @@ def package(args, pkgname, arch=None, force=False, strict=False,
|
|||
output path relative to the packages folder ("armhf/ab-1-r2.apk")
|
||||
"""
|
||||
# Once per session is enough
|
||||
arch = arch or args.arch_native
|
||||
arch = arch or pmb.config.arch_native
|
||||
if skip_already_built(args, pkgname, arch):
|
||||
return
|
||||
|
||||
|
@ -505,7 +505,7 @@ def package(args, pkgname, arch=None, force=False, strict=False,
|
|||
# Detect the build environment (skip unnecessary builds)
|
||||
if not check_build_for_arch(args, pkgname, arch):
|
||||
return
|
||||
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
|
||||
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
|
||||
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
|
||||
if not init_buildenv(args, apkbuild, arch, strict, force, cross, suffix,
|
||||
skip_init_buildenv, src):
|
||||
|
|
|
@ -50,8 +50,10 @@ def arch(args, pkgname):
|
|||
|
||||
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
|
||||
arches = apkbuild["arch"]
|
||||
if "noarch" in arches or "all" in arches or args.arch_native in arches:
|
||||
return args.arch_native
|
||||
if ("noarch" in arches or
|
||||
"all" in arches or
|
||||
pmb.config.arch_native in arches):
|
||||
return pmb.config.arch_native
|
||||
|
||||
arch_device = args.deviceinfo["arch"]
|
||||
if arch_device in arches:
|
||||
|
@ -63,8 +65,8 @@ def arch(args, pkgname):
|
|||
return None
|
||||
|
||||
|
||||
def suffix(args, apkbuild, arch):
|
||||
if arch == args.arch_native:
|
||||
def suffix(apkbuild, arch):
|
||||
if arch == pmb.config.arch_native:
|
||||
return "native"
|
||||
|
||||
if "pmb:cross-native" in apkbuild["options"]:
|
||||
|
@ -79,7 +81,7 @@ def crosscompile(args, apkbuild, arch, suffix):
|
|||
"""
|
||||
if not args.cross:
|
||||
return None
|
||||
if not pmb.parse.arch.cpu_emulation_required(args, arch):
|
||||
if not pmb.parse.arch.cpu_emulation_required(arch):
|
||||
return None
|
||||
if suffix == "native":
|
||||
return "native"
|
||||
|
|
|
@ -142,7 +142,7 @@ def run_abuild(args, pkgname, arch, apkbuild_path, kbuild_out):
|
|||
# Create the apk package
|
||||
env = {"CARCH": arch,
|
||||
"CHOST": arch,
|
||||
"CBUILD": args.arch_native,
|
||||
"CBUILD": pmb.config.arch_native,
|
||||
"SUDO_APK": "abuild-apk --no-progress"}
|
||||
cmd = ["abuild", "rootpkg"]
|
||||
pmb.chroot.user(args, cmd, working_dir=build_path, env=env)
|
||||
|
@ -177,11 +177,11 @@ def package_kernel(args):
|
|||
else:
|
||||
function_body = pmb.parse.function_body(aport + "/APKBUILD", "package")
|
||||
kbuild_out = find_kbuild_output_dir(function_body)
|
||||
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
|
||||
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
|
||||
|
||||
# Install package dependencies
|
||||
depends, _ = pmb.build._package.build_depends(
|
||||
args, apkbuild, args.arch_native, strict=False)
|
||||
args, apkbuild, pmb.config.arch_native, strict=False)
|
||||
pmb.build.init(args, suffix)
|
||||
pmb.chroot.apk.install(args, depends, suffix)
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ def menuconfig(args, pkgname, use_oldconfig):
|
|||
aport = pmb.helpers.pmaports.find(args, pkgname)
|
||||
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
|
||||
arch = args.arch or get_arch(apkbuild)
|
||||
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
|
||||
suffix = pmb.build.autodetect.suffix(apkbuild, arch)
|
||||
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
|
||||
hostspec = pmb.parse.arch.alpine_to_hostspec(arch)
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ def download(args, file):
|
|||
"""
|
||||
channel_cfg = pmb.config.pmaports.read_config_channel(args)
|
||||
mirrordir = channel_cfg["mirrordir_alpine"]
|
||||
base_url = f"{args.mirror_alpine}{mirrordir}/main/{args.arch_native}"
|
||||
base_url = f"{args.mirror_alpine}{mirrordir}/main/{pmb.config.arch_native}"
|
||||
return pmb.helpers.http.download(args, f"{base_url}/{file}", file)
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ def mark_in_chroot(args, suffix="native"):
|
|||
|
||||
def setup_qemu_emulation(args, suffix):
|
||||
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
||||
if not pmb.parse.arch.cpu_emulation_required(args, arch):
|
||||
if not pmb.parse.arch.cpu_emulation_required(arch):
|
||||
return
|
||||
|
||||
chroot = f"{args.work}/chroot_{suffix}"
|
||||
|
|
|
@ -90,6 +90,6 @@ def shutdown(args, only_install_related=False):
|
|||
|
||||
# Clean up the rest
|
||||
for arch in pmb.config.build_device_architectures:
|
||||
if pmb.parse.arch.cpu_emulation_required(args, arch):
|
||||
if pmb.parse.arch.cpu_emulation_required(arch):
|
||||
pmb.chroot.binfmt.unregister(args, arch)
|
||||
logging.debug("Shutdown complete")
|
||||
|
|
|
@ -158,7 +158,9 @@ def zap_pkgs_online_mismatch(args, confirm=True, dry=False):
|
|||
# Iterate over existing apk caches
|
||||
for path in paths:
|
||||
arch = os.path.basename(path).split("_", 2)[2]
|
||||
suffix = "native" if arch == args.arch_native else f"buildroot_{arch}"
|
||||
suffix = f"buildroot_{arch}"
|
||||
if arch == pmb.config.arch_native:
|
||||
suffix = "native"
|
||||
|
||||
# Clean the cache with apk
|
||||
logging.info(f"({suffix}) apk -v cache clean")
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import multiprocessing
|
||||
import os
|
||||
import pmb.parse.arch
|
||||
import sys
|
||||
|
||||
#
|
||||
|
@ -18,6 +19,7 @@ from pmb.config.merge_with_args import merge_with_args
|
|||
version = "1.38.0"
|
||||
pmb_src = os.path.normpath(os.path.realpath(__file__) + "/../../..")
|
||||
apk_keys_path = pmb_src + "/pmb/data/keys"
|
||||
arch_native = pmb.parse.arch.alpine_native()
|
||||
|
||||
# apk-tools minimum version
|
||||
# https://pkgs.alpinelinux.org/packages?name=apk-tools&branch=edge
|
||||
|
|
|
@ -31,15 +31,7 @@ import pmb.helpers.git
|
|||
args.device ("samsung-i9100", "qemu-amd64" etc.)
|
||||
args.work ("/home/user/.local/var/pmbootstrap", override with --work)
|
||||
|
||||
3. Shortcuts
|
||||
Long variables or function calls that always return the same information
|
||||
may have a shortcut defined, to make the code more readable (see
|
||||
add_shortcuts() below).
|
||||
|
||||
Example:
|
||||
args.arch_native ("x86_64" etc.)
|
||||
|
||||
4. Cache
|
||||
3. Cache
|
||||
pmbootstrap uses this dictionary to save the result of expensive
|
||||
results, so they work a lot faster the next time they are needed in the
|
||||
same session. Usually the cache is written to and read from in the same
|
||||
|
@ -54,7 +46,7 @@ import pmb.helpers.git
|
|||
|
||||
See add_cache() below for details.
|
||||
|
||||
5. Parsed configs
|
||||
4. Parsed configs
|
||||
Similar to the cache above, specific config files get parsed and added
|
||||
to args, so they can get accessed quickly (without parsing the configs
|
||||
over and over). These configs are not only used in one specific
|
||||
|
@ -116,11 +108,6 @@ def replace_placeholders(args):
|
|||
setattr(args, key, os.path.expanduser(getattr(args, key)))
|
||||
|
||||
|
||||
def add_shortcuts(args):
|
||||
""" Add convenience shortcuts """
|
||||
setattr(args, "arch_native", pmb.parse.arch.alpine_native())
|
||||
|
||||
|
||||
def add_cache(args):
|
||||
""" Add a caching dict (caches parsing of files etc. for the current
|
||||
session) """
|
||||
|
@ -142,7 +129,7 @@ def add_deviceinfo(args):
|
|||
""" Add and verify the deviceinfo (only after initialization) """
|
||||
setattr(args, "deviceinfo", pmb.parse.deviceinfo(args))
|
||||
arch = args.deviceinfo["arch"]
|
||||
if (arch != args.arch_native and
|
||||
if (arch != pmb.config.arch_native and
|
||||
arch not in pmb.config.build_device_architectures):
|
||||
raise ValueError("Arch '" + arch + "' is not available in"
|
||||
" postmarketOS. If you would like to add it, see:"
|
||||
|
@ -154,7 +141,6 @@ def init(args):
|
|||
fix_mirrors_postmarketos(args)
|
||||
pmb.config.merge_with_args(args)
|
||||
replace_placeholders(args)
|
||||
add_shortcuts(args)
|
||||
add_cache(args)
|
||||
|
||||
# Initialize logs (we could raise errors below)
|
||||
|
|
|
@ -507,7 +507,7 @@ def shutdown(args):
|
|||
def stats(args):
|
||||
# Chroot suffix
|
||||
suffix = "native"
|
||||
if args.arch != args.arch_native:
|
||||
if args.arch != pmb.config.arch_native:
|
||||
suffix = "buildroot_" + args.arch
|
||||
|
||||
# Install ccache and display stats
|
||||
|
|
|
@ -96,7 +96,7 @@ def apkindex_files(args, arch=None, user_repository=True, pmos=True,
|
|||
:returns: list of absolute APKINDEX.tar.gz file paths
|
||||
"""
|
||||
if not arch:
|
||||
arch = args.arch_native
|
||||
arch = pmb.config.arch_native
|
||||
|
||||
ret = []
|
||||
# Local user repository (for packages compiled with pmbootstrap)
|
||||
|
@ -209,7 +209,7 @@ def alpine_apkindex_path(args, repo="main", arch=None):
|
|||
raise RuntimeError("Invalid Alpine repository: " + repo)
|
||||
|
||||
# Download the file
|
||||
arch = arch or args.arch_native
|
||||
arch = arch or pmb.config.arch_native
|
||||
update(args, arch)
|
||||
|
||||
# Find it on disk
|
||||
|
|
|
@ -282,7 +282,7 @@ def providers(args, package, arch=None, must_exist=True, indexes=None):
|
|||
"""
|
||||
|
||||
if not indexes:
|
||||
arch = arch or args.arch_native
|
||||
arch = arch or pmb.config.arch_native
|
||||
indexes = pmb.helpers.repo.apkindex_files(args, arch)
|
||||
|
||||
for operator in [">", ">=", "=", "<=", "<", "~"]:
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# Copyright 2021 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import platform
|
||||
import fnmatch
|
||||
import platform
|
||||
import pmb.parse.arch
|
||||
|
||||
|
||||
def alpine_native():
|
||||
|
@ -22,7 +23,7 @@ def alpine_native():
|
|||
|
||||
def from_chroot_suffix(args, suffix):
|
||||
if suffix == "native":
|
||||
return args.arch_native
|
||||
return pmb.config.arch_native
|
||||
if suffix in [f"rootfs_{args.device}", f"installer_{args.device}"]:
|
||||
return args.deviceinfo["arch"]
|
||||
if suffix.startswith("buildroot_"):
|
||||
|
@ -95,9 +96,9 @@ def alpine_to_hostspec(arch):
|
|||
" to the right hostspec value")
|
||||
|
||||
|
||||
def cpu_emulation_required(args, arch):
|
||||
def cpu_emulation_required(arch):
|
||||
# Obvious case: host arch is target arch
|
||||
if args.arch_native == arch:
|
||||
if pmb.config.arch_native == arch:
|
||||
return False
|
||||
|
||||
# Other cases: host arch on the left, target archs on the right
|
||||
|
@ -106,8 +107,8 @@ def cpu_emulation_required(args, arch):
|
|||
"armv7": ["armel", "armhf"],
|
||||
"aarch64": ["armel", "armhf", "armv7"],
|
||||
}
|
||||
if args.arch_native in not_required:
|
||||
if arch in not_required[args.arch_native]:
|
||||
if pmb.config.arch_native in not_required:
|
||||
if arch in not_required[pmb.config.arch_native]:
|
||||
return False
|
||||
|
||||
# No match: then it's required
|
||||
|
|
|
@ -416,7 +416,7 @@ def arguments_newapkbuild(subparser):
|
|||
|
||||
def arguments_kconfig(subparser):
|
||||
# Allowed architectures
|
||||
arch_native = pmb.parse.arch.alpine_native()
|
||||
arch_native = pmb.config.arch_native
|
||||
arch_choices = set(pmb.config.build_device_architectures + [arch_native])
|
||||
|
||||
# Kconfig subparser
|
||||
|
@ -476,7 +476,7 @@ def arguments_repo_missing(subparser):
|
|||
if argcomplete:
|
||||
package.completer = package_completer
|
||||
ret.add_argument("--arch", choices=pmb.config.build_device_architectures,
|
||||
default=pmb.parse.arch.alpine_native())
|
||||
default=pmb.config.arch_native)
|
||||
ret.add_argument("--built", action="store_true",
|
||||
help="include packages which exist in the binary repos")
|
||||
ret.add_argument("--overview", action="store_true",
|
||||
|
@ -523,7 +523,7 @@ def add_packages_arg(subparser, name="packages", *args, **kwargs):
|
|||
|
||||
def arguments():
|
||||
parser = argparse.ArgumentParser(prog="pmbootstrap")
|
||||
arch_native = pmb.parse.arch.alpine_native()
|
||||
arch_native = pmb.config.arch_native
|
||||
arch_choices = set(pmb.config.build_device_architectures + [arch_native])
|
||||
mirrors_pmos_default = pmb.config.defaults["mirrors_postmarketos"]
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
|
|||
|
||||
# QEMU mach-virt's max CPU count is 8, limit it so it will work correctly
|
||||
# on systems with more than 8 CPUs
|
||||
if arch != args.arch_native and ncpus > 8:
|
||||
if arch != pmb.config.arch_native and ncpus > 8:
|
||||
ncpus = 8
|
||||
|
||||
if args.host_qemu:
|
||||
|
@ -130,7 +130,7 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
|
|||
rootfs_native + "/usr/share"})
|
||||
|
||||
command = []
|
||||
if args.arch_native in ["aarch64", "armv7"]:
|
||||
if pmb.config.arch_native in ["aarch64", "armv7"]:
|
||||
# Workaround for QEMU failing on aarch64 asymetric multiprocessor
|
||||
# arch (big/little architecture
|
||||
# https://en.wikipedia.org/wiki/ARM_big.LITTLE) see
|
||||
|
@ -141,12 +141,12 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
|
|||
logging.info("QEMU will run on big/little architecture on the"
|
||||
f" first {ncpus} cores (from /proc/cpuinfo)")
|
||||
command += [rootfs_native + "/lib/ld-musl-" +
|
||||
args.arch_native + ".so.1"]
|
||||
pmb.config.arch_native + ".so.1"]
|
||||
command += [rootfs_native + "/usr/bin/taskset"]
|
||||
command += ["-c", "0-" + str(ncpus - 1)]
|
||||
|
||||
command += [rootfs_native + "/lib/ld-musl-" +
|
||||
args.arch_native + ".so.1"]
|
||||
pmb.config.arch_native + ".so.1"]
|
||||
command += ["--library-path=" + rootfs_native + "/lib:" +
|
||||
rootfs_native + "/usr/lib:" +
|
||||
rootfs_native + "/usr/lib/pulseaudio"]
|
||||
|
@ -189,7 +189,7 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
|
|||
" yet.")
|
||||
|
||||
# Kernel Virtual Machine (KVM) support
|
||||
native = args.arch_native == args.deviceinfo["arch"]
|
||||
native = pmb.config.arch_native == args.deviceinfo["arch"]
|
||||
if args.qemu_kvm and native and os.path.exists("/dev/kvm"):
|
||||
command += ["-enable-kvm"]
|
||||
command += ["-cpu", "host"]
|
||||
|
|
|
@ -315,7 +315,7 @@ def test_finish(args, monkeypatch):
|
|||
assert "Package not found" in str(e.value)
|
||||
|
||||
# Existing output path
|
||||
func(args, apkbuild, args.arch_native, output)
|
||||
func(args, apkbuild, pmb.config.arch_native, output)
|
||||
|
||||
|
||||
def test_package(args):
|
||||
|
@ -362,7 +362,7 @@ def test_build_depends_high_level(args, monkeypatch):
|
|||
|
||||
# Remove hello-world
|
||||
pmb.helpers.run.root(args, ["rm", output_hello_outside])
|
||||
pmb.build.index_repo(args, args.arch_native)
|
||||
pmb.build.index_repo(args, pmb.config.arch_native)
|
||||
args.cache["built"] = {}
|
||||
|
||||
# Ask to build the wrapper. It should not build the wrapper (it exists, not
|
||||
|
@ -414,7 +414,7 @@ def test_build_local_source_high_level(args, tmpdir):
|
|||
|
||||
# Test native arch and foreign arch chroot
|
||||
channel = pmb.config.pmaports.read_config(args)["channel"]
|
||||
for arch in [args.arch_native, "armhf"]:
|
||||
for arch in [pmb.config.arch_native, "armhf"]:
|
||||
# Delete all hello-world --src packages
|
||||
pattern = f"{args.work}/packages/{channel}/{arch}/hello-world-*_p*.apk"
|
||||
for path in glob.glob(pattern):
|
||||
|
@ -432,5 +432,5 @@ def test_build_local_source_high_level(args, tmpdir):
|
|||
pmb.helpers.run.root(args, ["rm", paths[0]])
|
||||
|
||||
# Clean up: update index, delete temp folder
|
||||
pmb.build.index_repo(args, args.arch_native)
|
||||
pmb.build.index_repo(args, pmb.config.arch_native)
|
||||
pmb.helpers.run.root(args, ["rm", "-r", tmpdir])
|
||||
|
|
|
@ -27,8 +27,8 @@ def test_keys(args):
|
|||
# Get the alpine-keys apk filename
|
||||
pmb.chroot.init(args)
|
||||
version = pmb.parse.apkindex.package(args, "alpine-keys")["version"]
|
||||
pattern = (args.work + "/cache_apk_" + args.arch_native + "/alpine-keys-" +
|
||||
version + ".*.apk")
|
||||
pattern = (args.work + "/cache_apk_" + pmb.config.arch_native +
|
||||
"/alpine-keys-" + version + ".*.apk")
|
||||
filename = os.path.basename(glob.glob(pattern)[0])
|
||||
|
||||
# Extract it to a temporary folder
|
||||
|
|
|
@ -142,7 +142,7 @@ def test_pkgrel_bump_high_level(args, tmpdir):
|
|||
|
||||
# Delete package with previous soname (--auto-dry exits with >0 now)
|
||||
channel = pmb.config.pmaports.read_config(args)["channel"]
|
||||
arch = args.arch_native
|
||||
arch = pmb.config.arch_native
|
||||
apk_path = f"{tmpdir}/packages/{channel}/{arch}/testlib-1.0-r0.apk"
|
||||
pmb.helpers.run.root(args, ["rm", apk_path])
|
||||
pmbootstrap(args, tmpdir, ["index"])
|
||||
|
|
Loading…
Reference in New Issue