[ci skip] multi-user should be multiuser
[scons.git] / test / ParseDepends.py
blobb699017ead98ec4fb65ea0fa02707ccf17b96c9f
1 #!/usr/bin/env python
3 # SPDX-License-Identifier: MIT
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 import os.path
28 import TestSCons
30 _python_ = TestSCons._python_
32 test = TestSCons.TestSCons()
34 test.subdir('subdir', 'sub2')
36 test.write('build.py', r"""
37 import sys
38 with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as afp2, open(sys.argv[3], 'rb') as afp3:
39 f.write(afp2.read() + afp3.read())
40 """)
42 test.write('SConstruct', """\
43 Foo = Builder(action=r'%(_python_)s build.py $TARGET $SOURCES subdir/foo.dep')
44 Bar = Builder(action=r'%(_python_)s build.py $TARGET $SOURCES subdir/bar.dep')
45 DefaultEnvironment(tools=[])
46 env = Environment(tools=[], 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 DefaultEnvironment(tools=[])
142 ParseDepends('nonexistent_file')
143 """)
145 test.run()
147 test.write('SConstruct', """\
148 DefaultEnvironment(tools=[])
149 ParseDepends('nonexistent_file', must_exist=True)
150 """)
152 test.run(status=2, stderr=None)
154 test.must_contain_all_lines(test.stderr(), ["No such file or directory"])
156 test.pass_test()
158 # Local Variables:
159 # tab-width:4
160 # indent-tabs-mode:nil
161 # End:
162 # vim: set expandtab tabstop=4 shiftwidth=4: