Skip to content

Commit

Permalink
Check that soname matches the filename. Closes #785.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Oct 8, 2016
1 parent 9fdec2d commit 4dc798d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Expand Up @@ -1827,7 +1827,8 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
soversion = target.soversion
else:
soversion = None
commands += linker.get_soname_args(target.name, abspath, soversion)
soname = target.prefix + target.name + '.' + target.suffix
commands += linker.get_soname_args(soname, abspath, soversion)
# This is only visited when using the Visual Studio toolchain
if target.vs_module_defs and hasattr(linker, 'gen_vs_module_defs_args'):
commands += linker.gen_vs_module_defs_args(target.vs_module_defs.rel_to_builddir(self.build_to_src))
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers.py
Expand Up @@ -1894,7 +1894,7 @@ def get_gcc_soname_args(gcc_type, shlib_name, path, soversion):
sostr = '.' + soversion
if gcc_type == GCC_STANDARD or gcc_type == GCC_MINGW:
# Might not be correct for mingw but seems to work.
return ['-Wl,-soname,lib%s.so%s' % (shlib_name, sostr)]
return ['-Wl,-soname,%s%s' % (shlib_name, sostr)]
elif gcc_type == GCC_OSX:
return ['-install_name', os.path.join(path, 'lib' + shlib_name + '.dylib')]
else:
Expand Down
31 changes: 26 additions & 5 deletions munit.py
Expand Up @@ -15,26 +15,47 @@

import unittest, os, shutil
import subprocess
import re

def get_soname(fname):
# HACK, fix to not use shell.
raw_out = subprocess.check_output(['readelf', '-a', fname])
pattern = re.compile(b'soname: \[(.*?)\]')
for line in raw_out.split(b'\n'):
m = pattern.search(line)
if m is not None:
return m.group(1)

class LinuxlikeTests(unittest.TestCase):

def setUp(self):
super().setUp()
src_root = os.path.split(__file__)[0]
self.builddir = 'unittestdir' # fixme to be unique
self.meson_command = [os.path.join(src_root, 'meson.py')]
self.ninja_command = ['ninja']
self.ninja_command = ['ninja', '-C', self.builddir]
self.common_test_dir = os.path.join(src_root, 'test cases/common')
self.builddir = 'unittestdir' # fixme to be unique
os.mkdir(self.builddir)

def tearDown(self):
shutil.rmtree(self.builddir)
super().tearDown()

def test_simple(self):
testdir = os.path.join(self.common_test_dir, '1 trivial')
def test_basic_soname(self):
testdir = os.path.join(self.common_test_dir, '4 shared')
subprocess.check_call(self.meson_command + [testdir, self.builddir])
subprocess.check_call(self.ninja_command)
lib1 = os.path.join(self.builddir, 'libmylib.so')
soname = get_soname(lib1)
self.assertEqual(soname, b'libmylib.so')

def test_custom_soname(self):
testdir = os.path.join(self.common_test_dir, '27 library versions')
subprocess.check_call(self.meson_command + [testdir, self.builddir])
subprocess.check_call(self.ninja_command, cwd=self.builddir)
subprocess.check_call(self.ninja_command)
lib1 = os.path.join(self.builddir, 'prefixsomelib.suffix')
soname = get_soname(lib1)
self.assertEqual(soname, b'prefixsomelib.suffix')

if __name__ == '__main__':
unittest.main()

0 comments on commit 4dc798d

Please sign in to comment.