Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCons: Address minor show_progress issues #99292

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions methods.py
Original file line number Diff line number Diff line change
@@ -857,10 +857,8 @@ def using_emcc(env):


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

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

# Progress reporting is not available in non-TTY environments since it
# messes with the output (for example, when writing to a file).
self.display = cast(bool, self.max and env["progress"] and IS_TTY)

def __call__(self, node, *args, **kw):
self.count += 1
if self.max != 0:
if self.display:
percent = int(min(self.count * 100 / self.max, 100))
sys.stdout.write(f"\r[{percent:3d}%] ")
sys.stdout.flush()

from SCons.Script import Progress
from SCons.Script.Main import GetBuildFailures

progressor = ShowProgress()
Progress(progressor)

def progress_finish(target, source, env):
def progress_finish():
if len(GetBuildFailures()):
return
try:
with open(NODE_COUNT_FILENAME, "w", encoding="utf-8", newline="\n") as f:
f.write(f"{progressor.count}\n")
except OSError:
pass

env.AlwaysBuild(
env.CommandNoCache(
"progress_finish", [], env.Action(progress_finish, "Building node count database .scons_node_count")
)
)
atexit.register(progress_finish)


def convert_size(size_bytes: int) -> str: