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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
#!/usr/bin/env python
#
# __COPYRIGHT__
#
# 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 time
import TestSCons
if sys.platform == 'win32':
_obj = '.obj'
_exe = '.exe'
else:
_obj = '.o'
_exe = ''
test = TestSCons.TestSCons()
test.subdir('repository',
['repository', 'src1'],
['repository', 'src2'],
['repository', 'src2', 'include'],
['repository', 'src2', 'xxx'],
['repository', 'build2'],
['repository', 'build2', 'foo'],
['repository', 'build2', 'bar'],
'work1',
['work1', 'src1'],
'work2',
['work2', 'src2'],
['work2', 'src2', 'include'],
['work2', 'src2', 'xxx'])
aaa_obj = 'aaa' + _obj
bbb_obj = 'bbb' + _obj
main_obj = 'main' + _obj
xxx_exe = 'xxx' + _exe
repository_build1_foo_xxx = test.workpath('repository', 'build1', 'foo', 'xxx')
work1_build1_foo_xxx = test.workpath('work1', 'build1', 'foo', 'xxx')
work1_build1_bar_xxx = test.workpath('work1', 'build1', 'bar', 'xxx')
repository_build2_foo_src2_xxx_xxx = test.workpath('repository', 'build2',
'foo', 'src2', 'xxx', 'xxx')
repository_build2_bar_src2_xxx_xxx = test.workpath('repository', 'build2',
'bar', 'src2', 'xxx', 'xxx')
work2_build2_foo_src2_xxx_xxx = test.workpath('work2', 'build2',
'foo', 'src2', 'xxx', 'xxx')
work2_build2_bar_src2_xxx_xxx = test.workpath('work2', 'build2',
'bar', 'src2', 'xxx', 'xxx')
opts = "-Y " + test.workpath('repository')
#
test.write(['repository', 'SConstruct'], r"""
OS = ARGUMENTS.get('OS', '')
build1_os = "#build1/" + OS
default = Environment()
ccflags = {
'' : '',
'foo' : '-DFOO',
'bar' : '-DBAR',
}
env1 = Environment(CCFLAGS = default.subst('$CCFLAGS %s' % ccflags[OS]),
CPPPATH = build1_os)
BuildDir(build1_os, 'src1')
SConscript(build1_os + '/SConscript', "env1")
SConscript('build2/foo/SConscript')
SConscript('build2/bar/SConscript')
""")
test.write(['repository', 'src1', 'SConscript'], r"""
Import("env1")
env1.Program('xxx', ['aaa.c', 'bbb.c', 'main.c'])
""")
test.write(['repository', 'build2', 'foo', 'SConscript'], r"""
BuildDir('src2', '#src2')
default = Environment()
env2 = Environment(CCFLAGS = default.subst('$CCFLAGS -DFOO'),
CPPPATH = ['#src2/xxx', '#src2/include'])
SConscript('src2/xxx/SConscript', "env2")
""")
test.write(['repository', 'build2', 'bar', 'SConscript'], r"""
BuildDir('src2', '#src2')
default = Environment()
env2 = Environment(CCFLAGS = default.subst('$CCFLAGS -DBAR'),
CPPPATH = ['#src2/xxx', '#src2/include'])
SConscript('src2/xxx/SConscript', "env2")
""")
test.write(['repository', 'src2', 'xxx', 'SConscript'], r"""
Import("env2")
env2.Program('xxx', ['main.c'])
""")
test.write(['repository', 'src1', 'iii.h'], r"""
#ifdef FOO
#define STRING "REPOSITORY_FOO"
#endif
#ifdef BAR
#define STRING "REPOSITORY_BAR"
#endif
""")
test.write(['repository', 'src1', 'aaa.c'], r"""
#include <stdio.h>
#include <stdlib.h>
#include <iii.h>
void
aaa(void)
{
printf("repository/src1/aaa.c: %s\n", STRING);
}
""")
test.write(['repository', 'src1', 'bbb.c'], r"""
#include <stdio.h>
#include <stdlib.h>
#include <iii.h>
void
bbb(void)
{
printf("repository/src1/bbb.c: %s\n", STRING);
}
""")
test.write(['repository', 'src1', 'main.c'], r"""
#include <stdio.h>
#include <stdlib.h>
#include <iii.h>
extern void aaa(void);
extern void bbb(void);
int
main(int argc, char *argv[])
{
#ifdef BAR
printf("Only when -DBAR.\n");
#endif
aaa();
bbb();
printf("repository/src1/main.c: %s\n", STRING);
exit (0);
}
""")
test.write(['repository', 'src2', 'include', 'my_string.h'], r"""
#ifdef FOO
#define INCLUDE_OS "FOO"
#endif
#ifdef BAR
#define INCLUDE_OS "BAR"
#endif
#define INCLUDE_STRING "repository/src2/include/my_string.h: %s\n"
""")
test.write(['repository', 'src2', 'xxx', 'include.h'], r"""
#include <my_string.h>
#ifdef FOO
#define XXX_OS "FOO"
#endif
#ifdef BAR
#define XXX_OS "BAR"
#endif
#define XXX_STRING "repository/src2/xxx/include.h: %s\n"
""")
test.write(['repository', 'src2', 'xxx', 'main.c'], r"""
#include <stdio.h>
#include <stdlib.h>
#include <include.h>
#ifdef FOO
#define MAIN_OS "FOO"
#endif
#ifdef BAR
#define MAIN_OS "BAR"
#endif
int
main(int argc, char *argv[])
{
printf(INCLUDE_STRING, INCLUDE_OS);
printf(XXX_STRING, XXX_OS);
printf("repository/src2/xxx/main.c: %s\n", MAIN_OS);
exit (0);
}
""")
#
test.run(chdir = 'repository', options = opts + " OS=foo", arguments = '.')
test.run(program = repository_build1_foo_xxx, stdout = """\
repository/src1/aaa.c: REPOSITORY_FOO
repository/src1/bbb.c: REPOSITORY_FOO
repository/src1/main.c: REPOSITORY_FOO
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
test.run(program = repository_build2_foo_src2_xxx_xxx, stdout = """\
repository/src2/include/my_string.h: FOO
repository/src2/xxx/include.h: FOO
repository/src2/xxx/main.c: FOO
""")
test.run(program = repository_build2_bar_src2_xxx_xxx, stdout = """\
repository/src2/include/my_string.h: BAR
repository/src2/xxx/include.h: BAR
repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
# Make the entire repository non-writable, so we'll detect
# if we try to write into it accidentally.
test.writable('repository', 0)
#
test.up_to_date(chdir = 'work1', options = opts + " OS=foo", arguments = 'build1')
test.fail_test(os.path.exists(test.workpath('work1', 'build1', 'foo', aaa_obj)))
test.fail_test(os.path.exists(test.workpath('work1', 'build1', 'foo', bbb_obj)))
test.fail_test(os.path.exists(test.workpath('work1', 'build1', 'foo', main_obj)))
test.fail_test(os.path.exists(test.workpath('work1', 'build1', 'foo', xxx_exe)))
#
test.run(chdir = 'work1', options = opts, arguments = 'OS=bar .')
test.run(program = work1_build1_bar_xxx, stdout = """\
Only when -DBAR.
repository/src1/aaa.c: REPOSITORY_BAR
repository/src1/bbb.c: REPOSITORY_BAR
repository/src1/main.c: REPOSITORY_BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
test.up_to_date(chdir = 'work1', options = opts + " OS=bar", arguments = 'build1')
# Ensure file time stamps will be newer.
time.sleep(2)
test.write(['work1', 'src1', 'iii.h'], r"""
#ifdef FOO
#define STRING "WORK_FOO"
#endif
#ifdef BAR
#define STRING "WORK_BAR"
#endif
""")
#
test.run(chdir = 'work1', options = opts + " OS=bar", arguments = 'build1')
test.run(program = work1_build1_bar_xxx, stdout = """\
Only when -DBAR.
repository/src1/aaa.c: WORK_BAR
repository/src1/bbb.c: WORK_BAR
repository/src1/main.c: WORK_BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
test.up_to_date(chdir = 'work1', options = opts + " OS=bar", arguments = 'build1')
#
test.run(chdir = 'work1', options = opts + " OS=foo", arguments = 'build1')
test.run(program = work1_build1_foo_xxx, stdout = """\
repository/src1/aaa.c: WORK_FOO
repository/src1/bbb.c: WORK_FOO
repository/src1/main.c: WORK_FOO
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
test.up_to_date(chdir = 'work1', options = opts + " OS=foo", arguments = 'build1')
#
test.up_to_date(chdir = 'work2', options = opts, arguments = 'build2')
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'foo', 'src2', 'xxx', aaa_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'foo', 'src2', 'xxx', bbb_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'foo', 'src2', 'xxx', main_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'foo', 'src2', 'xxx', xxx_exe)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'bar', 'src2', 'xxx', aaa_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'bar', 'src2', 'xxx', bbb_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'bar', 'src2', 'xxx', main_obj)))
test.fail_test(os.path.exists(test.workpath('work2', 'build2', 'bar', 'src2', 'xxx', xxx_exe)))
# Ensure file time stamps will be newer.
time.sleep(2)
test.write(['work2', 'src2', 'include', 'my_string.h'], r"""
#ifdef FOO
#define INCLUDE_OS "FOO"
#endif
#ifdef BAR
#define INCLUDE_OS "BAR"
#endif
#define INCLUDE_STRING "work2/src2/include/my_string.h: %s\n"
""")
#
test.run(chdir = 'work2', options = opts, arguments = 'build2')
test.run(program = work2_build2_foo_src2_xxx_xxx, stdout = """\
work2/src2/include/my_string.h: FOO
repository/src2/xxx/include.h: FOO
repository/src2/xxx/main.c: FOO
""")
test.run(program = work2_build2_bar_src2_xxx_xxx, stdout = """\
work2/src2/include/my_string.h: BAR
repository/src2/xxx/include.h: BAR
repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
# Ensure file time stamps will be newer.
time.sleep(2)
test.write(['work2', 'src2', 'xxx', 'include.h'], r"""
#include <my_string.h>
#ifdef FOO
#define XXX_OS "FOO"
#endif
#ifdef BAR
#define XXX_OS "BAR"
#endif
#define XXX_STRING "work2/src2/xxx/include.h: %s\n"
""")
test.run(chdir = 'work2', options = opts, arguments = 'build2')
test.run(program = work2_build2_foo_src2_xxx_xxx, stdout = """\
work2/src2/include/my_string.h: FOO
work2/src2/xxx/include.h: FOO
repository/src2/xxx/main.c: FOO
""")
test.run(program = work2_build2_bar_src2_xxx_xxx, stdout = """\
work2/src2/include/my_string.h: BAR
work2/src2/xxx/include.h: BAR
repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
#
test.unlink(['work2', 'src2', 'include', 'my_string.h'])
test.run(chdir = 'work2', options = opts, arguments = 'build2')
test.run(program = work2_build2_foo_src2_xxx_xxx, stdout = """\
repository/src2/include/my_string.h: FOO
work2/src2/xxx/include.h: FOO
repository/src2/xxx/main.c: FOO
""")
test.run(program = work2_build2_bar_src2_xxx_xxx, stdout = """\
repository/src2/include/my_string.h: BAR
work2/src2/xxx/include.h: BAR
repository/src2/xxx/main.c: BAR
""")
test.fail_test(os.path.exists(test.workpath('repository', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('repository', 'src2', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work1', 'src1', '.sconsign')))
test.fail_test(os.path.exists(test.workpath('work2', 'src2', '.sconsign')))
#
test.pass_test()
|