summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-12-10 18:52:09 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2017-12-14 23:49:12 +0200
commit88756bfe95f539c0658b4ecb4d6547d76affdce4 (patch)
treead11fae47bf14a448127f3279be7829a168d6a20
parent93c988b45384cb141b592995eebeba954bd36cb6 (diff)
downloadmeson-88756bfe95f539c0658b4ecb4d6547d76affdce4.tar.gz
Print UTF-8 warning only when actually encountering non-ascii filenames.
-rwxr-xr-xmeson.py11
-rw-r--r--mesonbuild/interpreter.py2
-rw-r--r--mesonbuild/mesonlib.py29
3 files changed, 31 insertions, 11 deletions
diff --git a/meson.py b/meson.py
index 57cc6dc24..13bc870e6 100755
--- a/meson.py
+++ b/meson.py
@@ -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 f33d437bf..cbf141374 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 f10a1381e..9ad066821 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