From 47c68a59938c927b3879ecc0e237c2af0156e35a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 10 Jul 2018 04:27:23 +0530 Subject: 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 --- mesonbuild/compilers/c.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers') 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 -- cgit v1.1