diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-06-05 17:54:45 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-06-05 19:28:46 +0530 |
commit | 91b43960796bf6b9ecc23f39d790b40b3647b759 (patch) | |
tree | 90455fc3d9c65a7cb296816aac1101a94dc1c16e | |
parent | 39da01cc3ce1915afe0baa3435a35dd89dc68f53 (diff) | |
download | meson-nirbheek/find_library_fixes.tar.gz |
find_library: Add a cache for library searchingnirbheek/find_library_fixes
Otherwise we can end up searching for the same library tens of times,
because pkg-config does not de-duplicate -lfoo args before returning
them.
We use -Wl,--start-group/end-group, so we do not need to worry about
ordering issues in static libraries.
-rw-r--r-- | mesonbuild/compilers/c.py | 21 | ||||
-rw-r--r-- | mesonbuild/compilers/vala.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/boost.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/ui.py | 2 |
4 files changed, 17 insertions, 10 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 354124ab2..4208b8985 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -46,6 +46,7 @@ from .compilers import ( class CCompiler(Compiler): library_dirs_cache = {} program_dirs_cache = {} + find_library_cache = {} def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs): # If a child ObjC or CPP class has already set it, don't set it ourselves @@ -837,13 +838,8 @@ class CCompiler(Compiler): raise AssertionError('BUG: unknown libtype {!r}'.format(libtype)) return prefixes, suffixes - def find_library_impl(self, libname, env, extra_dirs, code, libtype='default'): - # These libraries are either built-in or invalid - if libname in self.ignore_libs: - return [] + def find_library_real(self, libname, env, extra_dirs, code, libtype): # First try if we can just add the library as -l. - if extra_dirs and isinstance(extra_dirs, str): - extra_dirs = [extra_dirs] # Gcc + co seem to prefer builtin lib dirs to -L dirs. # Only try to find std libs if no extra dirs specified. if not extra_dirs and libtype == 'default': @@ -864,7 +860,18 @@ class CCompiler(Compiler): trial = os.path.join(d, prefix + libname + '.' + suffix) if os.path.isfile(trial): return [trial] - return None + return [] + + def find_library_impl(self, libname, env, extra_dirs, code, libtype): + # These libraries are either built-in or invalid + if libname in self.ignore_libs: + return [] + if isinstance(extra_dirs, str): + extra_dirs = [extra_dirs] + key = (tuple(self.exelist), libname, tuple(extra_dirs), code, libtype) + if key not in self.find_library_cache: + self.find_library_cache[key] = self.find_library_real(libname, env, extra_dirs, code, libtype) + return self.find_library_cache[key][:] def find_library(self, libname, env, extra_dirs, libtype='default'): code = 'int main(int argc, char **argv) { return 0; }' diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index 6194d1aed..e89bc8db4 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -93,7 +93,7 @@ class ValaCompiler(Compiler): if os.path.isfile(vapi): return [vapi] mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname)) - return None + return [] def thread_flags(self, env): return [] diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index a17fb58de..301d7588e 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -363,7 +363,7 @@ class BoostDependency(ExternalDependency): libname = 'boost_' + module + tag args = self.compiler.find_library(libname, self.env, self.extra_lib_dirs()) - if args is None: + if not args: mlog.debug("Couldn\'t find library '{}' for boost module '{}' (ABI tag = '{}')".format(libname, module, tag)) all_found = False else: diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index b07b0ae9f..4f4fe7852 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -568,7 +568,7 @@ class VulkanDependency(ExternalDependency): else: # simply try to guess it, usually works on linux libs = self.compiler.find_library('vulkan', environment, []) - if libs is not None and self.compiler.has_header('vulkan/vulkan.h', '', environment): + if libs and self.compiler.has_header('vulkan/vulkan.h', '', environment): self.type_name = 'system' self.is_found = True self.version = 1 # TODO |