Skip to content

Commit cabb3ca

Browse files
committed
Merge pull request godotengine#90551 from Repiteo/scons/silence-msvc-for-real
SCons: Silence MSVC output bloat without hiding errors
2 parents 91aca6e + b278cef commit cabb3ca

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

platform/windows/detect.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ def get_opts():
202202
BoolVariable("use_asan", "Use address sanitizer (ASAN)", False),
203203
BoolVariable("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False),
204204
BoolVariable("incremental_link", "Use MSVC incremental linking. May increase or decrease build times.", False),
205-
BoolVariable(
206-
"silence_msvc", "Silence MSVC's stdout to decrease output log bloat. May hide error messages.", False
207-
),
205+
BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting any errors to stderr.", True),
208206
("angle_libs", "Path to the ANGLE static libraries", ""),
209207
# Direct3D 12 support.
210208
(
@@ -398,16 +396,32 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
398396
env["MAXLINELENGTH"] = 8192 # Windows Vista and beyond, so always applicable.
399397

400398
if env["silence_msvc"]:
401-
env.Prepend(CCFLAGS=[">", "NUL"])
402-
env.Prepend(LINKFLAGS=[">", "NUL"])
399+
from tempfile import mkstemp
400+
401+
old_spawn = env["SPAWN"]
402+
403+
def spawn_capture(sh, escape, cmd, args, env):
404+
# We only care about cl/link, process everything else as normal.
405+
if args[0] not in ["cl", "link"]:
406+
return old_spawn(sh, escape, cmd, args, env)
403407

404-
# "> NUL" fails if using a tempfile, circumvent by removing the argument altogether.
405-
old_esc_func = env["TEMPFILEARGESCFUNC"]
408+
tmp_stdout, tmp_stdout_name = mkstemp()
409+
os.close(tmp_stdout)
410+
args.append(f">{tmp_stdout_name}")
411+
ret = old_spawn(sh, escape, cmd, args, env)
412+
413+
try:
414+
with open(tmp_stdout_name, "rt", encoding=sys.stdout.encoding) as tmp_stdout:
415+
# First line is always bloat, subsequent lines are always errors. This filter sends
416+
# either just the errors to stderr, or an empty string to effectively do nothing.
417+
sys.stderr.write("".join(tmp_stdout.readlines()[1:]))
418+
os.remove(tmp_stdout_name)
419+
except OSError:
420+
pass
406421

407-
def trim_nul(arg):
408-
return "" if arg in [">", "NUL"] else old_esc_func(arg)
422+
return ret
409423

410-
env["TEMPFILEARGESCFUNC"] = trim_nul
424+
env["SPAWN"] = spawn_capture
411425

412426
if env["debug_crt"]:
413427
# Always use dynamic runtime, static debug CRT breaks thread_local.

0 commit comments

Comments
 (0)