5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Test that SCons supports use of a home-brew ToolSurrogate class
29 like we use in our bin/sconsexamples.py script.
34 test = TestSCons.TestSCons()
36 test.write('SConstruct', """\
39 def __init__(self, fun, *args, **kwargs):
41 self.pending = args[:]
42 self.kwargs = kwargs.copy()
44 def __call__(self, *args, **kwargs):
45 if kwargs and self.kwargs:
46 kw = self.kwargs.copy()
49 kw = kwargs or self.kwargs
51 return apply(self.fun, self.pending + args, kw)
53 def Str(target, source, env, cmd=""):
55 for cmd in env.subst_list(cmd, target=target, source=source):
56 result.append(string.join(map(str, cmd)))
57 return string.join(result, '\\n')
60 def __init__(self, tool, variable, func):
62 self.variable = variable
64 def __call__(self, env):
67 orig = env[self.variable]
68 env[self.variable] = Action(self.func, strfunction=Curry(Str, cmd=orig))
70 def Cat(target, source, env):
71 target = str(target[0])
72 f = open(target, "wb")
73 for src in map(str, source):
74 f.write(open(src, "rb").read())
78 'posix' : [('cc', 'CCCOM', Cat),
79 ('link', 'LINKCOM', Cat)],
80 'win32' : [('msvc', 'CCCOM', Cat),
81 ('mslink', 'LINKCOM', Cat)]
84 platform = ARGUMENTS['platform']
85 tools = map(lambda t: apply(ToolSurrogate, t), ToolList[platform])
87 env = Environment(tools=tools, PROGSUFFIX='.exe', OBJSUFFIX='.obj')
91 test.write('foo.c', "foo.c posix\n")
93 test.run(arguments = '. platform=posix', stdout = test.wrap_stdout("""\
94 cc -o foo.obj -c foo.c
98 test.write('foo.c', "foo.c win32\n")
100 test.run(arguments = '. platform=win32', stdout = test.wrap_stdout("""\
101 cl /Fofoo.obj /c foo.c /nologo
102 link /nologo /OUT:foo.exe foo.obj