From 4ddbc96c7b595ccb79fee49674b032da0b422bbe Mon Sep 17 00:00:00 2001 From: Veselin Dobrev Date: Thu, 22 Mar 2018 18:04:28 -0700 Subject: [PATCH] Speedup the default 'libs' property search ... (#7553) * Speedup the default 'libs' property search - important for external packages. * As advised by @alalazo, use tuples instead of lists inside _libs_default_handler. --- lib/spack/spack/spec.py | 43 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 68fa632e9e..35ab59f76a 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -729,31 +729,28 @@ def _libs_default_handler(descriptor, spec, cls): # unlikely). name = 'lib' + spec.name.replace('-', '?') - if '+shared' in spec: - libs = find_libraries( - name, root=spec.prefix, shared=True, recursive=True - ) - elif '~shared' in spec: - libs = find_libraries( - name, root=spec.prefix, shared=False, recursive=True - ) - else: - # Prefer shared - libs = find_libraries( - name, root=spec.prefix, shared=True, recursive=True - ) - if libs: - return libs + # To speedup the search for external packages configured e.g. in /usr, + # perform first non-recursive search in prefix.lib then in prefix.lib64 and + # finally search all of prefix recursively. The search stops when the first + # match is found. + prefix = spec.prefix + search_paths = [(prefix.lib, False), (prefix.lib64, False), (prefix, True)] - libs = find_libraries( - name, root=spec.prefix, shared=False, recursive=True - ) + # If '+shared' search only for shared library; if '~shared' search only for + # static library; otherwise, first search for shared and then for static. + search_shared = [True] if ('+shared' in spec) else \ + ([False] if ('~shared' in spec) else [True, False]) - if libs: - return libs - else: - msg = 'Unable to recursively locate {0} libraries in {1}' - raise RuntimeError(msg.format(spec.name, spec.prefix)) + for shared in search_shared: + for path, recursive in search_paths: + libs = find_libraries( + name, root=path, shared=shared, recursive=recursive + ) + if libs: + return libs + + msg = 'Unable to recursively locate {0} libraries in {1}' + raise RuntimeError(msg.format(spec.name, prefix)) class ForwardQueryToPackage(object):