[ci skip] update generated files
[scons.git] / test / Repository / VariantDir.py
blobeb33aa155c0ac983ac0ff16d1d1f22b7f074b63d
1 #!/usr/bin/env python
3 # MIT License
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 test = TestSCons.TestSCons()
32 test.subdir('repository', ['repository', 'src'],
33 'work1', ['work1', 'src'],
34 'work2', ['work2', 'src'])
36 opts = "-Y " + test.workpath('repository')
39 test.write(['repository', 'SConstruct'], r"""
40 DefaultEnvironment(tools=[]) # test speedup
41 VariantDir('build0', 'src', duplicate=0)
42 VariantDir('build1', 'src', duplicate=1)
43 SConscript('build0/SConscript')
44 SConscript('build1/SConscript')
45 """)
47 test.write(['repository', 'src', 'SConscript'], r"""
48 def cat(env, source, target):
49 target = str(target[0])
50 source = list(map(str, source))
51 print('cat(%s) > %s' % (source, target))
52 with open(target, "w") as ofp:
53 for src in source:
54 with open(src, "r") as ifp:
55 ofp.write(ifp.read())
57 env = Environment(BUILDERS={'Build':Builder(action=cat)})
58 env.Build('aaa.mid', 'aaa.in')
59 env.Build('bbb.mid', 'bbb.in')
60 env.Build('ccc.mid', 'ccc.in')
61 env.Build('output', ['aaa.mid', 'bbb.mid', 'ccc.mid'])
62 """)
64 test.write(['repository', 'src', 'aaa.in'], "repository/src/aaa.in\n")
65 test.write(['repository', 'src', 'bbb.in'], "repository/src/bbb.in\n")
66 test.write(['repository', 'src', 'ccc.in'], "repository/src/ccc.in\n")
68 # Make the entire repository non-writable, so we'll detect
69 # if we try to write into it accidentally.
70 test.writable('repository', 0)
73 test.run(chdir = 'work1', options = opts, arguments = '.')
75 test.must_match(['work1', 'build0', 'output'],
76 """repository/src/aaa.in
77 repository/src/bbb.in
78 repository/src/ccc.in
79 """, mode='r')
81 test.fail_test(os.path.exists('work1/build0/aaa.in'))
82 test.fail_test(os.path.exists('work1/build0/bbb.in'))
83 test.fail_test(os.path.exists('work1/build0/ccc.in'))
84 test.fail_test(not os.path.exists('work1/build0/aaa.mid'))
85 test.fail_test(not os.path.exists('work1/build0/bbb.mid'))
86 test.fail_test(not os.path.exists('work1/build0/ccc.mid'))
88 test.must_match(['work1', 'build1', 'output'],
89 """repository/src/aaa.in
90 repository/src/bbb.in
91 repository/src/ccc.in
92 """, mode='r')
94 test.fail_test(not os.path.exists('work1/build1/aaa.in'))
95 test.fail_test(not os.path.exists('work1/build1/bbb.in'))
96 test.fail_test(not os.path.exists('work1/build1/ccc.in'))
97 test.fail_test(not os.path.exists('work1/build1/aaa.mid'))
98 test.fail_test(not os.path.exists('work1/build1/bbb.mid'))
99 test.fail_test(not os.path.exists('work1/build1/ccc.mid'))
101 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
104 test.write(['work1', 'src', 'bbb.in'], "work1/src/bbb.in\n")
106 test.run(chdir = 'work1', options = opts, arguments = '.')
108 test.must_match(['work1', 'build0', 'output'],
109 """repository/src/aaa.in
110 work1/src/bbb.in
111 repository/src/ccc.in
112 """, mode='r')
114 test.fail_test(os.path.exists('work1/build0/aaa.in'))
115 test.fail_test(os.path.exists('work1/build0/bbb.in'))
116 test.fail_test(os.path.exists('work1/build0/ccc.in'))
117 test.fail_test(not os.path.exists('work1/build0/aaa.mid'))
118 test.fail_test(not os.path.exists('work1/build0/bbb.mid'))
119 test.fail_test(not os.path.exists('work1/build0/ccc.mid'))
121 test.must_match(['work1', 'build1', 'output'],
122 """repository/src/aaa.in
123 work1/src/bbb.in
124 repository/src/ccc.in
125 """, mode='r')
127 test.fail_test(not os.path.exists('work1/build1/aaa.in'))
128 test.fail_test(not os.path.exists('work1/build1/bbb.in'))
129 test.fail_test(not os.path.exists('work1/build1/ccc.in'))
130 test.fail_test(not os.path.exists('work1/build1/aaa.mid'))
131 test.fail_test(not os.path.exists('work1/build1/bbb.mid'))
132 test.fail_test(not os.path.exists('work1/build1/ccc.mid'))
134 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
136 # Now build the stuff in the repository,
137 # and redo the above steps in a fresh work directory.
138 test.writable('repository', 1)
140 test.run(chdir = 'repository', arguments = '.')
142 test.writable('repository', 0)
145 test.run(chdir = 'work2', options = opts, arguments = '.')
147 test.fail_test(os.path.exists('work2/build0/aaa.in'))
148 test.fail_test(os.path.exists('work2/build0/bbb.in'))
149 test.fail_test(os.path.exists('work2/build0/ccc.in'))
150 test.fail_test(os.path.exists('work2/build0/aaa.mid'))
151 test.fail_test(os.path.exists('work2/build0/bbb.mid'))
152 test.fail_test(os.path.exists('work2/build0/ccc.mid'))
153 test.fail_test(os.path.exists('work2/build0/output'))
155 test.fail_test(not os.path.exists('work2/build1/aaa.in'))
156 test.fail_test(not os.path.exists('work2/build1/bbb.in'))
157 test.fail_test(not os.path.exists('work2/build1/ccc.in'))
158 test.fail_test(os.path.exists('work2/build1/aaa.mid'))
159 test.fail_test(os.path.exists('work2/build1/bbb.mid'))
160 test.fail_test(os.path.exists('work2/build1/ccc.mid'))
161 test.fail_test(os.path.exists('work2/build1/output'))
163 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
166 test.write(['work2', 'src', 'bbb.in'], "work2/src/bbb.in\n")
168 test.run(chdir = 'work2', options = opts, arguments = '.')
170 test.must_match(['work2', 'build0', 'output'],
171 """repository/src/aaa.in
172 work2/src/bbb.in
173 repository/src/ccc.in
174 """, mode='r')
176 test.fail_test(os.path.exists('work2/build0/aaa.in'))
177 test.fail_test(os.path.exists('work2/build0/bbb.in'))
178 test.fail_test(os.path.exists('work2/build0/ccc.in'))
179 test.fail_test(os.path.exists('work2/build0/aaa.mid'))
180 test.fail_test(not os.path.exists('work2/build0/bbb.mid'))
181 test.fail_test(os.path.exists('work2/build0/ccc.mid'))
183 test.must_match(['work2', 'build1', 'output'],
184 """repository/src/aaa.in
185 work2/src/bbb.in
186 repository/src/ccc.in
187 """, mode='r')
189 test.fail_test(not os.path.exists('work2/build1/aaa.in'))
190 test.fail_test(not os.path.exists('work2/build1/bbb.in'))
191 test.fail_test(not os.path.exists('work2/build1/ccc.in'))
192 test.fail_test(os.path.exists('work2/build1/aaa.mid'))
193 test.fail_test(not os.path.exists('work2/build1/bbb.mid'))
194 test.fail_test(os.path.exists('work2/build1/ccc.mid'))
196 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
199 test.pass_test()
201 # Local Variables:
202 # tab-width:4
203 # indent-tabs-mode:nil
204 # End:
205 # vim: set expandtab tabstop=4 shiftwidth=4: