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.
This commit is contained in:
Veselin Dobrev 2018-03-22 18:04:28 -07:00 committed by Adam J. Stewart
parent a0494003a2
commit 4ddbc96c7b

View file

@ -729,31 +729,28 @@ def _libs_default_handler(descriptor, spec, cls):
# unlikely). # unlikely).
name = 'lib' + spec.name.replace('-', '?') name = 'lib' + spec.name.replace('-', '?')
if '+shared' in spec: # 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( libs = find_libraries(
name, root=spec.prefix, shared=True, recursive=True name, root=path, shared=shared, recursive=recursive
)
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: if libs:
return libs return libs
libs = find_libraries(
name, root=spec.prefix, shared=False, recursive=True
)
if libs:
return libs
else:
msg = 'Unable to recursively locate {0} libraries in {1}' msg = 'Unable to recursively locate {0} libraries in {1}'
raise RuntimeError(msg.format(spec.name, spec.prefix)) raise RuntimeError(msg.format(spec.name, prefix))
class ForwardQueryToPackage(object): class ForwardQueryToPackage(object):