Clarify the exception type raised by cmd_and_log

This commit is contained in:
Thomas Nagy 2017-06-20 11:20:53 +02:00
parent 0c4b0592cd
commit 4d7527b4c4
14 changed files with 35 additions and 27 deletions

View File

@ -87,7 +87,7 @@ def configure(conf):
conf.find_program('python'+x, var=x) conf.find_program('python'+x, var=x)
# unpacking the waf directory concurrently can lead to a race condition, we'll need to take care of this (thanks, build farm!) # unpacking the waf directory concurrently can lead to a race condition, we'll need to take care of this (thanks, build farm!)
conf.cmd_and_log(conf.env[x] + ['./waf', '--version'], env={}) conf.cmd_and_log(conf.env[x] + ['./waf', '--version'], env={})
except Exception as e: except Errors.WafError as e:
pass pass
else: else:
conf.env.append_value('PYTHONS', x) conf.env.append_value('PYTHONS', x)

View File

@ -11,8 +11,8 @@ An advanced dynamic build simulating a call to an external system.
That external build system produces a library which is then used in the current build. That external build system produces a library which is then used in the current build.
""" """
import os, shutil, sys, subprocess import os, shutil, sys
from waflib import Utils, Build, Logs from waflib import Build, Errors, Logs
top = '.' top = '.'
out = 'build' out = 'build'
@ -79,7 +79,7 @@ def some_fun(task):
try: try:
task.generator.bld.cmd_and_log(cmd, cwd=cwd, quiet=0, output=0) task.generator.bld.cmd_and_log(cmd, cwd=cwd, quiet=0, output=0)
except Exception as e: except Errors.WafError as e:
try: try:
print(e.stderr) print(e.stderr)
except AttributeError: except AttributeError:

View File

@ -428,6 +428,7 @@ def find_program(self, filename, **kw):
:type msg: string :type msg: string
:param interpreter: interpreter for the program :param interpreter: interpreter for the program
:type interpreter: ConfigSet variable key :type interpreter: ConfigSet variable key
:raises: :py:class:`waflib.Errors.ConfigurationError`
""" """
exts = kw.get('exts', Utils.is_win32 and '.exe,.com,.bat,.cmd' or ',.sh,.pl,.py') exts = kw.get('exts', Utils.is_win32 and '.exe,.com,.bat,.cmd' or ',.sh,.pl,.py')

View File

@ -323,6 +323,8 @@ class Context(ctx):
:type kw: dict :type kw: dict
:returns: process exit status :returns: process exit status
:rtype: integer :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 subprocess = Utils.subprocess
kw['shell'] = isinstance(cmd, str) kw['shell'] = isinstance(cmd, str)
@ -382,7 +384,7 @@ class Context(ctx):
""" """
Executes a process and returns stdout/stderr if the execution is successful. 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 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): def configure(conf):
out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH) out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH)
@ -390,7 +392,7 @@ class Context(ctx):
(out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT) (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT)
try: try:
conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH) conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH)
except Exception as e: except Errors.WafError as e:
print(e.stdout, e.stderr) print(e.stdout, e.stderr)
:param cmd: args for subprocess.Popen :param cmd: args for subprocess.Popen

View File

@ -1024,7 +1024,7 @@ def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
env = conf.env.env or None env = conf.env.env or None
try: try:
out, err = conf.cmd_and_log(cmd, output=0, input='\n'.encode(), env=env) out, err = conf.cmd_and_log(cmd, output=0, input='\n'.encode(), env=env)
except Exception: except Errors.WafError:
conf.fatal('Could not determine the compiler version %r' % cmd) conf.fatal('Could not determine the compiler version %r' % cmd)
if gcc: if gcc:

View File

@ -6,6 +6,7 @@
Compiler definition for irix/MIPSpro cc compiler Compiler definition for irix/MIPSpro cc compiler
""" """
from waflib import Errors
from waflib.Tools import ccroot, ar from waflib.Tools import ccroot, ar
from waflib.Configure import conf from waflib.Configure import conf
@ -24,7 +25,7 @@ def find_irixcc(conf):
try: try:
conf.cmd_and_log(cc + ['-version']) conf.cmd_and_log(cc + ['-version'])
except Exception: except Errors.WafError:
conf.fatal('%r -version could not be executed' % cc) conf.fatal('%r -version could not be executed' % cc)
v.CC = cc v.CC = cc

View File

