"""
import argparse
-import enum
import dataclasses
+import enum
import logging
import os
import pathlib
import time
import warnings
import webbrowser
+from collections.abc import Callable, Iterable
# for Python 3.8
from typing import (
- cast,
Any,
- Callable,
- Dict,
- Iterable,
- List,
- Optional,
- Tuple,
- Union,
+ cast,
)
logger = logging.getLogger("wasm_build")
def parse_emconfig(
emconfig: pathlib.Path = EM_CONFIG,
-) -> Tuple[pathlib.Path, pathlib.Path]:
+) -> tuple[pathlib.Path, pathlib.Path]:
"""Parse EM_CONFIG file and lookup EMSCRIPTEN_ROOT and NODE_JS.
The ".emscripten" config file is a Python snippet that uses "EM_CONFIG"
with open(emconfig, encoding="utf-8") as f:
code = f.read()
# EM_CONFIG file is a Python snippet
- local: Dict[str, Any] = {}
+ local: dict[str, Any] = {}
exec(code, globals(), local)
emscripten_root = pathlib.Path(local["EMSCRIPTEN_ROOT"])
node_js = pathlib.Path(local["NODE_JS"])
name: str
pythonexe: str
- config_site: Optional[pathlib.PurePath]
- configure_wrapper: Optional[pathlib.Path]
- make_wrapper: Optional[pathlib.PurePath]
- environ: Dict[str, Any]
+ config_site: pathlib.PurePath | None
+ configure_wrapper: pathlib.Path | None
+ make_wrapper: pathlib.PurePath | None
+ environ: dict[str, Any]
check: Callable[[], None]
# Used for build_emports().
- ports: Optional[pathlib.PurePath]
- cc: Optional[pathlib.PurePath]
+ ports: pathlib.PurePath | None
+ cc: pathlib.PurePath | None
- def getenv(self, profile: "BuildProfile") -> Dict[str, Any]:
+ def getenv(self, profile: "BuildProfile") -> dict[str, Any]:
return self.environ.copy()
# git / upstream / tot-upstream installation
version = version[:-4]
version_tuple = cast(
- Tuple[int, int, int], tuple(int(v) for v in version.split("."))
+ tuple[int, int, int], tuple(int(v) for v in version.split("."))
)
if version_tuple < EMSDK_MIN_VERSION:
raise ConditionError(
return []
@property
- def emport_args(self) -> List[str]:
+ def emport_args(self) -> list[str]:
"""Host-specific port args (Emscripten)."""
cls = type(self)
if self is cls.wasm64_emscripten:
return []
@property
- def embuilder_args(self) -> List[str]:
+ def embuilder_args(self) -> list[str]:
"""Host-specific embuilder args (Emscripten)."""
cls = type(self)
if self is cls.wasm64_emscripten:
return self in {cls.browser, cls.browser_debug}
@property
- def emport_args(self) -> List[str]:
+ def emport_args(self) -> list[str]:
"""Target-specific port args."""
cls = type(self)
if self in {cls.browser_debug, cls.node_debug}:
name: str
support_level: SupportLevel
host: Host
- target: Union[EmscriptenTarget, None] = None
- dynamic_linking: Union[bool, None] = None
- pthreads: Union[bool, None] = None
+ target: EmscriptenTarget | None = None
+ dynamic_linking: bool | None = None
+ pthreads: bool | None = None
default_testopts: str = "-j2"
@property
return self.builddir / "Makefile"
@property
- def configure_cmd(self) -> List[str]:
+ def configure_cmd(self) -> list[str]:
"""Generate configure command"""
# use relative path, so WASI tests can find lib prefix.
# pathlib.Path.relative_to() does not work here.
return cmd
@property
- def make_cmd(self) -> List[str]:
+ def make_cmd(self) -> list[str]:
"""Generate make command"""
cmd = ["make"]
platform = self.host.platform
cmd.insert(0, os.fspath(platform.make_wrapper))
return cmd
- def getenv(self) -> Dict[str, Any]:
+ def getenv(self) -> dict[str, Any]:
"""Generate environ dict for platform"""
env = os.environ.copy()
if hasattr(os, "process_cpu_count"):
env.pop(key, None)
elif key == "PATH":
# list of path items, prefix with extra paths
- new_path: List[pathlib.PurePath] = []
+ new_path: list[pathlib.PurePath] = []
new_path.extend(self.host.get_extra_paths())
new_path.extend(value)
env[key] = os.pathsep.join(os.fspath(p) for p in new_path)
self,
cmd: Iterable[str],
args: Iterable[str] = (),
- cwd: Optional[pathlib.Path] = None,
+ cwd: pathlib.Path | None = None,
) -> int:
cmd = list(cmd)
cmd.extend(args)
self._check_execute()
return self.run_make("pythoninfo", *args)
- def run_test(self, target: str, testopts: Optional[str] = None) -> int:
+ def run_test(self, target: str, testopts: str | None = None) -> int:
"""Run buildbottests"""
self._check_execute()
if testopts is None:
)
# Don't list broken and experimental variants in help
-platforms_choices = list(p.name for p in _profiles) + ["cleanall"]
-platforms_help = list(p.name for p in _profiles if p.support_level) + [
- "cleanall"
-]
+platforms_choices = [p.name for p in _profiles] + ["cleanall"]
+platforms_help = [p.name for p in _profiles if p.support_level] + ["cleanall"]
parser.add_argument(
"platform",
metavar="PLATFORM",
choices=platforms_choices,
)
-ops = dict(
- build="auto build (build 'build' Python, emports, configure, compile)",
- configure="run ./configure",
- compile="run 'make all'",
- pythoninfo="run 'make pythoninfo'",
- test="run 'make buildbottest TESTOPTS=...' (supports parallel tests)",
- hostrunnertest="run 'make hostrunnertest TESTOPTS=...'",
- repl="start interactive REPL / webserver + browser session",
- clean="run 'make clean'",
- cleanall="remove all build directories",
- emports="build Emscripten port with embuilder (only Emscripten)",
-)
+ops = {
+ "build": "auto build (build 'build' Python, emports, configure, compile)",
+ "configure": "run ./configure",
+ "compile": "run 'make all'",
+ "pythoninfo": "run 'make pythoninfo'",
+ "test": "run 'make buildbottest TESTOPTS=...' (supports parallel tests)",
+ "hostrunnertest": "run 'make hostrunnertest TESTOPTS=...'",
+ "repl": "start interactive REPL / webserver + browser session",
+ "clean": "run 'make clean'",
+ "cleanall": "remove all build directories",
+ "emports": "build Emscripten port with embuilder (only Emscripten)",
+}
ops_help = "\n".join(f"{op:16s} {help}" for op, help in ops.items())
parser.add_argument(
"ops",