Skip to content

Commit

Permalink
FIX on buildall fail, print info after exiting rich context
Browse files Browse the repository at this point in the history
Otherwise the rich Live context will sometimes overwrite part of the failure
message.
  • Loading branch information
hoodmane committed Jan 28, 2024
1 parent d4450d9 commit 98ce1c1
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions pyodide-build/pyodide_build/buildall.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from time import perf_counter, sleep
from typing import Any

from packaging.utils import canonicalize_name
from pyodide_lock import PyodideLockSpec
from pyodide_lock.spec import PackageSpec as PackageLockSpec
from pyodide_lock.utils import update_package_sha256
Expand All @@ -28,6 +27,8 @@
from rich.spinner import Spinner
from rich.table import Table

from packaging.utils import canonicalize_name

from . import build_env, recipe
from .buildpkg import needs_rebuild
from .common import (
Expand All @@ -42,8 +43,9 @@


class BuildError(Exception):
def __init__(self, returncode: int) -> None:
def __init__(self, returncode: int, msg: str) -> None:
self.returncode = returncode
self.msg = msg
super().__init__()


Expand Down Expand Up @@ -164,14 +166,15 @@ def build(self, build_args: BuildArgs, build_dir: Path) -> None:
)

if p.returncode != 0:
logger.error(f"Error building {self.name}. Printing build logs.")
msg = []
msg.append(f"Error building {self.name}. Printing build logs.")
logfile = self.pkgdir / "build.log"
if logfile.is_file():
logger.error(logfile.read_text(encoding="utf-8"))
msg.append(logfile.read_text(encoding="utf-8") + "\n")
else:
logger.error("ERROR: No build log found.")
logger.error("ERROR: cancelling buildall")
raise BuildError(p.returncode)
msg.append("ERROR: No build log found.")
msg.append(f"ERROR: cancelling buildall due to error building {self.name}")
raise BuildError(p.returncode, "\n".join(msg))


class PackageStatus:
Expand Down Expand Up @@ -618,27 +621,29 @@ def builder(n: int) -> None:
Thread(target=builder, args=(n + 1,), daemon=True).start()

num_built = len(already_built)
with Live(progress_formatter, console=console_stdout):
while num_built < len(pkg_map):
match built_queue.get():
case BuildError() as err:
raise SystemExit(err.returncode)
case Exception() as err:
raise err
case a_package:
# MyPy should understand that this is a BasePackage
assert not isinstance(a_package, Exception)
pkg = a_package

num_built += 1

progress_formatter.update_progress_bar()

for _dependent in pkg.host_dependents:
dependent = pkg_map[_dependent]
dependent.unbuilt_host_dependencies.remove(pkg.name)
if len(dependent.unbuilt_host_dependencies) == 0:
build_queue.put((job_priority(dependent), dependent))
try:
with Live(progress_formatter, console=console_stdout):
while num_built < len(pkg_map):
match built_queue.get():
case BaseException() as err:
raise err
case a_package:
# MyPy should understand that this is a BasePackage
assert not isinstance(a_package, Exception)
pkg = a_package

num_built += 1

progress_formatter.update_progress_bar()

for _dependent in pkg.host_dependents:
dependent = pkg_map[_dependent]
dependent.unbuilt_host_dependencies.remove(pkg.name)
if len(dependent.unbuilt_host_dependencies) == 0:
build_queue.put((job_priority(dependent), dependent))
except BuildError as err:
logger.error(err.msg)
sys.exit(err.returncode)


def generate_packagedata(
Expand Down

0 comments on commit 98ce1c1

Please sign in to comment.