diff options
-rw-r--r-- | mesonbuild/compilers/c.py | 21 | ||||
-rwxr-xr-x | run_unittests.py | 24 |
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): ''' |