From 03cc991f4f5706d94032963483387642e6b01217 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 23 Nov 2016 15:33:40 +0530 Subject: [PATCH 1/2] configure_file: Use utf-8 to write configured file Closes #1085 --- mesonbuild/mesonlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index b92be5f1a..4d9cc69f4 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -303,7 +303,7 @@ def do_conf_file(src, dst, confdata): replace_if_different(dst, dst_tmp) def dump_conf_header(ofilename, cdata): - with open(ofilename, 'w') as ofile: + with open(ofilename, 'w', encoding='utf-8') as ofile: ofile.write('''/* * Autogenerated by the Meson build system. * Do not edit, your changes will be lost. From 34394afce6db988800cfecbfa32b67301fd7ba3d Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 23 Nov 2016 16:00:33 +0530 Subject: [PATCH 2/2] meson.py: Warn if the encoding is not UTF-8 compatible --- meson.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/meson.py b/meson.py index 8c223e588..6dc5c7a8b 100755 --- a/meson.py +++ b/meson.py @@ -14,10 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mesonbuild import mesonmain -import sys, os +from mesonbuild import mlog, mesonmain +import sys, os, locale def main(): + # Warn if the locale is not UTF-8. This can cause various unfixable issues + # such as os.stat not being able to decode filenames with unicode in them. + # There is no way to reset both the preferred encoding and the filesystem + # encoding, so we can just warn about it. + e = locale.getpreferredencoding() + if e.upper() != 'UTF-8': + mlog.warning('You are using {!r} which is not a a Unicode-compatible ' + 'locale.'.format(e)) + mlog.warning('You might see errors if you use UTF-8 strings as ' + 'filenames, as strings, or as file contents.') + mlog.warning('Please switch to a UTF-8 locale for your platform.') # Always resolve the command path so Ninja can find it for regen, tests, etc. launcher = os.path.realpath(sys.argv[0]) return mesonmain.run(launcher, sys.argv[1:])