Bugfix: find_libraries (#32653)
53a7b49
created a reference error which broke `.libs` (and
`find_libraries`) for many packages. This fixes the reference
error and improves the testing for `find_libraries` by actually
checking the extension types of libraries that are retrieved by
the function.
This commit is contained in:
parent
7971985a06
commit
deca34676f
@ -2055,22 +2055,22 @@ def find_libraries(libraries, root, shared=True, recursive=False):
|
|||||||
raise TypeError(message)
|
raise TypeError(message)
|
||||||
|
|
||||||
if is_windows:
|
if is_windows:
|
||||||
static = "lib"
|
static_ext = "lib"
|
||||||
shared = "dll"
|
shared_ext = "dll"
|
||||||
else:
|
else:
|
||||||
# Used on both Linux and macOS
|
# Used on both Linux and macOS
|
||||||
static = "a"
|
static_ext = "a"
|
||||||
shared = "so"
|
shared_ext = "so"
|
||||||
|
|
||||||
# Construct the right suffix for the library
|
# Construct the right suffix for the library
|
||||||
if shared:
|
if shared:
|
||||||
# Used on both Linux and macOS
|
# Used on both Linux and macOS
|
||||||
suffixes = [shared]
|
suffixes = [shared_ext]
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
# Only used on macOS
|
# Only used on macOS
|
||||||
suffixes.append("dylib")
|
suffixes.append("dylib")
|
||||||
else:
|
else:
|
||||||
suffixes = [static]
|
suffixes = [static_ext]
|
||||||
|
|
||||||
# List of libraries we are searching with suffixes
|
# List of libraries we are searching with suffixes
|
||||||
libraries = ["{0}.{1}".format(lib, suffix) for lib in libraries for suffix in suffixes]
|
libraries = ["{0}.{1}".format(lib, suffix) for lib in libraries for suffix in suffixes]
|
||||||
|
@ -72,7 +72,7 @@ def header_list():
|
|||||||
plat_shared_ext = "dll" if is_windows else "so"
|
plat_shared_ext = "dll" if is_windows else "so"
|
||||||
|
|
||||||
|
|
||||||
plat_apple_shared_ext = "dll" if is_windows else "dylib"
|
plat_apple_shared_ext = "dylib"
|
||||||
|
|
||||||
|
|
||||||
class TestLibraryList(object):
|
class TestLibraryList(object):
|
||||||
@ -86,7 +86,7 @@ def test_joined_and_str(self, library_list):
|
|||||||
expected = " ".join(
|
expected = " ".join(
|
||||||
[
|
[
|
||||||
"/dir1/liblapack.%s" % plat_static_ext,
|
"/dir1/liblapack.%s" % plat_static_ext,
|
||||||
"/dir2/libpython3.6.%s" % plat_apple_shared_ext,
|
"/dir2/libpython3.6.%s" % (plat_apple_shared_ext if not is_windows else "dll"),
|
||||||
"/dir1/libblas.%s" % plat_static_ext,
|
"/dir1/libblas.%s" % plat_static_ext,
|
||||||
"/dir3/libz.%s" % plat_shared_ext,
|
"/dir3/libz.%s" % plat_shared_ext,
|
||||||
"libmpi.%s.20.10.1" % plat_shared_ext,
|
"libmpi.%s.20.10.1" % plat_shared_ext,
|
||||||
@ -101,7 +101,7 @@ def test_joined_and_str(self, library_list):
|
|||||||
expected = ";".join(
|
expected = ";".join(
|
||||||
[
|
[
|
||||||
"/dir1/liblapack.%s" % plat_static_ext,
|
"/dir1/liblapack.%s" % plat_static_ext,
|
||||||
"/dir2/libpython3.6.%s" % plat_apple_shared_ext,
|
"/dir2/libpython3.6.%s" % (plat_apple_shared_ext if not is_windows else "dll"),
|
||||||
"/dir1/libblas.%s" % plat_static_ext,
|
"/dir1/libblas.%s" % plat_static_ext,
|
||||||
"/dir3/libz.%s" % plat_shared_ext,
|
"/dir3/libz.%s" % plat_shared_ext,
|
||||||
"libmpi.%s.20.10.1" % plat_shared_ext,
|
"libmpi.%s.20.10.1" % plat_shared_ext,
|
||||||
@ -254,6 +254,29 @@ def test_add(self, header_list):
|
|||||||
search_dir = os.path.join(spack.paths.test_path, "data", "directory_search")
|
search_dir = os.path.join(spack.paths.test_path, "data", "directory_search")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"lib_list,kwargs",
|
||||||
|
[
|
||||||
|
(["liba"], {"shared": True, "recursive": True}),
|
||||||
|
(["liba"], {"shared": False, "recursive": True}),
|
||||||
|
(["libc", "liba"], {"shared": True, "recursive": True}),
|
||||||
|
(["liba", "libc"], {"shared": False, "recursive": True}),
|
||||||
|
(["libc", "libb", "liba"], {"shared": True, "recursive": True}),
|
||||||
|
(["liba", "libb", "libc"], {"shared": False, "recursive": True}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_library_type_search(lib_list, kwargs):
|
||||||
|
results = find_libraries(lib_list, search_dir, **kwargs)
|
||||||
|
assert len(results) != 0
|
||||||
|
for result in results:
|
||||||
|
lib_type_ext = plat_shared_ext
|
||||||
|
if not kwargs["shared"]:
|
||||||
|
lib_type_ext = plat_static_ext
|
||||||
|
assert result.endswith(lib_type_ext) or (
|
||||||
|
kwargs["shared"] and result.endswith(plat_apple_shared_ext)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"search_fn,search_list,root,kwargs",
|
"search_fn,search_list,root,kwargs",
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user