summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn W. Parent <45471568+johnwparent@users.noreply.github.com>2022-09-14 16:45:42 -0400
committerGitHub <noreply@github.com>2022-09-14 14:45:42 -0600
commitdeca34676ff7ea272bb299589b5ae4b499999b32 (patch)
tree47cf678871c34db5c3343c7f358fbb33dba5dfbb /lib
parent7971985a06fd5d712406539389ffeff07cbeaec4 (diff)
downloadspack-deca34676ff7ea272bb299589b5ae4b499999b32.tar.gz
spack-deca34676ff7ea272bb299589b5ae4b499999b32.tar.bz2
spack-deca34676ff7ea272bb299589b5ae4b499999b32.tar.xz
spack-deca34676ff7ea272bb299589b5ae4b499999b32.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py12
-rw-r--r--lib/spack/spack/test/llnl/util/file_list.py29
2 files changed, 32 insertions, 9 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index a161a64d2a..a5da826217 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -2055,22 +2055,22 @@ def find_libraries(libraries, root, shared=True, recursive=False):
raise TypeError(message)
if is_windows:
- static = "lib"
- shared = "dll"
+ static_ext = "lib"
+ shared_ext = "dll"
else:
# Used on both Linux and macOS
- static = "a"
- shared = "so"
+ static_ext = "a"
+ shared_ext = "so"
# Construct the right suffix for the library
if shared:
# Used on both Linux and macOS
- suffixes = [shared]
+ suffixes = [shared_ext]
if sys.platform == "darwin":
# Only used on macOS
suffixes.append("dylib")
else:
- suffixes = [static]
+ suffixes = [static_ext]
# List of libraries we are searching with suffixes
libraries = ["{0}.{1}".format(lib, suffix) for lib in libraries for suffix in suffixes]
diff --git a/lib/spack/spack/test/llnl/util/file_list.py b/lib/spack/spack/test/llnl/util/file_list.py
index 0fe7572406..a6a7ef3fa9 100644
--- a/lib/spack/spack/test/llnl/util/file_list.py
+++ b/lib/spack/spack/test/llnl/util/file_list.py
@@ -72,7 +72,7 @@ plat_static_ext = "lib" if is_windows else "a"
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):
@@ -86,7 +86,7 @@ class TestLibraryList(object):
expected = " ".join(
[
"/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,
"/dir3/libz.%s" % plat_shared_ext,
"libmpi.%s.20.10.1" % plat_shared_ext,
@@ -101,7 +101,7 @@ class TestLibraryList(object):
expected = ";".join(
[
"/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,
"/dir3/libz.%s" % plat_shared_ext,
"libmpi.%s.20.10.1" % plat_shared_ext,
@@ -255,6 +255,29 @@ 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(
"search_fn,search_list,root,kwargs",
[
(find_libraries, "liba", search_dir, {"recursive": True}),