summaryrefslogtreecommitdiff
path: root/third_party/waf/waflib/Context.py
diff options
context:
space:
mode:
authorAlexander Bokovoy <ab@samba.org>2018-01-31 11:48:43 +0200
committerAndrew Bartlett <abartlet@samba.org>2018-09-05 06:37:22 +0200
commit4e65b33c1d40bb2c243f775f388056aed31d8671 (patch)
tree5a41b6ddef7ce1c0b6a93bcc16ef89da10f080e8 /third_party/waf/waflib/Context.py
parentfaef27506977db01cc4619140a71652463914378 (diff)
downloadsamba-4e65b33c1d40bb2c243f775f388056aed31d8671.tar.gz
third_party:waf: update to upstream 2.0.4 release
Update third_party/waf/ to 2.0.4 to bring us closer to Python 3 This change requires a number of changes in buildtools/ too. Signed-off-by: Alexander Bokovoy <ab@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'third_party/waf/waflib/Context.py')
-rw-r--r--third_party/waf/waflib/Context.py82
1 files changed, 51 insertions, 31 deletions
diff --git a/third_party/waf/waflib/Context.py b/third_party/waf/waflib/Context.py
index 4a3b892bc00..7eab573e28d 100644
--- a/third_party/waf/waflib/Context.py
+++ b/third_party/waf/waflib/Context.py
@@ -4,7 +4,7 @@
#!/usr/bin/env python
# encoding: utf-8
-# Thomas Nagy, 2010-2016 (ita)
+# Thomas Nagy, 2010-2018 (ita)
"""
Classes and functions enabling the command system
@@ -15,16 +15,16 @@ from waflib import Utils, Errors, Logs
import waflib.Node
# the following 3 constants are updated on each new release (do not touch)
-HEXVERSION=0x1090a00
+HEXVERSION=0x2000400
"""Constant updated on new releases"""
-WAFVERSION="1.9.10"
+WAFVERSION="2.0.4"
"""Constant updated on new releases"""
-WAFREVISION="ae3f254315e0dcea4059703987148882ba414894"
+WAFREVISION="5996879673deb7166b61a299be317a738de6891e"
"""Git revision when the waf version is updated"""
-ABI = 99
+ABI = 20
"""Version of the build data cache file format (used in :py:const:`waflib.Context.DBFILE`)"""
DBFILE = '.wafpickle-%s-%d-%d' % (sys.platform, sys.hexversion, ABI)
@@ -85,7 +85,6 @@ def create_context(cmd_name, *k, **kw):
:return: Context object
:rtype: :py:class:`waflib.Context.Context`
"""
- global classes
for x in classes:
if x.cmd == cmd_name:
return x(*k, **kw)
@@ -99,8 +98,8 @@ class store_context(type):
Context classes must provide an attribute 'cmd' representing the command name, and a function
attribute 'fun' representing the function name that the command uses.
"""
- def __init__(cls, name, bases, dict):
- super(store_context, cls).__init__(name, bases, dict)
+ def __init__(cls, name, bases, dct):
+ super(store_context, cls).__init__(name, bases, dct)
name = cls.__name__
if name in ('ctx', 'Context'):
@@ -114,7 +113,6 @@ class store_context(type):
if not getattr(cls, 'fun', None):
cls.fun = cls.cmd
- global classes
classes.insert(0, cls)
ctx = store_context('ctx', (object,), {})
@@ -154,7 +152,6 @@ class Context(ctx):
try:
rd = kw['run_dir']
except KeyError:
- global run_dir
rd = run_dir
# binds the context to the nodes in use to avoid a context singleton
@@ -205,7 +202,6 @@ class Context(ctx):
Here, it calls the function name in the top-level wscript file. Most subclasses
redefine this method to provide additional functionality.
"""
- global g_module
self.recurse([os.path.dirname(g_module.root_path)])
def pre_recurse(self, node):
@@ -300,6 +296,15 @@ class Context(ctx):
raise Errors.WafError('Cannot read the folder %r' % d)
raise Errors.WafError('No wscript file in directory %s' % d)
+ def log_command(self, cmd, kw):
+ if Logs.verbose:
+ fmt = os.environ.get('WAF_CMD_FORMAT')
+ if fmt == 'string':
+ if not isinstance(cmd, str):
+ cmd = Utils.shell_escape(cmd)
+ Logs.debug('runner: %r', cmd)
+ Logs.debug('runner_env: kw=%s', kw)
+
def exec_command(self, cmd, **kw):
"""
Runs an external process and returns the exit status::
@@ -318,11 +323,12 @@ class Context(ctx):
:type kw: dict
:returns: process exit status
:rtype: integer
+ :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
+ :raises: :py:class:`waflib.Errors.WafError` in case of execution failure
"""
subprocess = Utils.subprocess
kw['shell'] = isinstance(cmd, str)
- Logs.debug('runner: %r', cmd)
- Logs.debug('runner_env: kw=%s', kw)
+ self.log_command(cmd, kw)
if self.logger:
self.logger.info(cmd)
@@ -354,19 +360,19 @@ class Context(ctx):
try:
ret, out, err = Utils.run_process(cmd, kw, cargs)
- except Exception ,e:
+ except Exception as e:
raise Errors.WafError('Execution failure: %s' % str(e), ex=e)
if out:
if not isinstance(out, str):
- out = out.decode(sys.stdout.encoding or 'iso8859-1', errors='replace')
+ out = out.decode(sys.stdout.encoding or 'latin-1', errors='replace')
if self.logger:
self.logger.debug('out: %s', out)
else:
Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
if err:
if not isinstance(err, str):
- err = err.decode(sys.stdout.encoding or 'iso8859-1', errors='replace')
+ err = err.decode(sys.stdout.encoding or 'latin-1', errors='replace')
if self.logger:
self.logger.error('err: %s' % err)
else:
@@ -378,29 +384,29 @@ class Context(ctx):
"""
Executes a process and returns stdout/stderr if the execution is successful.
An exception is thrown when the exit status is non-0. In that case, both stderr and stdout
- will be bound to the WafError object::
+ will be bound to the WafError object (configuration tests)::
def configure(conf):
out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH)
(out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH)
- (out, err) = conf.cmd_and_log(cmd, input='\\n', output=waflib.Context.STDOUT)
+ (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT)
try:
conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH)
- except Exception ,e:
+ except Errors.WafError as e:
print(e.stdout, e.stderr)
:param cmd: args for subprocess.Popen
:type cmd: list or string
:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
:type kw: dict
- :returns: process exit status
- :rtype: integer
+ :returns: a tuple containing the contents of stdout and stderr
+ :rtype: string
:raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
:raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object
"""
subprocess = Utils.subprocess
kw['shell'] = isinstance(cmd, str)
- Logs.debug('runner: %r', cmd)
+ self.log_command(cmd, kw)
if 'quiet' in kw:
quiet = kw['quiet']
@@ -440,13 +446,13 @@ class Context(ctx):
try:
ret, out, err = Utils.run_process(cmd, kw, cargs)
- except Exception ,e:
+ except Exception as e:
raise Errors.WafError('Execution failure: %s' % str(e), ex=e)
if not isinstance(out, str):
- out = out.decode(sys.stdout.encoding or 'iso8859-1', errors='replace')
+ out = out.decode(sys.stdout.encoding or 'latin-1', errors='replace')
if not isinstance(err, str):
- err = err.decode(sys.stdout.encoding or 'iso8859-1', errors='replace')
+ err = err.decode(sys.stdout.encoding or 'latin-1', errors='replace')
if out and quiet != STDOUT and quiet != BOTH:
self.to_log('out: %s' % out)
@@ -483,9 +489,15 @@ class Context(ctx):
if self.logger:
self.logger.info('from %s: %s' % (self.path.abspath(), msg))
try:
- msg = '%s\n(complete log in %s)' % (msg, self.logger.handlers[0].baseFilename)
+ logfile = self.logger.handlers[0].baseFilename
except AttributeError:
pass
+ else:
+ if os.environ.get('WAF_PRINT_FAILURE_LOG'):
+ # see #1930
+ msg = 'Log from (%s):\n%s\n' % (logfile, Utils.readf(logfile))
+ else:
+ msg = '%s\n(complete log in %s)' % (msg, logfile)
raise self.errors.ConfigurationError(msg, ex=ex)
def to_log(self, msg):
@@ -581,9 +593,9 @@ class Context(ctx):
result = kw.get('result') or k[0]
defcolor = 'GREEN'
- if result == True:
+ if result is True:
msg = 'ok'
- elif result == False:
+ elif not result:
msg = 'not found'
defcolor = 'YELLOW'
else:
@@ -612,7 +624,6 @@ class Context(ctx):
:param ban: list of exact file names to exclude
:type ban: list of string
"""
- global waf_dir
if os.path.isdir(waf_dir):
lst = self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var)
for x in lst:
@@ -696,6 +707,9 @@ def load_tool(tool, tooldir=None, ctx=None, with_sys_path=True):
sys.path = tooldir + sys.path
try:
__import__(tool)
+ except ImportError as e:
+ e.waf_sys_path = list(sys.path)
+ raise
finally:
for d in tooldir:
sys.path.remove(d)
@@ -703,7 +717,8 @@ def load_tool(tool, tooldir=None, ctx=None, with_sys_path=True):
Context.tools[tool] = ret
return ret
else:
- if not with_sys_path: sys.path.insert(0, waf_dir)
+ if not with_sys_path:
+ sys.path.insert(0, waf_dir)
try:
for x in ('waflib.Tools.%s', 'waflib.extras.%s', 'waflib.%s', '%s'):
try:
@@ -713,11 +728,16 @@ def load_tool(tool, tooldir=None, ctx=None, with_sys_path=True):
x = None
else: # raise an exception
__import__(tool)
+ except ImportError as e:
+ e.waf_sys_path = list(sys.path)
+ raise
finally:
- if not with_sys_path: sys.path.remove(waf_dir)
+ if not with_sys_path:
+ sys.path.remove(waf_dir)
ret = sys.modules[x % tool]
Context.tools[tool] = ret
return ret
finally:
if not with_sys_path:
sys.path += back_path
+