mirror of https://gitlab.com/ita1024/waf.git
fix load_tool error messages and cover all occourences
When a tool cannot be loaded the wrong path was displayed on the error message. sys.path was always displayed but the actual path used depends on tooldir being passed and on the value of with_sys_path parameter. I put the exception handling (raising the fatal) inside load_tool itself as this is the only place where the exact path is known, without having to recalculate it outside. To be able to use fatal there also the ctx has to be passed from the various points. In this way all load_tool exceptions are caught and reported, while before an exception during configure was not caught for example, just during the options.
This commit is contained in:
parent
7d00ca7266
commit
5d3576af45
|
@ -378,7 +378,7 @@ class BuildContext(Context.Context):
|
|||
self.setup(i, tooldir)
|
||||
return
|
||||
|
||||
module = Context.load_tool(tool, tooldir)
|
||||
module = Context.load_tool(tool, tooldir, self)
|
||||
if hasattr(module, "setup"):
|
||||
module.setup(self)
|
||||
|
||||
|
|
|
@ -254,8 +254,6 @@ class ConfigurationContext(Context.Context):
|
|||
module = None
|
||||
try:
|
||||
module = Context.load_tool(tool, tooldir, ctx=self, with_sys_path=with_sys_path)
|
||||
except ImportError as e:
|
||||
self.fatal('Could not load the Waf tool %r from %r\n%s' % (tool, sys.path, e))
|
||||
except Exception as e:
|
||||
self.to_log('imp %r (%r & %r)' % (tool, tooldir, funs))
|
||||
self.to_log(traceback.format_exc())
|
||||
|
|
|
@ -188,7 +188,7 @@ class Context(ctx):
|
|||
with_sys_path = kw.get('with_sys_path', True)
|
||||
|
||||
for t in tools:
|
||||
module = load_tool(t, path, with_sys_path=with_sys_path)
|
||||
module = load_tool(t, path, self, with_sys_path=with_sys_path)
|
||||
fun = getattr(module, kw.get('name', self.fun), None)
|
||||
if fun:
|
||||
fun(self)
|
||||
|
@ -624,7 +624,7 @@ class Context(ctx):
|
|||
lst = self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var)
|
||||
for x in lst:
|
||||
if not x.name in ban:
|
||||
load_tool(x.name.replace('.py', ''))
|
||||
load_tool(x.name.replace('.py', ''), ctx=self)
|
||||
else:
|
||||
from zipfile import PyZipFile
|
||||
waflibs = PyZipFile(waf_dir)
|
||||
|
@ -640,7 +640,7 @@ class Context(ctx):
|
|||
doban = True
|
||||
if not doban:
|
||||
f = f.replace('.py', '')
|
||||
load_tool(f)
|
||||
load_tool(f, ctx=self)
|
||||
|
||||
cache_modules = {}
|
||||
"""
|
||||
|
@ -703,6 +703,8 @@ def load_tool(tool, tooldir=None, ctx=None, with_sys_path=True):
|
|||
sys.path = tooldir + sys.path
|
||||
try:
|
||||
__import__(tool)
|
||||
except ImportError as e:
|
||||
ctx.fatal('Could not load the Waf tool %r from %r\n%s' % (tool, sys.path, e))
|
||||
finally:
|
||||
for d in tooldir:
|
||||
sys.path.remove(d)
|
||||
|
@ -721,6 +723,8 @@ def load_tool(tool, tooldir=None, ctx=None, with_sys_path=True):
|
|||
x = None
|
||||
else: # raise an exception
|
||||
__import__(tool)
|
||||
except ImportError as e:
|
||||
ctx.fatal('Could not load the Waf tool %r from %r\n%s' % (tool, sys.path, e))
|
||||
finally:
|
||||
if not with_sys_path:
|
||||
sys.path.remove(waf_dir)
|
||||
|
|
Loading…
Reference in New Issue