Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Command.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 import TestSCons
28
29 python = TestSCons.python
30 _python_ = TestSCons._python_
31
32 test = TestSCons.TestSCons()
33
34 test.subdir('sub')
35
36 test.write('build.py', r"""
37 import sys
38 contents = open(sys.argv[2], 'rb').read()
39 file = open(sys.argv[1], 'wb')
40 file.write(contents)
41 file.close()
42 """)
43
44 test.write('SConstruct', """
45 import os
46
47 def buildIt(env, target, source):
48     contents = open(str(source[0]), 'rb').read()
49     file = open(str(target[0]), 'wb')
50     xyzzy = env.get('XYZZY', '')
51     if xyzzy:
52         file.write(xyzzy + '\\n')
53     file.write(contents)
54     file.close()
55     return 0
56
57 def sub(env, target, source):
58     target = str(target[0])
59     source = str(source[0])
60     t = open(target, 'wb')
61     for f in sorted(os.listdir(source)):
62         t.write(open(os.path.join(source, f), 'rb').read())
63     t.close()
64     return 0
65
66 env = Environment(COPY_THROUGH_TEMP = '%(_python_)s build.py .tmp $SOURCE\\n%(_python_)s build.py $TARGET .tmp',
67                   EXPAND = '$COPY_THROUGH_TEMP')
68 env.Command(target = 'f1.out', source = 'f1.in',
69             action = buildIt)
70 env.Command(target = 'f2.out', source = 'f2.in',
71             action = r'%(_python_)s build.py temp2 $SOURCES' + '\\n' + r'%(_python_)s build.py $TARGET temp2')
72 env.Command(target = 'f3.out', source = 'f3.in',
73             action = [ [ r'%(python)s', 'build.py', 'temp3', '$SOURCES' ],
74                        [ r'%(python)s', 'build.py', '$TARGET', 'temp3'] ])
75 Command(target = 'f4.out', source = 'sub', action = sub)
76 env.Command(target = 'f5.out', source = 'f5.in', action = buildIt,
77             XYZZY='XYZZY is set')
78 Command(target = 'f6.out', source = 'f6.in',
79         action = r'%(_python_)s build.py f6.out f6.in')
80 env.Command(target = 'f7.out', source = 'f7.in',
81             action = r'%(_python_)s build.py $TARGET $SOURCE')
82 Command(target = 'f8.out', source = 'f8.in',
83         action = r'%(_python_)s build.py $TARGET $SOURCE')
84 env.Command(target = 'f9.out', source = 'f9.in',
85             action = r'$EXPAND')
86 env.Command(target = '${F10}.out', source = '${F10}.in',
87             action = r'%(_python_)s build.py $TARGET $SOURCE',
88             F10 = 'f10')
89 """ % locals())
90
91 test.write('f1.in', "f1.in\n")
92 test.write('f2.in', "f2.in\n")
93 test.write('f3.in', "f3.in\n")
94 test.write(['sub', 'f4a'], "sub/f4a\n")
95 test.write(['sub', 'f4b'], "sub/f4b\n")
96 test.write(['sub', 'f4c'], "sub/f4c\n")
97 test.write('f5.in', "f5.in\n")
98 test.write('f6.in', "f6.in\n")
99 test.write('f7.in', "f7.in\n")
100 test.write('f8.in', "f8.in\n")
101 test.write('f9.in', "f9.in\n")
102 test.write('f10.in', "f10.in\n")
103
104 test.run(arguments = '.')
105
106 test.must_match('f1.out', "f1.in\n")
107 test.must_match('f2.out', "f2.in\n")
108 test.must_match('f3.out', "f3.in\n")
109 test.must_match('f4.out', "sub/f4a\nsub/f4b\nsub/f4c\n")
110 test.must_match('f5.out', "XYZZY is set\nf5.in\n")
111 test.must_match('f6.out', "f6.in\n")
112 test.must_match('f7.out', "f7.in\n")
113 test.must_match('f8.out', "f8.in\n")
114 test.must_match('f9.out', "f9.in\n")
115 test.must_match('f10.out', "f10.in\n")
116
117 test.pass_test()
118
119 # Local Variables:
120 # tab-width:4
121 # indent-tabs-mode:nil
122 # End:
123 # vim: set expandtab tabstop=4 shiftwidth=4: