diff --git a/waflib/Build.py b/waflib/Build.py index 84f63c0c..f6d5826d 100644 --- a/waflib/Build.py +++ b/waflib/Build.py @@ -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) diff --git a/waflib/Configure.py b/waflib/Configure.py index 67788db2..ebab3179 100644 --- a/waflib/Configure.py +++ b/waflib/Configure.py @@ -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()) diff --git a/waflib/Context.py b/waflib/Context.py index 16bccfa0..ab51f400 100644 --- a/waflib/Context.py +++ b/waflib/Context.py @@ -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)