Skip to content

Commit a74ae6a

Browse files
committed
Decode command output conservatively
On win32, rather than reading the temporary file used for external command output as text, read it as bytes and convert to the codec of the stream it will be written to, with suitable error fallback defined so it doesn't fail. Affects Configure usags. Fixes SCons#3529. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 67e030c commit a74ae6a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
6969
From Mats Wichmann:
7070
- Add support for Python 3.13 (as of alpha 2). So far only affects
7171
expected bytecodes in ActionTests.py.
72+
- Be more cautious about encodings fetching command output on Windows.
73+
Problem occurs in piped-spawn scenario, used by Configure tests.
74+
Fixes #3529.
7275

7376

7477
RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ FIXES
5050
- MSVS: Fix the msvs project generation test scripts so that "false positive" tests
5151
results are not possible when the initial build is successful and the command-line
5252
build of the project file fails.
53+
- On Windows platform, when collecting command output (Configure checks),
54+
make sure decoding of bytes doesn't fail.
5355

5456
IMPROVEMENTS
5557
------------

SCons/Platform/win32.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,18 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
165165
# and do clean up stuff
166166
if stdout is not None and not stdoutRedirected:
167167
try:
168-
with open(tmpFileStdoutName) as tmpFileStdout:
169-
stdout.write(tmpFileStdout.read())
168+
with open(tmpFileStdoutName, "rb") as tmpFileStdout:
169+
output = tmpFileStdout.read()
170+
stdout.write(output.decode(stdout.encoding, "replace"))
170171
os.remove(tmpFileStdoutName)
171172
except OSError:
172173
pass
173174

174175
if stderr is not None and not stderrRedirected:
175176
try:
176-
with open(tmpFileStderrName) as tmpFileStderr:
177-
stderr.write(tmpFileStderr.read())
177+
with open(tmpFileStderrName, "rb") as tmpFileStderr:
178+
errors = tmpFileStderr.read()
179+
stdout.write(errors.decode(stderr.encoding, "replace"))
178180
os.remove(tmpFileStderrName)
179181
except OSError:
180182
pass

0 commit comments

Comments
 (0)