diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-01-17 00:40:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-17 00:40:56 +0200 |
commit | e6df5a758691e7e2a2f3b0c7ad51c3b5f28e1aec (patch) | |
tree | 920882852c0ab1d53e17dd6fc1c3f2ea6fc719be | |
parent | 2ba2c7771fc27a086d3b73bbb25462eff300c2a2 (diff) | |
parent | 92b343f2f73ad02f8c06a3468719a0d892e9050e (diff) | |
download | meson-e6df5a758691e7e2a2f3b0c7ad51c3b5f28e1aec.zip meson-e6df5a758691e7e2a2f3b0c7ad51c3b5f28e1aec.tar.gz meson-e6df5a758691e7e2a2f3b0c7ad51c3b5f28e1aec.tar.bz2 |
Merge pull request #4719 from ocrete/fix-posix-lang
Replace surrogates with valid codepoints to print env
-rw-r--r-- | mesonbuild/mesonmain.py | 17 | ||||
-rw-r--r-- | mesonbuild/mtest.py | 4 |
2 files changed, 19 insertions, 2 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 7236d1a..037d76c 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -17,6 +17,7 @@ import os.path import importlib import traceback import argparse +import codecs from . import mesonlib from . import mlog @@ -150,6 +151,17 @@ def run_script_command(script_name, script_args): mlog.exception(e) return 1 +def ensure_stdout_accepts_unicode(): + if sys.stdout.encoding and not sys.stdout.encoding.upper().startswith('UTF-'): + if sys.version_info >= (3, 7): + sys.stdout.reconfigure(errors='surrogateescape') + else: + sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach(), + errors='surrogateescape') + sys.stdout.encoding = 'UTF-8' + if not hasattr(sys.stdout, 'buffer'): + sys.stdout.buffer = sys.stdout.raw if hasattr(sys.stdout, 'raw') else sys.stdout + def run(original_args, mainfile): if sys.version_info < (3, 5): print('Meson works correctly only with python 3.5+.') @@ -157,6 +169,11 @@ def run(original_args, mainfile): print('Please update your environment') return 1 + # Meson gets confused if stdout can't output Unicode, if the + # locale isn't Unicode, just force stdout to accept it. This tries + # to emulate enough of PEP 540 to work elsewhere. + ensure_stdout_accepts_unicode() + # https://github.com/mesonbuild/meson/issues/3653 if sys.platform.lower() == 'msys': mlog.error('This python3 seems to be msys/python on MSYS2 Windows, which is known to have path semantics incompatible with Meson') diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 8ce9538..b4bd4f2 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -647,8 +647,8 @@ Timeout: %4d self.logfilename = logfile_base + '.txt' self.jsonlogfilename = logfile_base + '.json' - self.jsonlogfile = open(self.jsonlogfilename, 'w', encoding='utf-8') - self.logfile = open(self.logfilename, 'w', encoding='utf-8') + self.jsonlogfile = open(self.jsonlogfilename, 'w', encoding='utf-8', errors='replace') + self.logfile = open(self.logfilename, 'w', encoding='utf-8', errors='surrogateescape') self.logfile.write('Log of Meson test suite run on %s\n\n' % datetime.datetime.now().isoformat()) |