summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Tool/__init__.py
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-06-20 18:27:16 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2017-06-20 18:27:16 (GMT)
commit8058b1600eff989c685ed5dbc660133f3c8ddf08 (patch)
treee543d978cb355faf9898b7477cf39d7f3cee6825 /src/engine/SCons/Tool/__init__.py
parent2c22c3ec5160b3d8e9ccb8884dfef96035b0f82e (diff)
parentfab72bed412cb035d96b9d8415f7052540a20556 (diff)
downloadSCons-8058b1600eff989c685ed5dbc660133f3c8ddf08.zip
SCons-8058b1600eff989c685ed5dbc660133f3c8ddf08.tar.gz
SCons-8058b1600eff989c685ed5dbc660133f3c8ddf08.tar.bz2
Merged in grbd/scons (pull request #481)
Addition of support for nested tools, tools within a sub-directory
Diffstat (limited to 'src/engine/SCons/Tool/__init__.py')
-rw-r--r--src/engine/SCons/Tool/__init__.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py
index 61b7788..e5b4b05 100644
--- a/src/engine/SCons/Tool/__init__.py
+++ b/src/engine/SCons/Tool/__init__.py
@@ -118,6 +118,16 @@ class Tool(object):
if hasattr(module, 'options'):
self.options = module.options
+ def _load_dotted_module_py2(self, short_name, full_name, searchpaths=None):
+ splitname = short_name.split('.')
+ index = 0
+ srchpths = searchpaths
+ for item in splitname:
+ file, path, desc = imp.find_module(item, srchpths)
+ mod = imp.load_module(full_name, file, path, desc)
+ srchpths = [path]
+ return mod, file
+
def _tool_module(self):
oldpythonpath = sys.path
sys.path = self.toolpath + sys.path
@@ -127,15 +137,16 @@ class Tool(object):
# Py 2 code
try:
try:
- file, path, desc = imp.find_module(self.name, self.toolpath)
+ file = None
try:
- return imp.load_module(self.name, file, path, desc)
-
+ mod, file = self._load_dotted_module_py2(self.name, self.name, self.toolpath)
+ return mod
finally:
if file:
file.close()
except ImportError as e:
- if str(e)!="No module named %s"%self.name:
+ splitname = self.name.split('.')
+ if str(e)!="No module named %s"%splitname[0]:
raise SCons.Errors.EnvironmentError(e)
try:
import zipimport
@@ -169,8 +180,9 @@ class Tool(object):
found_name = self.name
add_to_scons_tools_namespace = False
for path in self.toolpath:
- file_path = os.path.join(path, "%s.py"%self.name)
- file_package = os.path.join(path, self.name)
+ sepname = self.name.replace('.', os.path.sep)
+ file_path = os.path.join(path, "%s.py"%sepname)
+ file_package = os.path.join(path, sepname)
if debug: sys.stderr.write("Trying:%s %s\n"%(file_path, file_package))
@@ -179,6 +191,7 @@ class Tool(object):
if debug: print("file_Path:%s FOUND"%file_path)
break
elif os.path.isdir(file_package):
+ file_package = os.path.join(file_package, '__init__.py')
spec = importlib.util.spec_from_file_location(self.name, file_package)
if debug: print("PACKAGE:%s Found"%file_package)
break
@@ -231,8 +244,7 @@ class Tool(object):
try:
smpath = sys.modules['SCons.Tool'].__path__
try:
- file, path, desc = imp.find_module(self.name, smpath)
- module = imp.load_module(full_name, file, path, desc)
+ module, file = self._load_dotted_module_py2(self.name, full_name, smpath)
setattr(SCons.Tool, self.name, module)
if file:
file.close()