Merge branch 'master' into jbrill-msvc-detect
[scons.git] / test / LINK / VersionedLib.py
blob44cd0ee4ffcf970f9371893ad84af1119b16ce2b
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
27 import TestSCons
29 import SCons.Platform
30 import SCons.Defaults
32 env = SCons.Defaults.DefaultEnvironment()
33 platform = SCons.Platform.platform_default()
34 tool_list = SCons.Platform.DefaultToolList(platform, env)
36 if 'gnulink' in tool_list:
37 test_plan = [
39 'libversion' : '2',
40 'files' : [ 'libtest.so', 'libtest.so.2', 'test.os' ],
41 'instfiles' : [ 'libtest.so', 'libtest.so.2' ],
42 'symlinks' : [ ('libtest.so', 'libtest.so.2') ],
45 'libversion' : '2.5',
46 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5', 'test.os' ],
47 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5' ],
48 'symlinks' : [ ('libtest.so', 'libtest.so.2.5'), ('libtest.so.2', 'libtest.so.2.5') ],
51 'libversion' : '2.5.4',
52 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4', 'test.os' ],
53 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4' ],
54 'symlinks' : [ ('libtest.so', 'libtest.so.2.5.4'), ('libtest.so.2', 'libtest.so.2.5.4') ],
57 'libversion' : '2.5.4.7.8',
58 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4.7.8', 'test.os' ],
59 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4.7.8' ],
60 'symlinks' : [ ('libtest.so', 'libtest.so.2.5.4.7.8'), ('libtest.so.2', 'libtest.so.2.5.4.7.8') ],
63 'libversion' : 'aabf114f',
64 'files' : [ 'libtest.so', 'libtest.so.aabf114f', 'test.os' ],
65 'instfiles' : [ 'libtest.so', 'libtest.so.aabf114f' ],
66 'symlinks' : [ ('libtest.so', 'libtest.so.aabf114f') ],
69 'libversion' : '2.dfffa11',
70 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.dfffa11', 'test.os' ],
71 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.dfffa11' ],
72 'symlinks' : [ ('libtest.so', 'libtest.so.2.dfffa11'), ('libtest.so.2', 'libtest.so.2.dfffa11') ],
75 elif 'applelink' in tool_list:
76 # All (?) the files we expect will get created in the current directory
77 test_plan = [
79 'libversion' : '2.5.4',
80 'files' : [ 'libtest.dylib', 'libtest.2.5.4.dylib', 'test.os' ],
81 'instfiles' : [ 'libtest.dylib', 'libtest.2.5.4.dylib' ],
82 'symlinks' : [],
85 elif 'cyglink' in tool_list:
86 test_plan = [
88 'libversion' : '2',
89 'files' : [ 'cygtest-2.dll', 'libtest-2.dll.a', 'libtest.dll.a', 'test.os' ],
90 'instfiles' : [ 'cygtest-2.dll', 'libtest-2.dll.a', 'libtest.dll.a' ],
91 'symlinks' : [ ('libtest.dll.a', 'libtest-2.dll.a') ],
94 'libversion' : '2.5',
95 'files' : [ 'cygtest-2-5.dll', 'libtest-2-5.dll.a', 'libtest.dll.a', 'test.os' ],
96 'instfiles' : [ 'cygtest-2-5.dll', 'libtest-2-5.dll.a', 'libtest.dll.a' ],
97 'symlinks' : [ ('libtest.dll.a', 'libtest-2-5.dll.a') ],
100 'libversion' : '2.5.4',
101 'files' : [ 'cygtest-2-5-4.dll', 'libtest-2-5-4.dll.a', 'libtest.dll.a', 'test.os' ],
102 'instfiles' : [ 'cygtest-2-5-4.dll', 'libtest-2-5-4.dll.a', 'libtest.dll.a' ],
103 'symlinks' : [ ('libtest.dll.a', 'libtest-2-5-4.dll.a') ],
106 'libversion' : '2.5.4.7.8',
107 'files' : [ 'cygtest-2-5-4-7-8.dll', 'libtest-2-5-4-7-8.dll.a', 'libtest.dll.a', 'test.os' ],
108 'instfiles' : [ 'cygtest-2-5-4-7-8.dll', 'libtest-2-5-4-7-8.dll.a', 'libtest.dll.a' ],
109 'symlinks' : [ ('libtest.dll.a', 'libtest-2-5-4-7-8.dll.a') ],
112 'libversion' : 'aabf114f',
113 'files' : [ 'cygtest-aabf114f.dll', 'libtest-aabf114f.dll.a', 'libtest.dll.a', 'test.os' ],
114 'instfiles' : [ 'cygtest-aabf114f.dll', 'libtest-aabf114f.dll.a', 'libtest.dll.a' ],
115 'symlinks' : [ ('libtest.dll.a', 'libtest-aabf114f.dll.a') ],
118 'libversion' : '2.dfffa11',
119 'files' : [ 'cygtest-2-dfffa11.dll', 'libtest-2-dfffa11.dll.a', 'libtest.dll.a', 'test.os' ],
120 'instfiles' : [ 'cygtest-2-dfffa11.dll', 'libtest-2-dfffa11.dll.a', 'libtest.dll.a' ],
121 'symlinks' : [ ('libtest.dll.a', 'libtest-2-dfffa11.dll.a') ],
124 elif 'mslink' in tool_list:
125 test_plan = [
127 'libversion' : '2.5.4',
128 'files' : [ 'test.dll', 'test.lib', 'test.obj' ],
129 'instfiles' : [ 'test.dll', 'test.lib' ],
130 'symlinks' : [],
133 elif 'sunlink' in tool_list:
134 test_plan = [
136 'libversion' : '2',
137 'files' : [ 'libtest.so', 'libtest.so.2', 'test.pic.o' ],
138 'instfiles' : [ 'libtest.so', 'libtest.so.2' ],
139 'symlinks' : [ ('libtest.so', 'libtest.so.2') ],
142 'libversion' : '2.5',
143 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5', 'test.pic.o' ],
144 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5' ],
145 'symlinks' : [ ('libtest.so', 'libtest.so.2.5'), ('libtest.so.2', 'libtest.so.2.5') ],
148 'libversion' : '2.5.4',
149 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4', 'test.pic.o' ],
150 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4' ],
151 'symlinks' : [ ('libtest.so', 'libtest.so.2.5.4'), ('libtest.so.2', 'libtest.so.2.5.4') ],
154 'libversion' : '2.5.4.7.8',
155 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4.7.8', 'test.pic.o' ],
156 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.5.4.7.8' ],
157 'symlinks' : [ ('libtest.so', 'libtest.so.2.5.4.7.8'), ('libtest.so.2', 'libtest.so.2.5.4.7.8') ],
160 'libversion' : 'aabf114f',
161 'files' : [ 'libtest.so', 'libtest.so.aabf114f', 'test.pic.o' ],
162 'instfiles' : [ 'libtest.so', 'libtest.so.aabf114f' ],
163 'symlinks' : [ ('libtest.so', 'libtest.so.aabf114f') ],
166 'libversion' : '2.dfffa11',
167 'files' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.dfffa11', 'test.pic.o' ],
168 'instfiles' : [ 'libtest.so', 'libtest.so.2', 'libtest.so.2.dfffa11' ],
169 'symlinks' : [ ('libtest.so', 'libtest.so.2.dfffa11'), ('libtest.so.2', 'libtest.so.2.dfffa11') ],
172 else:
173 test_plan = [
175 'libversion' : '2.5.4',
176 'files' : [ 'libtest.so', 'test.os' ],
177 'instfiles' : [ ],
181 test_c_src = """\
182 #if _WIN32
183 __declspec(dllexport)
184 #endif
185 int testlib(int n) { return n+1 ; }
188 test_c_src2 = """\
189 #if _WIN32
190 __declspec(dllexport)
191 #endif
192 int testlib(int n) { return n+11 ; }
195 testapp_c_src = """\
196 #if _WIN32
197 __declspec(dllimport)
198 #endif
199 int testlib(int n);
200 #include <stdio.h>
201 int main(int argc, char **argv)
203 int itest ;
205 itest = testlib(2) ;
206 printf("results: testlib(2) = %d\\n",itest) ;
207 return 0 ;
211 for t in test_plan:
213 test = TestSCons.TestSCons()
215 libversion = t['libversion']
216 files = t['files']
217 symlinks = t['symlinks']
218 instfiles = t['instfiles']
220 test.write('SConstruct', """\
221 DefaultEnvironment(tools=[])
222 env = Environment()
223 objs = env.SharedObject('test.c')
224 mylib = env.SharedLibrary('test', objs, SHLIBVERSION = '%s')
225 env.Program('testapp1.c', LIBS = mylib, LIBPATH='.')
226 env.Program('testapp2.c', LIBS = ['test'], LIBPATH='.')
227 instnode = env.InstallVersionedLib("#/installtest",mylib)
228 env.Default(instnode)
230 # Extra test to ensure that InstallVersionedLib can be called from the DefaultEnvironment
231 # Ensures orthogonality where InstallVersionedLib wasn't previously available: SCons gave NameError.
232 instnode = InstallVersionedLib("defaultenv-installtest",mylib)
233 Default(instnode)
235 """ % libversion)
237 test.write('test.c', test_c_src)
238 test.write('testapp1.c', testapp_c_src)
239 test.write('testapp2.c', testapp_c_src)
241 test.run(arguments = ['--tree=all'])
243 for f in files:
244 test.must_exist([ f])
245 for f in instfiles:
246 test.must_exist(['installtest', f])
247 test.must_exist(['defaultenv-installtest', f])
249 wrong_symlinks = []
250 for (linkname,expected) in symlinks:
251 try:
252 endpoint = os.readlink(linkname)
253 except OSError as err:
254 print("%s (expected symlink %r -> %r)" % (err, linkname, expected))
255 wrong_symlinks.append(linkname)
256 else:
257 if endpoint != expected:
258 print("Wrong symlink: %r -> %r (expected symlink: %r -> %r)" % (linkname, endpoint, linkname, expected))
259 wrong_symlinks.append(linkname)
261 if wrong_symlinks:
262 test.fail_test(wrong_symlinks)
264 # modify test.c and make sure it can recompile when links already exist
265 test.write('test.c', test_c_src2)
267 test.run()
269 test.run(arguments = ['-c'])
271 for f in files:
272 test.must_not_exist([ f])
274 for f in instfiles:
275 test.must_not_exist(['installtest', f])
276 test.must_not_exist(['defaultenv-installtest', f])
278 test.pass_test()
280 # Local Variables:
281 # tab-width:4
282 # indent-tabs-mode:nil
283 # End:
284 # vim: set expandtab tabstop=4 shiftwidth=4: