Added fix for TeX includes with same name as subdirs.
[scons.git] / test / SPAWN.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test the SPAWN construction variable.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.write('cat.py', """\
38 import sys
39 ofp = open(sys.argv[1], 'wb')
40 for s in sys.argv[2:]:
41     ofp.write(open(s, 'rb').read())
42 ofp.close()
43 """)
44
45 test.write('SConstruct', """
46 import os
47 import sys
48 def my_spawn1(sh, escape, cmd, args, env):
49     s = " ".join(args + ['extra1.txt'])
50     if sys.platform in ['win32']:
51         s = '"' + s + '"'
52     os.system(s)
53 def my_spawn2(sh, escape, cmd, args, env):
54     s = " ".join(args + ['extra2.txt'])
55     if sys.platform in ['win32']:
56         s = '"' + s + '"'
57     os.system(s)
58 env = Environment(MY_SPAWN1 = my_spawn1,
59                   MY_SPAWN2 = my_spawn2,
60                   COMMAND = r'%(_python_)s cat.py $TARGET $SOURCES')
61 env1 = env.Clone(SPAWN = my_spawn1)
62 env1.Command('file1.out', 'file1.in', '$COMMAND')
63
64 env2 = env.Clone(SPAWN = '$MY_SPAWN2')
65 env2.Command('file2.out', 'file2.in', '$COMMAND')
66
67 env3 = env.Clone(SPAWN = '${USE_TWO and MY_SPAWN2 or MY_SPAWN1}')
68 env3.Command('file3.out', 'file3.in', '$COMMAND', USE_TWO=0)
69 env3.Command('file4.out', 'file4.in', '$COMMAND', USE_TWO=1)
70 """ % locals())
71
72 test.write('file1.in', "file1.in\n")
73 test.write('file2.in', "file2.in\n")
74 test.write('file3.in', "file3.in\n")
75 test.write('file4.in', "file4.in\n")
76 test.write('extra1.txt', "extra1.txt\n")
77 test.write('extra2.txt', "extra2.txt\n")
78
79 test.run(arguments = '.')
80
81 test.must_match('file1.out', "file1.in\nextra1.txt\n")
82 test.must_match('file2.out', "file2.in\nextra2.txt\n")
83 test.must_match('file3.out', "file3.in\nextra1.txt\n")
84 test.must_match('file4.out', "file4.in\nextra2.txt\n")
85
86 test.pass_test()
87
88 # Local Variables:
89 # tab-width:4
90 # indent-tabs-mode:nil
91 # End:
92 # vim: set expandtab tabstop=4 shiftwidth=4: