Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / ParseDepends.py
blob2de2105819fed6d30a0054490a1504385ded6f39
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
27 import os.path
29 import TestSCons
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 test.subdir('subdir', 'sub2')
37 test.write('build.py', r"""
38 import sys
39 with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as afp2, open(sys.argv[3], 'rb') as afp3:
40 f.write(afp2.read() + afp3.read())
41 """)
43 test.write('SConstruct', """
44 Foo = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/foo.dep')
45 Bar = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/bar.dep')
46 env = Environment(BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
47 env.ParseDepends('foo.d')
48 env.ParseDepends('bar.d')
49 env.Foo(target = 'f1.out', source = 'f1.in')
50 env.Foo(target = 'f2.out', source = 'f2.in')
51 env.Bar(target = 'subdir/f3.out', source = 'f3.in')
52 SConscript('subdir/SConscript', "env")
53 env.Foo(target = 'f5.out', source = 'f5.in')
54 env.Bar(target = 'sub2/f6.out', source = 'f6.in')
55 """ % locals())
57 test.write('foo.d', "f1.out f2.out: %s\n" % os.path.join('subdir', 'foo.dep'))
58 test.write('bar.d', "%s: %s\nf5.out: sub2" % (os.path.join('subdir', 'f3.out'),
59 os.path.join('subdir', 'bar.dep')))
61 test.write(['subdir', 'SConscript'], """
62 Import("env")
63 ParseDepends('bar.d')
64 env.Bar(target = 'f4.out', source = 'f4.in')
65 """)
67 test.write(['subdir', 'bar.d'], "f4.out: bar.dep\n")
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")
76 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
77 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
79 test.run(arguments = '.')
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")
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")
93 test.run(arguments = '.')
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")
103 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n")
105 test.run(arguments = '.')
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")
115 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
117 test.run(arguments = '.')
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")
127 test.write('f6.in', "f6.in 3\n")
129 test.run(arguments = '.')
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")
140 test.write('SConstruct', """
141 ParseDepends('nonexistent_file')
142 """)
144 test.run()
146 test.write('SConstruct', """
147 ParseDepends('nonexistent_file', must_exist=1)
148 """)
150 test.run(status=2, stderr=None)
152 test.must_contain_all_lines(test.stderr(), ["No such file or directory"])
154 test.pass_test()
156 # Local Variables:
157 # tab-width:4
158 # indent-tabs-mode:nil
159 # End:
160 # vim: set expandtab tabstop=4 shiftwidth=4: