Update Copyright years.
[scons.git] / test / Repository / BuildDir.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002, 2003 Steven Knight
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 import sys
29 import TestSCons
30
31 test = TestSCons.TestSCons()
32
33 test.subdir('repository', ['repository', 'src'],
34             'work1', ['work1', 'src'],
35             'work2', ['work2', 'src'])
36
37 opts = "-Y " + test.workpath('repository')
38
39 #
40 test.write(['repository', 'SConstruct'], r"""
41 BuildDir('build0', 'src', duplicate=0)
42 BuildDir('build1', 'src', duplicate=1)
43 SConscript('build0/SConscript')
44 SConscript('build1/SConscript')
45 """)
46
47 test.write(['repository', 'src', 'SConscript'], r"""
48 def cat(env, source, target):
49     target = str(target[0])
50     source = map(str, source)
51     print 'cat(%s) > %s' % (source, target)
52     f = open(target, "wb")
53     for src in source:
54         f.write(open(src, "rb").read())
55     f.close()
56
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 """)
63
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")
67
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)
71
72 #
73 test.run(chdir = 'work1', options = opts, arguments = '.')
74
75 test.fail_test(test.read(['work1', 'build0', 'output']) !=
76 """repository/src/aaa.in
77 repository/src/bbb.in
78 repository/src/ccc.in
79 """)
80
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'))
87
88 test.fail_test(test.read(['work1', 'build1', 'output']) !=
89 """repository/src/aaa.in
90 repository/src/bbb.in
91 repository/src/ccc.in
92 """)
93
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'))
100
101 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
102
103 #
104 test.write(['work1', 'src', 'bbb.in'], "work1/src/bbb.in\n")
105
106 test.run(chdir = 'work1', options = opts, arguments = '.')
107
108 test.fail_test(test.read(['work1', 'build0', 'output']) !=
109 """repository/src/aaa.in
110 work1/src/bbb.in
111 repository/src/ccc.in
112 """)
113
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'))
120
121 test.fail_test(test.read(['work1', 'build1', 'output']) !=
122 """repository/src/aaa.in
123 work1/src/bbb.in
124 repository/src/ccc.in
125 """)
126
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'))
133
134 test.up_to_date(chdir = 'work1', options = opts, arguments = '.')
135
136 # Now build the stuff in the repository,
137 # and redo the above steps in a fresh work directory.
138 test.writable('repository', 1)
139
140 test.run(chdir = 'repository', arguments = '.')
141
142 test.writable('repository', 0)
143
144 #
145 test.run(chdir = 'work2', options = opts, arguments = '.')
146
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'))
154
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'))
162
163 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
164
165 #
166 test.write(['work2', 'src', 'bbb.in'], "work2/src/bbb.in\n")
167
168 test.run(chdir = 'work2', options = opts, arguments = '.')
169
170 test.fail_test(test.read(['work2', 'build0', 'output']) !=
171 """repository/src/aaa.in
172 work2/src/bbb.in
173 repository/src/ccc.in
174 """)
175
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'))
182
183 test.fail_test(test.read(['work2', 'build1', 'output']) !=
184 """repository/src/aaa.in
185 work2/src/bbb.in
186 repository/src/ccc.in
187 """)
188
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'))
195
196 test.up_to_date(chdir = 'work2', options = opts, arguments = '.')
197
198 #
199 test.pass_test()