From deca34676ff7ea272bb299589b5ae4b499999b32 Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:45:42 -0400 Subject: 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. --- lib/spack/llnl/util/filesystem.py | 12 ++++++------ lib/spack/spack/test/llnl/util/file_list.py | 29 ++++++++++++++++++++++++++--- 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, @@ -254,6 +254,29 @@ class TestHeaderList(object): 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", [ -- cgit v1.2.3-70-g09d2