diff --git a/demos/wscript b/demos/wscript index 90578f00..96036c07 100644 --- a/demos/wscript +++ b/demos/wscript @@ -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) diff --git a/playground/dynamic_build3/wscript b/playground/dynamic_build3/wscript index 1c3f1c73..6864ea9a 100644 --- a/playground/dynamic_build3/wscript +++ b/playground/dynamic_build3/wscript @@ -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: diff --git a/waflib/Configure.py b/waflib/Configure.py index 0a1ff57f..6f86fd3a 100644 --- a/waflib/Configure.py +++ b/waflib/Configure.py @@ -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') diff --git a/waflib/Context.py b/waflib/Context.py index 249a9dac..f286bbae 100644 --- a/waflib/Context.py +++ b/waflib/Context.py @@ -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 diff --git a/waflib/Tools/c_config.py b/waflib/Tools/c_config.py index 6a11d1d5..1a865614 100644 --- a/waflib/Tools/c_config.py +++ b/waflib/Tools/c_config.py @@ -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: diff --git a/waflib/Tools/irixcc.py b/waflib/Tools/irixcc.py index 706ec496..c3ae1ac9 100644 --- a/waflib/Tools/irixcc.py +++ b/waflib/Tools/irixcc.py @@ -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 diff --git a/waflib/Tools/perl.py b/waflib/Tools/perl.py index 90e47ea8..05bbd9df 100644 --- a/waflib/Tools/perl.py +++ b/waflib/Tools/perl.py @@ -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) diff --git a/waflib/Tools/python.py b/waflib/Tools/python.py index a536f696..11b0318d 100644 --- a/waflib/Tools/python.py +++ b/waflib/Tools/python.py @@ -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) diff --git a/waflib/Tools/ruby.py b/waflib/Tools/ruby.py index d92f0270..eef37369 100644 --- a/waflib/Tools/ruby.py +++ b/waflib/Tools/ruby.py @@ -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) diff --git a/waflib/Tools/suncc.py b/waflib/Tools/suncc.py index 39481e31..602e6392 100644 --- a/waflib/Tools/suncc.py +++ b/waflib/Tools/suncc.py @@ -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) diff --git a/waflib/Tools/suncxx.py b/waflib/Tools/suncxx.py index 97ce060b..a5921277 100644 --- a/waflib/Tools/suncxx.py +++ b/waflib/Tools/suncxx.py @@ -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) diff --git a/waflib/Tools/vala.py b/waflib/Tools/vala.py index 266c0132..df90a7d3 100644 --- a/waflib/Tools/vala.py +++ b/waflib/Tools/vala.py @@ -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('.') diff --git a/waflib/extras/pgicc.py b/waflib/extras/pgicc.py index d06e7f1a..9790b9cf 100644 --- a/waflib/extras/pgicc.py +++ b/waflib/extras/pgicc.py @@ -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) diff --git a/wscript b/wscript index 10960200..5080f5a6 100644 --- a/wscript +++ b/wscript @@ -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)