Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Depends.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 os.path
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('subdir', 'sub2')
36
37 test.write('build.py', r"""
38 import sys
39 contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
40 file = open(sys.argv[1], 'wb')
41 file.write(contents)
42 file.close()
43 """)
44
45 SUBDIR_foo_dep = os.path.join('$SUBDIR', 'foo.dep')
46 SUBDIR_f3_out = os.path.join('$SUBDIR', 'f3.out')
47
48 test.write('SConstruct', """
49 Foo = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/foo.dep')
50 Bar = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/bar.dep')
51 env = Environment(BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
52 env.Depends(target = ['f1.out', 'f2.out'], dependency = r'%(SUBDIR_foo_dep)s')
53 env.Depends(target = r'%(SUBDIR_f3_out)s', dependency = 'subdir/bar.dep')
54 env.Foo(target = 'f1.out', source = 'f1.in')
55 env.Foo(target = 'f2.out', source = 'f2.in')
56 env.Bar(target = 'subdir/f3.out', source = 'f3.in')
57 SConscript('subdir/SConscript', "env")
58 env.Foo(target = 'f5.out', source = 'f5.in')
59 env.Bar(target = 'sub2/f6.out', source = 'f6.in')
60 env.Depends(target = 'f5.out', dependency = 'sub2')
61 """ % locals())
62
63 test.write(['subdir', 'SConscript'], """
64 Import("env")
65 Depends(target = 'f4.out', dependency = 'bar.dep')
66 env.Bar(target = 'f4.out', source = 'f4.in')
67 """)
68
69 test.write('f1.in', "f1.in\n")
70 test.write('f2.in', "f2.in\n")
71 test.write('f3.in', "f3.in\n")
72 test.write(['subdir', 'f4.in'], "subdir/f4.in\n")
73 test.write('f5.in', "f5.in\n")
74 test.write('f6.in', "f6.in\n")
75
76 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
77 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
78
79 test.run(arguments = '.')
80
81 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 1\n")
82 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 1\n")
83 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 1\n")
84 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 1\n")
85 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 1\n")
86 test.must_match(['sub2', 'f6.out'], "f6.in\nsubdir/bar.dep 1\n")
87
88 #
89 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n")
90 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n")
91 test.write('f6.in', "f6.in 2\n")
92
93 test.run(arguments = '.')
94
95 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 2\n")
96 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 2\n")
97 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
98 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
99 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
100 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
101
102 #
103 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n")
104
105 test.run(arguments = '.')
106
107 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
108 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
109 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
110 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
111 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
112 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
113
114 #
115 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
116
117 test.run(arguments = '.')
118
119 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
120 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
121 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
122 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
123 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
124 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
125
126 #
127 test.write('f6.in', "f6.in 3\n")
128
129 test.run(arguments = '.')
130
131 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
132 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
133 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
134 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
135 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 3\n")
136 test.must_match(['sub2', 'f6.out'], "f6.in 3\nsubdir/bar.dep 3\n")
137
138 #
139 test.write('SConstruct', """\
140 env = Environment()
141 file1 = File('file1')
142 file2 = File('file2')
143 env.Depends(file1, [[file2, 'file3']])
144 """)
145
146 test.write('file2', "file2\n")
147 test.write('file3', "file3\n")
148
149 test.up_to_date(arguments = '.')
150
151 test.pass_test()
152
153 # Local Variables:
154 # tab-width:4
155 # indent-tabs-mode:nil
156 # End:
157 # vim: set expandtab tabstop=4 shiftwidth=4: