diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 18 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Tool/__init__.py | 20 |
4 files changed, 33 insertions, 12 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 1043b50..2b598ae 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -25,6 +25,9 @@ RELEASE 0.95 - XXX - Fix a problem with the msvc tool with Python versions prior to 2.3. + - Add support for a "toolpath" Tool() and Environment keyword that + allows Tool modules to be found in specified local directories. + From Chris Burghart: - Fix the ability to save/restore a PackageOption to a file. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 26be483..6afa69f 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -109,12 +109,13 @@ def our_deepcopy(x): copy = x return copy -def apply_tools(env, tools): +def apply_tools(env, tools, toolpath): if tools: for tool in tools: if SCons.Util.is_String(tool): - tool = SCons.Tool.Tool(tool) - tool(env) + env.Tool(tool, toolpath) + else: + tool(env) class BuilderWrapper: """Wrapper class that associates an environment with a Builder at @@ -207,6 +208,7 @@ class Base: def __init__(self, platform=None, tools=None, + toolpath=[], options=None, **kw): self.fs = SCons.Node.FS.default_fs @@ -238,7 +240,7 @@ class Base: tools = self._dict.get('TOOLS', None) if tools is None: tools = ['default'] - apply_tools(self, tools) + apply_tools(self, tools, toolpath) # Reapply the passed in variables after calling the tools, # since they should overide anything set by the tools: @@ -461,7 +463,7 @@ class Base: self._dict[envname][name] = nv - def Copy(self, tools=None, **kw): + def Copy(self, tools=None, toolpath=[], **kw): """Return a copy of a construction Environment. The copy is like a Python "deep copy"--that is, independent copies are made recursively of each objects--except that @@ -477,7 +479,7 @@ class Base: except KeyError: pass - apply_tools(clone, tools) + apply_tools(clone, tools, toolpath) # Apply passed-in variables after the new tools. apply(clone.Replace, (), kw) @@ -666,9 +668,9 @@ class Base: name = name[:-len(old_suffix)] return os.path.join(dir, new_prefix+name+new_suffix) - def Tool(self, tool): + def Tool(self, tool, toolpath=[]): tool = self.subst(tool) - return SCons.Tool.Tool(tool)(self) + return SCons.Tool.Tool(tool, map(self.subst, toolpath))(self) def WhereIs(self, prog, path=None, pathext=None): """Find prog in the path. diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index e6fd5c9..5fee3dd 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1162,7 +1162,9 @@ class EnvironmentTestCase(unittest.TestCase): exc_caught = 1 assert exc_caught, "did not catch expected UserError" - env.Tool('cc') + # Use a non-existent toolpath directory just to make sure we + # can call Tool() with the keyword argument. + env.Tool('cc', toolpath=['/no/such/directory']) assert env['CC'] == 'cc', env['CC'] env.Tool('$LINK') diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index a58ac6d..34e9e0d 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -55,9 +55,23 @@ class ToolSpec: def __str__(self): return self.name -def Tool(name): - """Select a canned Tool specification. - """ +def Tool(name, toolpath=[]): + "Select a canned Tool specification, optionally searching in toolpath." + + try: + file, path, desc = imp.find_module(name, toolpath) + try: + module = imp.load_module(name, file, path, desc) + spec = ToolSpec(name) + spec.generate = module.generate + spec.exists = module.exists + return spec + finally: + if file: + file.close() + except ImportError, e: + pass + full_name = 'SCons.Tool.' + name if not sys.modules.has_key(full_name): try: |