diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2019-01-04 17:27:38 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2019-01-15 14:01:32 -0500 |
commit | 92b343f2f73ad02f8c06a3468719a0d892e9050e (patch) | |
tree | 26a995b211f2a36138f90489ae41f6261816829c | |
parent | 7993747e139744fe6c8fb0f5cd324627629ec970 (diff) | |
download | meson-92b343f2f73ad02f8c06a3468719a0d892e9050e.zip meson-92b343f2f73ad02f8c06a3468719a0d892e9050e.tar.gz meson-92b343f2f73ad02f8c06a3468719a0d892e9050e.tar.bz2 |
mesonmain: Force to output UTF-8 even when the locale isn't
Otherwise Python gets all confused and it makes testing difficult.
Also minimally emulate the behaviour of the normal object to make the rest
of the code happy.
-rw-r--r-- | mesonbuild/mesonmain.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index c11d044..69c3f9f 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 @@ -148,6 +149,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+.') @@ -155,6 +167,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') |