summaryrefslogtreecommitdiffstats
path: root/test/Repository/BuildDir.py
blob: 905c61898dc6767222cb5d1bdf03131c70fc20f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python
#
# Copyright (c) 2001, 2002 Steven Knight
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

import os.path
import sys
import TestSCons

test = TestSCons.TestSCons()

test.subdir('repository', ['repository', 'src'],
            'work1', ['work1', 'src'],
            'work2', ['work2', 'src'])

opts = "-Y " + test.workpath('repository')

#
test.write(['repository', 'SConstruct'], r"""
BuildDir('build0', 'src')
BuildDir('build1', 'src', duplicate=0)
SConscript('build0/SConscript')
SConscript('build1/SConscript')
""")

test.write(['repository', 'src', 'SConscript'], r"""
def cat(env, source, target):
    target = str(target[0])
    source = map(str, source)
    print 'cat(%s) > %s' % (source, target)
    f = open(target, "wb")
    for src in source:
        f.write(open(src, "rb").read())
    f.close()

env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.mid', 'aaa.in')
env.Build('bbb.mid', 'bbb.in')
env.Build('ccc.mid', 'ccc.in')
env.Build('output', ['aaa.mid', 'bbb.mid', 'ccc.mid'])
""")

test.write(['repository', 'src', 'aaa.in'], "repository/src/aaa.in\n")
test.write(['repository', 'src', 'bbb.in'], "repository/src/bbb.in\n")
test.write(['repository', 'src', 'ccc.in'], "repository/src/ccc.in\n")

# Make the entire repository non-writable, so we'll detect
# if we try to write into it accidentally.
test.writable('repository', 0)

#
test.run(chdir = 'work1', options = opts, arguments = '.')

test.fail_test(test.read(['work1', 'build0', 'output']) !=
"""repository/src/aaa.in
repository/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(not os.path.exists('work1/build0/aaa.in'))
test.fail_test(not os.path.exists('work1/build0/bbb.in'))
test.fail_test(not os.path.exists('work1/build0/ccc.in'))
test.fail_test(not os.path.exists('work1/build0/aaa.mid'))
test.fail_test(not os.path.exists('work1/build0/bbb.mid'))
test.fail_test(not os.path.exists('work1/build0/ccc.mid'))

test.fail_test(test.read(['work1', 'build1', 'output']) !=
"""repository/src/aaa.in
repository/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(os.path.exists('work1/build1/aaa.in'))
test.fail_test(os.path.exists('work1/build1/bbb.in'))
test.fail_test(os.path.exists('work1/build1/ccc.in'))
test.fail_test(not os.path.exists('work1/build1/aaa.mid'))
test.fail_test(not os.path.exists('work1/build1/bbb.mid'))
test.fail_test(not os.path.exists('work1/build1/ccc.mid'))

test.up_to_date(chdir = 'work1', options = opts, arguments = '.')

#
test.write(['work1', 'src', 'bbb.in'], "work1/src/bbb.in\n")

test.run(chdir = 'work1', options = opts, arguments = '.')

test.fail_test(test.read(['work1', 'build0', 'output']) !=
"""repository/src/aaa.in
work1/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(not os.path.exists('work1/build0/aaa.in'))
test.fail_test(not os.path.exists('work1/build0/bbb.in'))
test.fail_test(not os.path.exists('work1/build0/ccc.in'))
test.fail_test(not os.path.exists('work1/build0/aaa.mid'))
test.fail_test(not os.path.exists('work1/build0/bbb.mid'))
test.fail_test(not os.path.exists('work1/build0/ccc.mid'))

test.fail_test(test.read(['work1', 'build1', 'output']) !=
"""repository/src/aaa.in
work1/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(os.path.exists('work1/build1/aaa.in'))
test.fail_test(os.path.exists('work1/build1/bbb.in'))
test.fail_test(os.path.exists('work1/build1/ccc.in'))
test.fail_test(not os.path.exists('work1/build1/aaa.mid'))
test.fail_test(not os.path.exists('work1/build1/bbb.mid'))
test.fail_test(not os.path.exists('work1/build1/ccc.mid'))

test.up_to_date(chdir = 'work1', options = opts, arguments = '.')

# Now build the stuff in the repository,
# and redo the above steps in a fresh work directory.
test.writable('repository', 1)

test.run(chdir = 'repository', arguments = '.')

test.writable('repository', 0)

#
test.run(chdir = 'work2', options = opts, arguments = '.')

test.fail_test(not os.path.exists('work2/build0/aaa.in'))
test.fail_test(not os.path.exists('work2/build0/bbb.in'))
test.fail_test(not os.path.exists('work2/build0/ccc.in'))
test.fail_test(os.path.exists('work2/build0/aaa.mid'))
test.fail_test(os.path.exists('work2/build0/bbb.mid'))
test.fail_test(os.path.exists('work2/build0/ccc.mid'))
test.fail_test(os.path.exists('work2/build0/output'))

test.fail_test(os.path.exists('work2/build1/aaa.in'))
test.fail_test(os.path.exists('work2/build1/bbb.in'))
test.fail_test(os.path.exists('work2/build1/ccc.in'))
test.fail_test(os.path.exists('work2/build1/aaa.mid'))
test.fail_test(os.path.exists('work2/build1/bbb.mid'))
test.fail_test(os.path.exists('work2/build1/ccc.mid'))
test.fail_test(os.path.exists('work2/build1/output'))

test.up_to_date(chdir = 'work2', options = opts, arguments = '.')

#
test.write(['work2', 'src', 'bbb.in'], "work2/src/bbb.in\n")

test.run(chdir = 'work2', options = opts, arguments = '.')

test.fail_test(test.read(['work2', 'build0', 'output']) !=
"""repository/src/aaa.in
work2/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(not os.path.exists('work2/build0/aaa.in'))
test.fail_test(not os.path.exists('work2/build0/bbb.in'))
test.fail_test(not os.path.exists('work2/build0/ccc.in'))
test.fail_test(os.path.exists('work2/build0/aaa.mid'))
test.fail_test(not os.path.exists('work2/build0/bbb.mid'))
test.fail_test(os.path.exists('work2/build0/ccc.mid'))

test.fail_test(test.read(['work2', 'build1', 'output']) !=
"""repository/src/aaa.in
work2/src/bbb.in
repository/src/ccc.in
""")

test.fail_test(os.path.exists('work2/build1/aaa.in'))
test.fail_test(os.path.exists('work2/build1/bbb.in'))
test.fail_test(os.path.exists('work2/build1/ccc.in'))
test.fail_test(os.path.exists('work2/build1/aaa.mid'))
test.fail_test(not os.path.exists('work2/build1/bbb.mid'))
test.fail_test(os.path.exists('work2/build1/ccc.mid'))

test.up_to_date(chdir = 'work2', options = opts, arguments = '.')

#
test.pass_test()