aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mlog.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-02-28 00:22:41 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2017-03-01 07:58:46 -0500
commita7609e76f630dd1a8b2bfe4141969881040373f0 (patch)
treeb31fb52c4ee55c1f945a0992c2e7aed85aa0899a /mesonbuild/mlog.py
parentb9274681375b39d4b63f8ece1ced6dcf18789a4f (diff)
downloadmeson-a7609e76f630dd1a8b2bfe4141969881040373f0.zip
meson-a7609e76f630dd1a8b2bfe4141969881040373f0.tar.gz
meson-a7609e76f630dd1a8b2bfe4141969881040373f0.tar.bz2
Graceful fallback when printing messages with characters not understood by stdout.
Diffstat (limited to 'mesonbuild/mlog.py')
-rw-r--r--mesonbuild/mlog.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index f771b1a..843f366 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys, os, platform
+import sys, os, platform, io
"""This is (mostly) a standalone module used to write logging
information about Meson runs. Some output goes to screen,
@@ -70,6 +70,17 @@ def process_markup(args, keep):
arr.append(str(arg))
return arr
+def force_print(*args, **kwargs):
+ # _Something_ is going to get printed.
+ try:
+ print(*args, **kwargs)
+ except UnicodeEncodeError:
+ iostr = io.StringIO()
+ kwargs['file'] = iostr
+ print(*args, **kwargs)
+ cleaned = iostr.getvalue().encode('ascii', 'replace').decode('ascii')
+ print(cleaned)
+
def debug(*args, **kwargs):
arr = process_markup(args, False)
if log_file is not None:
@@ -83,7 +94,7 @@ def log(*args, **kwargs):
log_file.flush()
if colorize_console:
arr = process_markup(args, True)
- print(*arr, **kwargs)
+ force_print(*arr, **kwargs)
def warning(*args, **kwargs):
log(yellow('WARNING:'), *args, **kwargs)