diff options
author | Veselin Dobrev <v-dobrev@users.noreply.github.com> | 2018-03-22 18:04:28 -0700 |
---|---|---|
committer | Adam J. Stewart <ajstewart426@gmail.com> | 2018-03-22 20:04:28 -0500 |
commit | 4ddbc96c7b595ccb79fee49674b032da0b422bbe (patch) | |
tree | 833af248b3103f20fe5d6da793bcbb3ed0d23ad5 /lib | |
parent | a0494003a2421cfa6c4fbaaefb7266bbe6a21410 (diff) | |
download | spack-4ddbc96c7b595ccb79fee49674b032da0b422bbe.tar.gz spack-4ddbc96c7b595ccb79fee49674b032da0b422bbe.tar.bz2 spack-4ddbc96c7b595ccb79fee49674b032da0b422bbe.tar.xz spack-4ddbc96c7b595ccb79fee49674b032da0b422bbe.zip |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/spec.py | 45 |
1 files changed, 21 insertions, 24 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 - - libs = find_libraries( - name, root=spec.prefix, shared=False, recursive=True - ) + # 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)] + + # 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]) + + 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 - if libs: - return libs - else: - msg = 'Unable to recursively locate {0} libraries in {1}' - raise RuntimeError(msg.format(spec.name, spec.prefix)) + msg = 'Unable to recursively locate {0} libraries in {1}' + raise RuntimeError(msg.format(spec.name, prefix)) class ForwardQueryToPackage(object): |