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,
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
- 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.
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.
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
def __init__(self,
platform=None,
tools=None,
- toolpath=[],
+ toolpath=None,
options=None,
**kw):
"""
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
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)
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 = '')
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 = '')
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"""\
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.