Skip to content

Avoid ascii/utf encoding errors on some systems #1555

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

Merged
merged 1 commit into from
Mar 6, 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
18 changes: 10 additions & 8 deletions Utilities/build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import sys
import errno

sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')

if platform.system() == 'Darwin':
shared_lib_ext = '.dylib'
else:
Expand Down Expand Up @@ -564,19 +561,24 @@ def cmake_build(args, swiftc_exec, cmake_args, swift_flags, source_path,

if args.verbose:
print(' '.join(ninja_cmd))
# Note: encoding is explicitly set to None to indicate that the output must
# be bytes, not strings. This is to work around per-system differences in
# default encoding. Some systems have a default encoding of 'ascii', but that
# conflicts with this output, which can contain UTF encoded characters. The
# bytes are then written, instead of printed, to bypass issues with encoding.
ninjaProcess = subprocess.Popen(ninja_cmd, cwd=build_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env = os.environ,
encoding='utf-8')
env=os.environ,
encoding=None)
stdout, stderr = ninjaProcess.communicate()
if ninjaProcess.returncode != 0:
print(stdout)
sys.stdout.buffer.write(stdout)
print('Ninja invocation failed: ')
print(stderr)
sys.stderr.buffer.write(stderr)
sys.exit(ninjaProcess.returncode)
if args.verbose:
print(stdout)
sys.stdout.buffer.write(stdout)

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