diff --git a/pmb/build/_package.py b/pmb/build/_package.py index 44567d55..b1e26a75 100644 --- a/pmb/build/_package.py +++ b/pmb/build/_package.py @@ -7,6 +7,7 @@ from pmb.core.arch import Arch from pmb.core.context import Context from pmb.core.pkgrepo import pkgrepo_relative_path from pmb.helpers import logging +from pmb.types import CrossCompileType from pathlib import Path import pmb.build @@ -196,7 +197,7 @@ class BuildQueueItem(TypedDict): output_path: Path channel: str depends: list[str] - cross: str + cross: CrossCompileType chroot: Chroot @@ -337,7 +338,10 @@ def packages( # Add a package to the build queue, fetch it's dependency, and # add record build helpers to installed (e.g. sccache) def queue_build( - aports: Path, apkbuild: dict[str, Any], depends: list[str], cross: Optional[str] = None + aports: Path, + apkbuild: dict[str, Any], + depends: list[str], + cross: CrossCompileType = None, ) -> list[str]: # Skip if already queued name = apkbuild["pkgname"] diff --git a/pmb/build/autodetect.py b/pmb/build/autodetect.py index 53bdb2ae..ecca044d 100644 --- a/pmb/build/autodetect.py +++ b/pmb/build/autodetect.py @@ -11,6 +11,7 @@ import pmb.helpers.pmaports from pmb.core import Chroot from pmb.core.context import get_context from pmb.meta import Cache +from pmb.types import CrossCompileType # FIXME (#2324): type hint Arch @@ -93,10 +94,8 @@ def chroot(apkbuild: dict[str, str], arch: Arch) -> Chroot: return Chroot.buildroot(arch) -def crosscompile(apkbuild, arch: Arch): - """ - :returns: None, "native", "crossdirect" - """ +def crosscompile(apkbuild, arch: Arch) -> CrossCompileType: + """Decide the type of compilation necessary to build a given APKBUILD.""" if not get_context().cross: return None if not arch.cpu_emulation_required(): diff --git a/pmb/types.py b/pmb/types.py index a849ab02..f1a41537 100644 --- a/pmb/types.py +++ b/pmb/types.py @@ -3,10 +3,11 @@ from argparse import Namespace from pathlib import Path -from typing import Optional, TypedDict, Union +from typing import Literal, Optional, TypedDict, Union from pmb.core.arch import Arch +CrossCompileType = Optional[Union[Literal["native"], Literal["crossdirect"]]] PathString = Union[Path, str] Env = dict[str, PathString]