diff options
author | Steven Knight <knight@baldmt.com> | 2005-03-24 04:17:25 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-03-24 04:17:25 (GMT) |
commit | f93cc22229166ffa87e069f9e082cf05b82c55f6 (patch) | |
tree | 8600c78d8c912807578f3315af123cad76787e99 /src | |
parent | e37e6ed273173fddca32e9eada7925d909ed1e85 (diff) | |
download | SCons-f93cc22229166ffa87e069f9e082cf05b82c55f6.zip SCons-f93cc22229166ffa87e069f9e082cf05b82c55f6.tar.gz SCons-f93cc22229166ffa87e069f9e082cf05b82c55f6.tar.bz2 |
Allow toolpath to be stored in the environment and re-used for Copy() and Tool() calls. (Chad Austin)
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 16 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 46 |
3 files changed, 60 insertions, 5 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 2e26545..6f0691f 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -25,6 +25,9 @@ RELEASE 0.97 - XXX - Allow Tools found on a toolpath to import Python modules from their local directory. + - Have the environment store the toolpath and re-use it to find Tools + modules during later Copy() or Tool() calls (unless overridden). + From Stanislav Baranov: - Make it possible to support with custom Alias (sub-)classes. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 9b93e12..77ce3c2 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -117,6 +117,10 @@ def our_deepcopy(x): return copy def apply_tools(env, tools, toolpath): + # Store the toolpath in the Environment. + if toolpath is not None: + env['toolpath'] = toolpath + if not tools: return # Filter out null tools from the list. @@ -124,9 +128,9 @@ def apply_tools(env, tools, toolpath): if SCons.Util.is_List(tool) or type(tool)==type(()): toolname = tool[0] toolargs = tool[1] # should be a dict of kw args - tool = apply(env.Tool, (toolname, toolpath), toolargs) + tool = apply(env.Tool, [toolname], toolargs) else: - env.Tool(tool, toolpath) + env.Tool(tool) # These names are controlled by SCons; users should never set or override # them. This warning can optionally be turned off, but scons will still @@ -465,7 +469,7 @@ class Base(SubstitutionEnvironment): def __init__(self, platform=None, tools=None, - toolpath=[], + toolpath=None, options=None, **kw): """ @@ -704,7 +708,7 @@ class Base(SubstitutionEnvironment): self._dict[key] = self._dict[key] + val self.scanner_map_delete(kw) - def Copy(self, tools=[], toolpath=[], **kw): + def Copy(self, tools=[], toolpath=None, **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 @@ -1045,9 +1049,11 @@ class Base(SubstitutionEnvironment): del kw[k] apply(self.Replace, (), kw) - def Tool(self, tool, toolpath=[], **kw): + def Tool(self, tool, toolpath=None, **kw): if SCons.Util.is_String(tool): tool = self.subst(tool) + if toolpath is None: + toolpath = self.get('toolpath', []) toolpath = map(self.subst, toolpath) tool = apply(SCons.Tool.Tool, (tool, toolpath), kw) tool(self) diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 0e8fd56..a508529 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1354,6 +1354,29 @@ def exists(env): x = env2.get('FLAGS') assert x == ['flag1', 'flag2', 'flag3', 'flag4'], x + # Test that the environment stores the toolpath and + # re-uses it for copies. + test = TestCmd.TestCmd(workdir = '') + + test.write('xxx.py', """\ +def exists(env): + 1 +def generate(env): + env['XXX'] = 'one' +""") + + test.write('yyy.py', """\ +def exists(env): + 1 +def generate(env): + env['YYY'] = 'two' +""") + + env = Environment(tools=['xxx'], toolpath=[test.workpath('')]) + assert env['XXX'] == 'one', env['XXX'] + env = env.Copy(tools=['yyy']) + assert env['YYY'] == 'two', env['YYY'] + def test_Detect(self): """Test Detect()ing tools""" test = TestCmd.TestCmd(workdir = '') @@ -1843,6 +1866,29 @@ f5: \ env.Tool('$LINK') assert env['LINK'] == '$SMARTLINK', env['LINK'] + # Test that the environment stores the toolpath and + # re-uses it for later calls. + test = TestCmd.TestCmd(workdir = '') + + test.write('xxx.py', """\ +def exists(env): + 1 +def generate(env): + env['XXX'] = 'one' +""") + + test.write('yyy.py', """\ +def exists(env): + 1 +def generate(env): + env['YYY'] = 'two' +""") + + env = Environment(tools=['xxx'], toolpath=[test.workpath('')]) + assert env['XXX'] == 'one', env['XXX'] + env.Tool('yyy') + assert env['YYY'] == 'two', env['YYY'] + def test_WhereIs(self): """Test the WhereIs() method""" test = TestCmd.TestCmd(workdir = '') |