@ -24,7 +24,7 @@ Support for Perl extensions. A C/C++ compiler is required::
""" """
import os import os
from waflib import Task, Options, Utils from waflib import Task, Options, Utils, Errors
from waflib.Configure import conf from waflib.Configure import conf
from waflib.TaskGen import extension, feature, before_method from waflib.TaskGen import extension, feature, before_method
@ -99,7 +99,7 @@ def check_perl_module(self, module):
self.start_msg('perl module %s' % module) self.start_msg('perl module %s' % module)
try: try:
r = self.cmd_and_log(cmd) r = self.cmd_and_log(cmd)
except Exception: except Errors.WafError:
self.end_msg(False) self.end_msg(False)
return None return None
self.end_msg(r or True) self.end_msg(r or True)

View File

@ -19,7 +19,7 @@ Support for Python, detect the headers and libraries and provide
""" """
import os, sys import os, sys
from waflib import Utils, Options, Errors, Logs, Task, Node from waflib import Errors, Logs, Node, Options, Task, Utils
from waflib.TaskGen import extension, before_method, after_method, feature from waflib.TaskGen import extension, before_method, after_method, feature
from waflib.Configure import conf from waflib.Configure import conf
@ -553,7 +553,7 @@ def check_python_module(conf, module_name, condition=''):
conf.start_msg(msg) conf.start_msg(msg)
try: try:
ret = conf.cmd_and_log(conf.env.PYTHON + ['-c', PYTHON_MODULE_TEMPLATE % module_name]) ret = conf.cmd_and_log(conf.env.PYTHON + ['-c', PYTHON_MODULE_TEMPLATE % module_name])
except Exception: except Errors.WafError:
conf.end_msg(False) conf.end_msg(False)
conf.fatal('Could not find the python module %r' % module_name) conf.fatal('Could not find the python module %r' % module_name)

View File

