Merge branch 'master' into perf/env-setitem
[scons.git] / test / LINK / VersionedLib-subdir.py
blob53ae5d0c9ca6ed59333af635c916a717a7614bc3
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 """
27 Ensure that SharedLibrary builder with SHLIBVERSION='0.1.2' can build its target
28 in a subdirectory containing .so.0.1.2 in name.
30 This is regression test for issue mentioned in:
31 https://thread.gmane.org/gmane.comp.programming.tools.scons.user/27081
32 (historical - dead link)
33 """
35 import TestSCons
36 import os
37 import sys
39 import SCons.Platform
40 import SCons.Defaults
42 test = TestSCons.TestSCons()
44 test.write('foo.c', """
45 #if _WIN32
46 __declspec(dllexport)
47 #endif
48 int foo() { return 0; }
49 """)
51 test.write('main.c', """
52 #if _WIN32
53 __declspec(dllimport)
54 #endif
55 int foo();
56 int main(void)
58 return foo();
60 """)
62 env = SCons.Defaults.DefaultEnvironment()
63 platform = SCons.Platform.platform_default()
64 tool_list = SCons.Platform.DefaultToolList(platform, env)
66 if 'applelink' in tool_list:
67 subdir = 'blah.0.1.2.dylib.blah'
68 elif 'cyglink' in tool_list:
69 subdir = 'blah-0-1-2.dll.a.blah'
70 else:
71 subdir = 'blah.so.0.1.2.blah'
73 test.write('SConstruct', """
74 env = Environment()
75 env.AppendUnique(LIBPATH = [ '%s' ])
76 env.SharedLibrary('%s/foo', 'foo.c', SHLIBVERSION = '0.1.2')
77 env.Program('main.c', LIBS=['foo'])
78 """ % (subdir,subdir))
80 test.run(arguments = ['--tree=all'])
82 if platform == 'cygwin' or platform == 'win32':
83 # PATH is used to search for *.dll libraries on windows
84 path = os.environ.get('PATH','')
85 if path: path = path + os.pathsep
86 path = path + test.workpath(subdir)
87 os.environ['PATH'] = path
89 if os.name == 'posix':
90 os.environ['LD_LIBRARY_PATH'] = subdir
91 if sys.platform.find('irix') != -1:
92 os.environ['LD_LIBRARYN32_PATH'] = subdir
94 test.run(program = test.workpath('main'))
96 if 'gnulink' in tool_list:
97 # All (?) the files we expect will get created in the current directory
98 files = [
99 'libfoo.so',
100 'libfoo.so.0',
101 'libfoo.so.0.1.2',
103 obj = 'foo.os'
104 elif 'applelink' in tool_list:
105 # All (?) the files we expect will get created in the current directory
106 files = [
107 'libfoo.dylib',
108 'libfoo.0.1.2.dylib',
110 obj = 'foo.os'
111 elif 'cyglink' in tool_list:
112 # All (?) the files we expect will get created in the current directory
113 files = [
114 'cygfoo-0-1-2.dll',
115 'libfoo-0-1-2.dll.a',
116 'libfoo.dll.a',
118 obj = 'foo.os'
119 elif 'mslink' in tool_list:
120 # All (?) the files we expect will get created in the current directory
121 files = [
122 'foo.dll',
123 'foo.lib',
125 obj = 'foo.obj'
126 elif 'sunlink' in tool_list:
127 # All (?) the files we expect will get created in the current directory
128 files = [
129 'libfoo.so',
130 'libfoo.so.0',
131 'libfoo.so.0.1.2',
133 obj = 'so_foo.os'
134 else:
135 # All (?) the files we expect will get created in the current directory
136 files= [
137 'libfoo.so',
139 obj = 'foo.os'
141 test.must_exist([ obj ])
142 for f in files:
143 test.must_exist([ subdir, f ])
145 test.run(arguments = ['-c'])
147 test.must_not_exist([ obj ])
148 for f in files:
149 test.must_not_exist([ subdir, f ])
151 test.must_exist(['foo.c'])
152 test.must_exist(['SConstruct'])
154 test.pass_test()
156 # Local Variables:
157 # tab-width:4
158 # indent-tabs-mode:nil
159 # End:
160 # vim: set expandtab tabstop=4 shiftwidth=4: