FIX on buildall fail, print info after exiting rich context (#4441)

Otherwise the rich Live context will sometimes overwrite part of the failure message.
This commit is contained in:
Hood Chatham 2024-01-28 13:16:03 -08:00 committed by GitHub
parent 5a3f10fa59
commit 5da4725830
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 25 deletions

View File

@ -42,8 +42,9 @@ from .pywasmcross import BuildArgs
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__()
@ -164,14 +165,15 @@ class Package(BasePackage):
)
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:
@ -556,7 +558,7 @@ def build_from_graph(
if len(pkg.unbuilt_host_dependencies) == 0:
build_queue.put((job_priority(pkg), pkg))
built_queue: Queue[BasePackage | Exception] = Queue()
built_queue: Queue[BasePackage | BaseException] = Queue()
thread_lock = Lock()
queue_idx = 1
building_rust_pkg = False
@ -618,27 +620,27 @@ def build_from_graph(
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
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 BasePackage() as pkg:
pass
num_built += 1
num_built += 1
progress_formatter.update_progress_bar()
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))
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(