@ -23,7 +23,7 @@ Support for Ruby extensions. A C/C++ compiler is required::
""" """
import os import os
from waflib import Options, Utils, Task from waflib import Errors, Options, Task, Utils
from waflib.TaskGen import before_method, feature, extension from waflib.TaskGen import before_method, feature, extension
from waflib.Configure import conf from waflib.Configure import conf
@ -60,13 +60,13 @@ def check_ruby_version(self, minver=()):
try: try:
version = self.cmd_and_log(ruby + ['-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip() version = self.cmd_and_log(ruby + ['-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
except Exception: except Errors.WafError:
self.fatal('could not determine ruby version') self.fatal('could not determine ruby version')
self.env.RUBY_VERSION = version self.env.RUBY_VERSION = version
try: try:
ver = tuple(map(int, version.split("."))) ver = tuple(map(int, version.split('.')))
except Exception: except Errors.WafError:
self.fatal('unsupported ruby version %r' % version) self.fatal('unsupported ruby version %r' % version)
cver = '' cver = ''
@ -151,7 +151,7 @@ def check_ruby_module(self, module_name):
self.start_msg('Ruby module %s' % module_name) self.start_msg('Ruby module %s' % module_name)
try: try:
self.cmd_and_log(self.env.RUBY + ['-e', 'require \'%s\';puts 1' % module_name]) self.cmd_and_log(self.env.RUBY + ['-e', 'require \'%s\';puts 1' % module_name])
except Exception: except Errors.WafError:
self.end_msg(False) self.end_msg(False)
self.fatal('Could not find the ruby module %r' % module_name) self.fatal('Could not find the ruby module %r' % module_name)
self.end_msg(True) self.end_msg(True)

View File

@ -3,6 +3,7 @@
# Thomas Nagy, 2006-2017 (ita) # Thomas Nagy, 2006-2017 (ita)
# Ralf Habacker, 2006 (rh) # Ralf Habacker, 2006 (rh)
from waflib import Errors
from waflib.Tools import ccroot, ar from waflib.Tools import ccroot, ar
from waflib.Configure import conf from waflib.Configure import conf
@ -15,7 +16,7 @@ def find_scc(conf):
cc = conf.find_program('cc', var='CC') cc = conf.find_program('cc', var='CC')
try: try:
conf.cmd_and_log(cc + ['-flags']) conf.cmd_and_log(cc + ['-flags'])
except Exception: except Errors.WafError:
conf.fatal('%r is not a Sun compiler' % cc) conf.fatal('%r is not a Sun compiler' % cc)
v.CC_NAME = 'sun' v.CC_NAME = 'sun'
conf.get_suncc_version(cc) conf.get_suncc_version(cc)

View File

@ -3,6 +3,7 @@
# Thomas Nagy, 2006-2017 (ita) # Thomas Nagy, 2006-2017 (ita)
# Ralf Habacker, 2006 (rh) # Ralf Habacker, 2006 (rh)
from waflib import Errors
from waflib.Tools import ccroot, ar from waflib.Tools import ccroot, ar
from waflib.Configure import conf from waflib.Configure import conf
@ -15,7 +16,7 @@ def find_sxx(conf):
cc = conf.find_program(['CC', 'c++'], var='CXX') cc = conf.find_program(['CC', 'c++'], var='CXX')
try: try:
conf.cmd_and_log(cc + ['-flags']) conf.cmd_and_log(cc + ['-flags'])
except Exception: except Errors.WafError:
conf.fatal('%r is not a Sun compiler' % cc) conf.fatal('%r is not a Sun compiler' % cc)
v.CXX_NAME = 'sun' v.CXX_NAME = 'sun'
conf.get_suncc_version(cc) conf.get_suncc_version(cc)

View File

@ -9,7 +9,7 @@ this tool to be too stable either (apis, etc)
""" """
import re import re
from waflib import Build, Context, Task, Utils, Logs, Options, Errors, Node from waflib import Build, Context, Errors, Logs, Node, Options, Task, Utils
from waflib.TaskGen import extension, taskgen_method from waflib.TaskGen import extension, taskgen_method
from waflib.Configure import conf from waflib.Configure import conf
@ -274,7 +274,7 @@ def find_valac(self, valac_name, min_version):
valac = self.find_program(valac_name, var='VALAC') valac = self.find_program(valac_name, var='VALAC')
try: try:
output = self.cmd_and_log(valac + ['--version']) output = self.cmd_and_log(valac + ['--version'])
except Exception: except Errors.WafError:
valac_version = None valac_version = None
else: else:
ver = re.search(r'\d+.\d+.\d+', output).group().split('.') ver = re.search(r'\d+.\d+.\d+', output).group().split('.')

View File

@ -7,6 +7,7 @@ Detect the PGI C compiler
""" """
import sys, re import sys, re
from waflib import Errors
from waflib.Configure import conf from waflib.Configure import conf
from waflib.Tools.compiler_c import c_compiler from waflib.Tools.compiler_c import c_compiler
c_compiler['linux'].append('pgicc') c_compiler['linux'].append('pgicc')
@ -42,7 +43,7 @@ def get_pgi_version(conf, cc):
try: try:
out, err = conf.cmd_and_log(cmd, output=0) out, err = conf.cmd_and_log(cmd, output=0)
except Exception: except Errors.WafError:
conf.fatal('Could not find pgi compiler %r' % cmd) conf.fatal('Could not find pgi compiler %r' % cmd)
if out: if out:
@ -56,7 +57,7 @@ def get_pgi_version(conf, cc):
cmd = cc + ['-help=variable'] cmd = cc + ['-help=variable']
try: try:
out, err = conf.cmd_and_log(cmd, output=0) out, err = conf.cmd_and_log(cmd, output=0)
except Exception: except Errors.WafError:
conf.fatal('Could not find pgi compiler %r' % cmd) conf.fatal('Could not find pgi compiler %r' % cmd)
version = re.findall('^COMPVER\s*=(.*)', out, re.M) version = re.findall('^COMPVER\s*=(.*)', out, re.M)

View File

@ -23,7 +23,7 @@ PRELUDE = ''
import os, sys, re, io, optparse, tokenize import os, sys, re, io, optparse, tokenize
from hashlib import md5 from hashlib import md5
from waflib import Utils, Options, Logs, Scripting from waflib import Errors, Utils, Options, Logs, Scripting
from waflib import Configure from waflib import Configure
Configure.autoconfig = 1 Configure.autoconfig = 1
@ -64,9 +64,10 @@ def init(ctx):
try: try:
rev = ctx.cmd_and_log("git rev-parse HEAD").strip() rev = ctx.cmd_and_log("git rev-parse HEAD").strip()
pats.append(('^WAFREVISION(.*)', 'WAFREVISION="%s"' % rev)) except Errors.WafError:
except Exception:
rev = '' rev = ''
else:
pats.append(('^WAFREVISION(.*)', 'WAFREVISION="%s"' % rev))
sub_file('waflib/Context.py', pats) sub_file('waflib/Context.py', pats)
@ -344,7 +345,7 @@ def create_waf(self, *k, **kw):
bld = self.generator.bld bld = self.generator.bld
try: try:
rev = bld.cmd_and_log('git rev-parse HEAD', quiet=0).strip() rev = bld.cmd_and_log('git rev-parse HEAD', quiet=0).strip()
except Exception: except Errors.WafError:
rev = '' rev = ''
else: else:
reg = re.compile('^GIT(.*)', re.M) reg = re.compile('^GIT(.*)', re.M)