Skip to content

Commit df6ac39

Browse files
committed
SCons: Fix minor show_progress issues
1 parent 2b7ea62 commit df6ac39

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

methods.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -857,10 +857,8 @@ def using_emcc(env):
857857

858858

859859
def show_progress(env):
860-
# Progress reporting is not available in non-TTY environments since it messes with the output
861-
# (for example, when writing to a file). Ninja has its own progress/tracking tool that clashes
862-
# with ours.
863-
if not env["progress"] or not IS_TTY or env["ninja"]:
860+
# Ninja has its own progress/tracking tool that clashes with ours.
861+
if env["ninja"]:
864862
return
865863

866864
NODE_COUNT_FILENAME = f"{base_folder_path}.scons_node_count"
@@ -877,30 +875,33 @@ def __init__(self):
877875
if self.max == 0:
878876
print("NOTE: Performing initial build, progress percentage unavailable!")
879877

878+
# Progress reporting is not available in non-TTY environments since it
879+
# messes with the output (for example, when writing to a file).
880+
self.display = cast(bool, self.max and env["progress"] and IS_TTY)
881+
880882
def __call__(self, node, *args, **kw):
881883
self.count += 1
882-
if self.max != 0:
884+
if self.display:
883885
percent = int(min(self.count * 100 / self.max, 100))
884886
sys.stdout.write(f"\r[{percent:3d}%] ")
885887
sys.stdout.flush()
886888

887889
from SCons.Script import Progress
890+
from SCons.Script.Main import GetBuildFailures
888891

889892
progressor = ShowProgress()
890893
Progress(progressor)
891894

892-
def progress_finish(target, source, env):
895+
def progress_finish():
896+
if len(GetBuildFailures()):
897+
return
893898
try:
894899
with open(NODE_COUNT_FILENAME, "w", encoding="utf-8", newline="\n") as f:
895900
f.write(f"{progressor.count}\n")
896901
except OSError:
897902
pass
898903

899-
env.AlwaysBuild(
900-
env.CommandNoCache(
901-
"progress_finish", [], env.Action(progress_finish, "Building node count database .scons_node_count")
902-
)
903-
)
904+
atexit.register(progress_finish)
904905

905906

906907
def convert_size(size_bytes: int) -> str:

0 commit comments

Comments
 (0)