pmb.types.CrossCompileType: split up None

Replace None with the three things it is actually used for to make the
code easier to follow:
* "autodetect"
* "unnecessary"
* "qemu-only"

I've used the term "unnecessary" instead of "native", because "native"
was previously used for "cross-native", then "cross-native2" and it
still sounds similar to these.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
This commit is contained in:
Oliver Smith 2025-03-14 18:28:45 +01:00
parent 0625ece550
commit bef3b43343
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
4 changed files with 17 additions and 12 deletions

View file

@ -405,15 +405,15 @@ def process_package(
dep = depends.pop(0)
if is_cached_or_cache(arch, pmb.helpers.package.remove_operators(dep)):
continue
cross = None
aports, apkbuild = get_apkbuild(dep)
if not apkbuild:
continue
cross = pmb.build.autodetect.crosscompile(apkbuild, arch)
if context.no_depends:
pmb.helpers.repo.update(arch)
cross = pmb.build.autodetect.crosscompile(apkbuild, arch)
_dep_arch = Arch.native() if cross == "cross-native2" else arch
if not pmb.parse.apkindex.package(dep, _dep_arch, False):
raise RuntimeError(
@ -493,7 +493,7 @@ def packages(
aports: Path,
apkbuild: dict[str, Any],
depends: list[str],
cross: CrossCompileType = None,
cross: CrossCompileType = "autodetect",
) -> list[str]:
# Skip if already queued
name = apkbuild["pkgname"]
@ -501,7 +501,6 @@ def packages(
return []
pkg_arch = pmb.build.autodetect.arch(apkbuild) if arch is None else arch
chroot = pmb.build.autodetect.chroot(apkbuild, pkg_arch)
cross = cross or pmb.build.autodetect.crosscompile(apkbuild, pkg_arch)
pkgver = get_pkgver(apkbuild["pkgver"], src is None)
channel = pmb.config.pmaports.read_config(aports)["channel"]
@ -614,8 +613,8 @@ def packages(
" build the package with --src again."
)
cross = None
prev_cross = None
cross = "autodetect"
prev_cross = "autodetect"
hostchroot = None # buildroot for the architecture we're building for
total_pkgs = len(build_queue)
@ -664,7 +663,7 @@ def packages(
if "rust" in all_dependencies or "cargo" in all_dependencies:
pmb.chroot.apk.install(["sccache"], chroot)
if cross != prev_cross:
if cross != prev_cross and cross not in ["unnecessary", "qemu-only"]:
pmb.build.init_compiler(context, pkg_depends, cross, pkg_arch)
if cross == "crossdirect":
pmb.chroot.mount_native_into_foreign(chroot)

View file

@ -95,13 +95,13 @@ def chroot(apkbuild: Apkbuild, arch: Arch) -> Chroot:
def crosscompile(apkbuild: Apkbuild, arch: Arch) -> CrossCompileType:
"""Decide the type of compilation necessary to build a given APKBUILD."""
if not get_context().cross:
return None
return "qemu-only"
if not arch.cpu_emulation_required():
return None
return "unnecessary"
if "pmb:cross-native" in apkbuild["options"]:
return "cross-native"
if arch.is_native() or "pmb:cross-native2" in apkbuild["options"]:
return "cross-native2"
if "!pmb:crossdirect" in apkbuild["options"]:
return None
return "qemu-only"
return "crossdirect"

View file

@ -202,7 +202,6 @@ def run_abuild(
depending on the cross-compiler method and target architecture), copy
the aport to the chroot and execute abuild.
:param cross: None, "cross-native", "cross-native2" or "crossdirect"
:param src: override source used to build the package with a local folder
:param bootstrap_stage: pass a BOOTSTRAP= env var with the value to abuild
:returns: (output, cmd, env), output is the destination apk path relative

View file

@ -8,7 +8,14 @@ from typing import Any, Literal, TypedDict
from pmb.core.arch import Arch
CrossCompileType = Literal["crossdirect", "cross-native", "cross-native2"] | None
CrossCompileType = Literal[
"autodetect",
"unnecessary",
"qemu-only",
"crossdirect",
"cross-native",
"cross-native2",
]
RunOutputTypeDefault = Literal["log", "stdout", "interactive", "tui", "null"]
RunOutputTypePopen = Literal["background", "pipe"]
RunOutputType = RunOutputTypeDefault | RunOutputTypePopen