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)
# 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={})
except Exception as e:
except Errors.WafError as e:
pass
else:
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.
"""
import os, shutil, sys, subprocess
from waflib import Utils, Build, Logs
import os, shutil, sys
from waflib import Build, Errors, Logs
top = '.'
out = 'build'
@ -79,7 +79,7 @@ def some_fun(task):
try:
task.generator.bld.cmd_and_log(cmd, cwd=cwd, quiet=0, output=0)
except Exception as e:
except Errors.WafError as e:
try:
print(e.stderr)
except AttributeError:

View File

@ -428,6 +428,7 @@ def find_program(self, filename, **kw):
:type msg: string
:param interpreter: interpreter for the program
: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')

View File

@ -323,6 +323,8 @@ 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)
@ -382,7 +384,7 @@ 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)
@ -390,7 +392,7 @@ class Context(ctx):
(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 as e:
except Errors.WafError as e:
print(e.stdout, e.stderr)
: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
try:
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)
if gcc:

View File

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

View File

@ -24,7 +24,7 @@ Support for Perl extensions. A C/C++ compiler is required::
"""
import os
from waflib import Task, Options, Utils
from waflib import Task, Options, Utils, Errors
from waflib.Configure import conf
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)
try:
r = self.cmd_and_log(cmd)
except Exception:
except Errors.WafError:
self.end_msg(False)
return None
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
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.Configure import conf
@ -553,7 +553,7 @@ def check_python_module(conf, module_name, condition=''):
conf.start_msg(msg)
try:
ret = conf.cmd_and_log(conf.env.PYTHON + ['-c', PYTHON_MODULE_TEMPLATE % module_name])
except Exception:
except Errors.WafError:
conf.end_msg(False)
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
from waflib import Options, Utils, Task
from waflib import Errors, Options, Task, Utils
from waflib.TaskGen import before_method, feature, extension
from waflib.Configure import conf
@ -60,13 +60,13 @@ def check_ruby_version(self, minver=()):
try:
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.env.RUBY_VERSION = version
try:
ver = tuple(map(int, version.split(".")))
except Exception:
ver = tuple(map(int, version.split('.')))
except Errors.WafError:
self.fatal('unsupported ruby version %r' % version)
cver = ''
@ -151,7 +151,7 @@ def check_ruby_module(self, module_name):
self.start_msg('Ruby module %s' % module_name)
try:
self.cmd_and_log(self.env.RUBY + ['-e', 'require \'%s\';puts 1' % module_name])
except Exception:
except Errors.WafError:
self.end_msg(False)
self.fatal('Could not find the ruby module %r' % module_name)
self.end_msg(True)

View File

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

View File

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

View File

@ -9,7 +9,7 @@ this tool to be too stable either (apis, etc)
"""
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.Configure import conf
@ -274,7 +274,7 @@ def find_valac(self, valac_name, min_version):
valac = self.find_program(valac_name, var='VALAC')
try:
output = self.cmd_and_log(valac + ['--version'])
except Exception:
except Errors.WafError:
valac_version = None
else:
ver = re.search(r'\d+.\d+.\d+', output).group().split('.')

View File

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

View File

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