summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-10-07 17:49:23 (GMT)
committerSteven Knight <knight@baldmt.com>2004-10-07 17:49:23 (GMT)
commit1a5adfd67ec02f9a2fdfa8a2da87dc7266759114 (patch)
tree1c2aa0119a24b6f0427d0dd2c3974d930257c488 /src/engine
parent3e59136605528a8b568fe339bcee817a5230b699 (diff)
downloadSCons-1a5adfd67ec02f9a2fdfa8a2da87dc7266759114.zip
SCons-1a5adfd67ec02f9a2fdfa8a2da87dc7266759114.tar.gz
SCons-1a5adfd67ec02f9a2fdfa8a2da87dc7266759114.tar.bz2
Allow passing a dictionary of keyword arguments to Tool specifications. (Gary Oberbrunner)
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Environment.py29
-rw-r--r--src/engine/SCons/EnvironmentTests.py16
-rw-r--r--src/engine/SCons/Tool/__init__.py19
3 files changed, 48 insertions, 16 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index af602a5..8f76d55 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -116,14 +116,16 @@ def our_deepcopy(x):
return copy
def apply_tools(env, tools, toolpath):
- if tools:
- # Filter out null tools from the list.
- tools = filter(None, tools)
- for tool in tools:
- if SCons.Util.is_String(tool):
- env.Tool(tool, toolpath)
- else:
- tool(env)
+ if not tools:
+ return
+ # Filter out null tools from the list.
+ for tool in filter(None, tools):
+ 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)
+ else:
+ env.Tool(tool, toolpath)
# These names are controlled by SCons; users should never set or override
# them. This warning can optionally be turned off, but scons will still
@@ -620,7 +622,7 @@ class Base:
self._dict[key] = self._dict[key] + val
self.scanner_map_delete(kw)
- def Copy(self, tools=None, toolpath=[], **kw):
+ def Copy(self, tools=[], 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
@@ -963,9 +965,12 @@ class Base:
del kw[k]
apply(self.Replace, (), kw)
- def Tool(self, tool, toolpath=[]):
- tool = self.subst(tool)
- return SCons.Tool.Tool(tool, map(self.subst, toolpath))(self)
+ def Tool(self, tool, toolpath=[], **kw):
+ if SCons.Util.is_String(tool):
+ tool = self.subst(tool)
+ toolpath = map(self.subst, toolpath)
+ tool = apply(SCons.Tool.Tool, (tool, toolpath), kw)
+ tool(self)
def WhereIs(self, prog, path=None, pathext=None, reject=[]):
"""Find prog in the path.
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index aa38965..b2f3536 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -840,6 +840,22 @@ class EnvironmentTestCase(unittest.TestCase):
t4(env)
assert env['TOOL4'] == 444, env
+ test = TestCmd.TestCmd(workdir = '')
+ test.write('faketool.py', """\
+def generate(env, **kw):
+ for k, v in kw.items():
+ env[k] = v
+
+def exists(env):
+ return 1
+""")
+
+ env = Environment(tools = [('faketool', {'a':1, 'b':2, 'c':3})],
+ toolpath = [test.workpath('')])
+ assert env['a'] == 1, env['a']
+ assert env['b'] == 2, env['b']
+ assert env['c'] == 3, env['c']
+
def test_Default_TOOLS(self):
"""Test overriding the default TOOLS variable"""
def t5(env):
diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py
index afad44c..2adaacb 100644
--- a/src/engine/SCons/Tool/__init__.py
+++ b/src/engine/SCons/Tool/__init__.py
@@ -45,24 +45,35 @@ import SCons.Errors
import SCons.Defaults
class ToolSpec:
- def __init__(self, name):
+ def __init__(self, name, **kw):
self.name = name
+ # remember these so we can merge them into the call
+ self.init_kw = kw
def __call__(self, env, *args, **kw):
+ if self.init_kw is not None:
+ # Merge call kws into init kws;
+ # but don't bash self.init_kw.
+ if kw is not None:
+ call_kw = kw
+ kw = self.init_kw.copy()
+ kw.update(call_kw)
+ else:
+ kw = self.init_kw
env.Append(TOOLS = [ self.name ])
apply(self.generate, ( env, ) + args, kw)
def __str__(self):
return self.name
-def Tool(name, toolpath=[]):
+def Tool(name, toolpath=[], **kw):
"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 = apply(ToolSpec, (name,), kw)
spec.generate = module.generate
spec.exists = module.exists
return spec
@@ -83,7 +94,7 @@ def Tool(name, toolpath=[]):
raise SCons.Errors.UserError, "No tool named '%s': %s" % (name, e)
if file:
file.close()
- spec = ToolSpec(name)
+ spec = apply(ToolSpec, (name,), kw)
spec.generate = sys.modules[full_name].generate
spec.exists = sys.modules[full_name].exists
return spec