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
|
#!/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
import sys
import TestSCons
test = TestSCons.TestSCons()
test.write('SConstruct', """
import sys
env=Environment(WINDOWS_INSERT_DEF=1)
env2 = Environment(LIBS = [ 'foo1', 'foo2', 'foo3' ],
LIBPATH = [ '.' ])
env.SharedLibrary(target = 'foo1', source = 'f1.c')
if sys.platform == 'win32':
env.StaticLibrary(target = 'foo1-static', source = 'f1.c')
else:
env.StaticLibrary(target = 'foo1', source = 'f1.c')
SharedLibrary(target = 'foo2',
source = Split('f2a.c f2b.c f2c.c'),
WINDOWS_INSERT_DEF = 1)
env.SharedLibrary(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.c'])
env2.Program(target = 'prog', source = 'prog.c')
""")
test.write('SConstructFoo', """
env=Environment()
obj = env.Object('foo', 'foo.c')
Default(env.SharedLibrary(target = 'foo', source = obj))
""")
test.write('SConstructFoo2', """
env=Environment()
obj = env.SharedObject('bar', 'foo.c')
Default(env.Library(target = 'foo', source = obj))
""")
test.write('foo.c', r"""
#include <stdio.h>
void
f1(void)
{
printf("foo.c\n");
fflush(stdout);
}
""")
test.write('f1.c', r"""
#include <stdio.h>
void
f1(void)
{
printf("f1.c\n");
fflush(stdout);
}
""")
test.write("foo1.def", r"""
LIBRARY "foo1"
DESCRIPTION "Foo1 Shared Library"
EXPORTS
f1
""")
test.write('f2a.c', r"""
#include <stdio.h>
void
f2a(void)
{
printf("f2a.c\n");
}
""")
test.write('f2b.c', r"""
#include <stdio.h>
void
f2b(void)
{
printf("f2b.c\n");
}
""")
test.write('f2c.c', r"""
#include <stdio.h>
void
f2c(void)
{
printf("f2c.c\n");
fflush(stdout);
}
""")
test.write("foo2.def", r"""
LIBRARY "foo2"
DESCRIPTION "Foo2 Shared Library"
EXPORTS
f2a
f2b
f2c
""")
test.write('f3a.c', r"""
#include <stdio.h>
void
f3a(void)
{
printf("f3a.c\n");
}
""")
test.write('f3b.c', r"""
#include <stdio.h>
void
f3b(void)
{
printf("f3b.c\n");
}
""")
test.write('f3c.c', r"""
#include <stdio.h>
void
f3c(void)
{
printf("f3c.c\n");
fflush(stdout);
}
""")
test.write("foo3.def", r"""
LIBRARY "foo3"
DESCRIPTION "Foo3 Shared Library"
EXPORTS
f3a
f3b
f3c
""")
test.write('prog.c', r"""
#include <stdio.h>
void f1(void);
void f2a(void);
void f2b(void);
void f2c(void);
void f3a(void);
void f3b(void);
void f3c(void);
int
main(int argc, char *argv[])
{
argv[argc++] = "--";
f1();
f2a();
f2b();
f2c();
f3a();
f3b();
f3c();
printf("prog.c\n");
return 0;
}
""")
test.run(arguments = '.',
stderr=TestSCons.noisy_ar,
match=TestSCons.match_re_dotall)
if os.name == 'posix':
os.environ['LD_LIBRARY_PATH'] = '.'
if sys.platform.find('irix') != -1:
os.environ['LD_LIBRARYN32_PATH'] = '.'
test.run(program = test.workpath('prog'),
stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.c\nprog.c\n")
if sys.platform == 'win32' or sys.platform.find('irix') != -1:
test.run(arguments = '-f SConstructFoo')
else:
test.run(arguments = '-f SConstructFoo', status=2, stderr='''\
scons: \*\*\* \[.*\] Source file: foo\..* is static and is not compatible with shared target: .*
''',
match=TestSCons.match_re_dotall)
# Run it again to make sure that we still get the error
# even though the static objects already exist.
test.run(arguments = '-f SConstructFoo', status=2, stderr='''\
scons: \*\*\* \[.*\] Source file: foo\..* is static and is not compatible with shared target: .*
''',
match=TestSCons.match_re_dotall)
test.run(arguments = '-f SConstructFoo2',
stderr=TestSCons.noisy_ar,
match=TestSCons.match_re_dotall)
if sys.platform == 'win32':
# Make sure we don't insert a .def source file (when
# WINDOWS_INSERT_DEF is set) and a .lib target file if
# they're specified explicitly.
test.write('SConstructBar', '''
env = Environment(WINDOWS_INSERT_DEF=1)
env2 = Environment(LIBS = [ 'foo4' ],
LIBPATH = [ '.' ])
env.SharedLibrary(target = ['foo4', 'foo4.lib'], source = ['f4.c', 'foo4.def'])
env2.Program(target = 'progbar', source = 'progbar.c')
''')
test.write('f4.c', r"""
#include <stdio.h>
f4(void)
{
printf("f4.c\n");
fflush(stdout);
}
""")
test.write("foo4.def", r"""
LIBRARY "foo4"
DESCRIPTION "Foo4 Shared Library"
EXPORTS
f4
""")
test.write('progbar.c', r"""
#include <stdio.h>
void f4(void);
int
main(int argc, char *argv[])
{
argv[argc++] = "--";
f4();
printf("progbar.c\n");
return 0;
}
""")
test.run(arguments = '-f SConstructBar .')
# Make sure there is (at most) one mention each of the
# appropriate .def and .lib files per line.
for line in test.stdout().split('\n'):
test.fail_test(line.count('foo4.def') > 1)
test.fail_test(line.count('foo4.lib') > 1)
test.run(program = test.workpath('progbar'),
stdout = "f4.c\nprogbar.c\n")
test.pass_test()
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|