diff options
-rwxr-xr-x | meson.py | 11 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 2 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 29 |
3 files changed, 31 insertions, 11 deletions
@@ -18,17 +18,6 @@ from mesonbuild import mesonmain, mesonlib 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' and not mesonlib.is_windows(): - print('Warning: You are using {!r} which is not a Unicode-compatible ' - 'locale.'.format(e), file=sys.stderr) - print('You might see errors if you use UTF-8 strings as ' - 'filenames, as strings, or as file contents.', file=sys.stderr) - print('Please switch to a UTF-8 locale for your platform.', file=sys.stderr) # Always resolve the command path so Ninja can find it for regen, tests, etc. launcher = os.path.realpath(sys.argv[0]) return mesonmain.run(sys.argv[1:], launcher) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index f33d437..cbf1413 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2503,6 +2503,7 @@ to directly access options of other subprojects.''') @permittedKwargs(permitted_kwargs['subdir']) def func_subdir(self, node, args, kwargs): self.validate_arguments(args, 1, [str]) + mesonlib.check_direntry_issues(args) if '..' in args[0]: raise InvalidArguments('Subdir contains ..') if self.subdir == '' and args[0] == self.subproject_dir: @@ -2912,6 +2913,7 @@ different subdirectory. def source_strings_to_files(self, sources): results = [] + mesonlib.check_direntry_issues(sources) for s in sources: if isinstance(s, (mesonlib.File, GeneratedListHolder, CustomTargetHolder, CustomTargetIndexHolder)): diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index f10a138..9ad0668 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -19,6 +19,7 @@ import stat import time import platform, subprocess, operator, os, shutil, re import collections +from mesonbuild import mlog from glob import glob @@ -59,6 +60,34 @@ else: python_command = [sys.executable] meson_command = python_command + [detect_meson_py_location()] +def is_ascii_string(astring): + try: + if isinstance(astring, str): + astring.encode('ascii') + if isinstance(astring, bytes): + astring.decode('ascii') + except UnicodeDecodeError: + return False + return True + +def check_direntry_issues(direntry_array): + import locale + # 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' and not is_windows(): + if not isinstance(direntry_array, list): + direntry_array = [direntry_array] + for de in direntry_array: + if is_ascii_string(de): + continue + mlog.warning('''You are using {!r} which is not a Unicode-compatible ' +locale but you are trying to access a file system entry called {!r} which is +not pure ASCII. This may cause problems. +'''.format(e, de), file=sys.stderr) + # Put this in objects that should not get dumped to pickle files # by accident. import threading |