summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-03-24 04:17:25 (GMT)
committerSteven Knight <knight@baldmt.com>2005-03-24 04:17:25 (GMT)
commitf93cc22229166ffa87e069f9e082cf05b82c55f6 (patch)
tree8600c78d8c912807578f3315af123cad76787e99
parente37e6ed273173fddca32e9eada7925d909ed1e85 (diff)
downloadSCons-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)
-rw-r--r--doc/man/scons.115
-rw-r--r--src/CHANGES.txt3
-rw-r--r--src/engine/SCons/Environment.py16
-rw-r--r--src/engine/SCons/EnvironmentTests.py46
-rw-r--r--test/toolpath.py5
5 files changed, 79 insertions, 6 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index 3aac25c..26fcc66 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -1023,6 +1023,19 @@ value if the tool is available.
Tools in the toolpath are used before
any of the built-in ones. For example, adding gcc.py to the toolpath
would override the built-in gcc tool.
+Also note that the toolpath is
+stored in the environment for use
+by later calls to
+.BR Copy ()
+and
+.BR Tool ()
+methods:
+
+.ES
+base = Environment(toolpath=['custom_path'])
+derived = base.Copy(tools=['custom_tool'])
+derived.CustomBuilder()
+.EE
The elements of the tools list may also
be functions or callable objects,
@@ -7382,7 +7395,7 @@ and selects the compiler to be used for the check;
the default is "C".
.TP
-.RI Configure.CheckLib( self ", [" library ", " symbol ", " header ", " language ", " autoadd ])
+.RI Configure.CheckLib( self ", [" library ", " symbol ", " header ", " language ", " autoadd=1 ])
Checks if
.I library
provides
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 = '')
diff --git a/test/toolpath.py b/test/toolpath.py
index 797f345..55b70fd 100644
--- a/test/toolpath.py
+++ b/test/toolpath.py
@@ -87,6 +87,10 @@ env0.Tool('SCCS', toolpath=['$TOOLPATH'])
print "env0['SCCS'] =", env0.get('SCCS')
print "env0['TOOL_SCCS1'] =", env0.get('TOOL_SCCS1')
print "env0['TOOL_SCCS2'] =", env0.get('TOOL_SCCS2')
+
+base = Environment(tools=[], toolpath=['tools'])
+derived = base.Copy(tools=['bar'])
+print "derived['TOOL_BAR'] =", derived.get('TOOL_BAR')
""")
test.write('SCCS.py', r"""\
@@ -148,6 +152,7 @@ env9['TOOL_SCCS2'] = 1
env0['SCCS'] = None
env0['TOOL_SCCS1'] = None
env0['TOOL_SCCS2'] = 1
+derived['TOOL_BAR'] = 1
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.