aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-07-10 04:27:23 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-07-10 12:42:52 -0700
commit47c68a59938c927b3879ecc0e237c2af0156e35a (patch)
tree3a994053ee4ad8d105236e0274380f3a78fbe7dd
parent09ad29ec560f2a05108694d909de30b5e3e58357 (diff)
downloadmeson-47c68a59938c927b3879ecc0e237c2af0156e35a.zip
meson-47c68a59938c927b3879ecc0e237c2af0156e35a.tar.gz
meson-47c68a59938c927b3879ecc0e237c2af0156e35a.tar.bz2
find_library: Validate and sort globbed shared library files
We need to pick the library with the highest version, which is what the OpenBSD linker also does. https://github.com/mesonbuild/meson/issues/3570#issuecomment-403638752
-rw-r--r--mesonbuild/compilers/c.py21
-rwxr-xr-xrun_unittests.py24
2 files changed, 39 insertions, 6 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index b62155b..af3e2c4 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -866,12 +866,29 @@ class CCompiler(Compiler):
return patterns
@staticmethod
- def _get_trials_from_pattern(pattern, directory, libname):
+ def _sort_shlibs_openbsd(libs):
+ filtered = []
+ for lib in libs:
+ # Validate file as a shared library of type libfoo.so.X.Y
+ ret = lib.rsplit('.so.', maxsplit=1)
+ if len(ret) != 2:
+ continue
+ try:
+ float(ret[1])
+ except ValueError:
+ continue
+ filtered.append(lib)
+ float_cmp = lambda x: float(x.rsplit('.so.', maxsplit=1)[1])
+ return sorted(filtered, key=float_cmp, reverse=True)
+
+ @classmethod
+ def _get_trials_from_pattern(cls, pattern, directory, libname):
f = os.path.join(directory, pattern.format(libname))
+ # Globbing for OpenBSD
if '*' in pattern:
# NOTE: globbing matches directories and broken symlinks
# so we have to do an isfile test on it later
- return glob.glob(f)
+ return cls._sort_shlibs_openbsd(glob.glob(f))
return [f]
@staticmethod
diff --git a/run_unittests.py b/run_unittests.py
index df4603e..f4e95a3 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -522,12 +522,28 @@ class InternalTests(unittest.TestCase):
self.assertEqual(p, shr)
p = cc.get_library_naming(env, 'static')
self.assertEqual(p, stc)
- p = cc.get_library_naming(env, 'default')
- self.assertEqual(p, shr + stc)
- p = cc.get_library_naming(env, 'shared-static')
- self.assertEqual(p, shr + stc)
p = cc.get_library_naming(env, 'static-shared')
self.assertEqual(p, stc + shr)
+ p = cc.get_library_naming(env, 'shared-static')
+ self.assertEqual(p, shr + stc)
+ p = cc.get_library_naming(env, 'default')
+ self.assertEqual(p, shr + stc)
+ # Test find library by mocking up openbsd
+ if platform != 'openbsd':
+ return
+ with tempfile.TemporaryDirectory() as tmpdir:
+ with open(os.path.join(tmpdir, 'libfoo.so.6.0'), 'w') as f:
+ f.write('')
+ with open(os.path.join(tmpdir, 'libfoo.so.5.0'), 'w') as f:
+ f.write('')
+ with open(os.path.join(tmpdir, 'libfoo.so.54.0'), 'w') as f:
+ f.write('')
+ with open(os.path.join(tmpdir, 'libfoo.so.66a.0b'), 'w') as f:
+ f.write('')
+ with open(os.path.join(tmpdir, 'libfoo.so.70.0.so.1'), 'w') as f:
+ f.write('')
+ found = cc.find_library_real('foo', env, [tmpdir], '', 'default')
+ self.assertEqual(os.path.basename(found[0]), 'libfoo.so.54.0')
def test_find_library_patterns(self):
'''