Skip to content

Commit 22b351b

Browse files
committed
Avoid ascii/utf encoding errors on some systems
1 parent e0792ec commit 22b351b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Utilities/build-script-helper.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import sys
1010
import errno
1111

12-
sys.stdout.reconfigure(encoding='utf-8')
13-
sys.stderr.reconfigure(encoding='utf-8')
14-
1512
if platform.system() == 'Darwin':
1613
shared_lib_ext = '.dylib'
1714
else:
@@ -564,19 +561,24 @@ def cmake_build(args, swiftc_exec, cmake_args, swift_flags, source_path,
564561

565562
if args.verbose:
566563
print(' '.join(ninja_cmd))
564+
# Note: encoding is explicitly set to None to indicate that the output must
565+
# be bytes, not strings. This is to work around per-system differences in
566+
# default encoding. Some systems have a default encoding of 'ascii', but that
567+
# conflicts with this output, which can contain UTF encoded characters. The
568+
# bytes are then written, instead of printed, to bypass issues with encoding.
567569
ninjaProcess = subprocess.Popen(ninja_cmd, cwd=build_dir,
568570
stdout=subprocess.PIPE,
569571
stderr=subprocess.PIPE,
570-
env = os.environ,
571-
encoding='utf-8')
572+
env=os.environ,
573+
encoding=None)
572574
stdout, stderr = ninjaProcess.communicate()
573575
if ninjaProcess.returncode != 0:
574-
print(stdout)
576+
sys.stdout.buffer.write(stdout)
575577
print('Ninja invocation failed: ')
576-
print(stderr)
578+
sys.stderr.buffer.write(stderr)
577579
sys.exit(ninjaProcess.returncode)
578580
if args.verbose:
579-
print(stdout)
581+
sys.stdout.buffer.write(stdout)
580582

581583
def get_build_target(swiftc_path, args, cross_compile=False):
582584
"""Returns the target-triple of the current machine."""

0 commit comments

Comments
 (0)