2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-26 03:39:53 +01:00

Don't fail on output decoding errors

This commit is contained in:
Jan Niklas Hasse 2016-09-30 14:25:49 +02:00
parent 43302767dd
commit bfcef62e45

View File

@ -116,6 +116,12 @@ class store_context(type):
ctx = store_context('ctx', (object,), {}) ctx = store_context('ctx', (object,), {})
"""Base class for all :py:class:`waflib.Context.Context` classes""" """Base class for all :py:class:`waflib.Context.Context` classes"""
def decode(out):
try:
return out.decode(sys.stdout.encoding or 'iso8859-1', errors='replace')
except TypeError: # Python <= 2.6
return out.decode(sys.stdout.encoding or 'iso8859-1')
class Context(ctx): class Context(ctx):
""" """
Default context for waf commands, and base class for new command contexts. Default context for waf commands, and base class for new command contexts.
@ -355,14 +361,14 @@ class Context(ctx):
if out: if out:
if not isinstance(out, str): if not isinstance(out, str):
out = out.decode(sys.stdout.encoding or 'iso8859-1') out = decode(out)
if self.logger: if self.logger:
self.logger.debug('out: %s', out) self.logger.debug('out: %s', out)
else: else:
Logs.info(out, extra={'stream':sys.stdout, 'c1': ''}) Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
if err: if err:
if not isinstance(err, str): if not isinstance(err, str):
err = err.decode(sys.stdout.encoding or 'iso8859-1') err = decode(err)
if self.logger: if self.logger:
self.logger.error('err: %s' % err) self.logger.error('err: %s' % err)
else: else:
@ -440,9 +446,9 @@ class Context(ctx):
raise Errors.WafError('Execution failure: %s' % str(e), ex=e) raise Errors.WafError('Execution failure: %s' % str(e), ex=e)
if not isinstance(out, str): if not isinstance(out, str):
out = out.decode(sys.stdout.encoding or 'iso8859-1') out = decode(out)
if not isinstance(err, str): if not isinstance(err, str):
err = err.decode(sys.stdout.encoding or 'iso8859-1') err = decode(err)
if out and quiet != STDOUT and quiet != BOTH: if out and quiet != STDOUT and quiet != BOTH:
self.to_log('out: %s' % out) self.to_log('out: %s' % out)