Merge pull request #4584 from siegria/fix_piped_spawn_encoding
[scons.git] / test / LINK / SHLIBVERSIONFLAGS.py
blob158e82a3918e7426eac37c7d9e94046837d91535
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.
28 import TestSCons
30 import SCons.Defaults
31 import SCons.Platform
33 foo_c_src = "void foo() {}\n"
35 env = SCons.Defaults.DefaultEnvironment()
36 platform = SCons.Platform.platform_default()
37 tool_list = SCons.Platform.DefaultToolList(platform, env)
39 test = TestSCons.TestSCons()
40 if 'gnulink' in tool_list:
41 versionflags = r".+ -Wl,-soname=libfoo.so.1( .+)+"
42 soname = 'libfoo.so.4'
43 sonameVersionFlags = r".+ -Wl,-soname=%s( .+)+" % soname
45 elif 'sunlink' in tool_list:
46 versionflags = r".+ -h libfoo.so.1( .+)+"
47 soname = 'libfoo.so.4'
48 sonameVersionFlags = r".+ -h %s( .+)+" % soname
49 elif 'applelink' in tool_list:
50 versionflags = r".+ -Wl,-current_version,1.2.3( .+)+"
51 soname = 'libfoo.4.dylib'
52 sonameVersionFlags = r".+ -Wl,-compatibility_version,1.2.0(.+)+"
53 else:
54 test.skip_test('No testable linkers found, skipping the test\n')
56 # stdout must not contain SHLIBVERSIONFLAGS if there is no SHLIBVERSION provided
57 test.write('foo.c', foo_c_src)
58 test.write('SConstruct', "SharedLibrary('foo','foo.c')\n")
59 test.run()
60 test.fail_test(test.match_re_dotall(test.stdout(), versionflags))
61 test.run(arguments=['-c'])
63 # stdout must contain SHLIBVERSIONFLAGS if there is SHLIBVERSION provided
64 test = TestSCons.TestSCons()
65 test.write('foo.c', foo_c_src)
66 test.write('SConstruct', "SharedLibrary('foo','foo.c',SHLIBVERSION='1.2.3')\n")
67 test.run(stdout=versionflags, match=TestSCons.match_re_dotall)
68 test.run(arguments=['-c'])
70 # stdout must contain SONAME if there is SONAME provided
71 test = TestSCons.TestSCons()
72 test.write('foo.c', foo_c_src)
73 test.write('SConstruct', """
74 SharedLibrary('foo','foo.c',SHLIBVERSION='1.2.3',SONAME='%s')
75 """ % soname)
76 test.run(stdout=sonameVersionFlags, match=TestSCons.match_re_dotall)
77 test.must_exist(test.workpath(soname))
78 test.run(arguments=['-c'])
80 # stdout must contain SOVERSION if there is SOVERSION provided
81 test = TestSCons.TestSCons()
82 test.write('foo.c', foo_c_src)
83 test.write('SConstruct', """
84 SharedLibrary('foo','foo.c',SHLIBVERSION='1.2.3',SOVERSION='4')
85 """)
86 test.run(stdout=sonameVersionFlags, match=TestSCons.match_re_dotall)
87 test.must_exist(test.workpath(soname))
88 test.run(arguments=['-c'])
90 # test if both SONAME and SOVERSION are used
91 test = TestSCons.TestSCons()
92 test.write('foo.c', foo_c_src)
93 test.write('SConstruct', """
94 SharedLibrary('foo','foo.c',SHLIBVERSION='1.2.3',SONAME='%s',SOVERSION='4')
95 """ % soname)
96 test.run(status=2, stderr=None)
97 test.must_contain_all_lines(test.stderr(), ['Ambiguous library .so naming'])
99 test.pass_test()
101 # Local Variables:
102 # tab-width:4
103 # indent-tabs-mode:nil
104 # End:
105 # vim: set expandtab tabstop=4 shiftwidth=4: