Skip to content

Commit

Permalink
LibraryList : deduplicates on __add__
Browse files Browse the repository at this point in the history
  • Loading branch information
alalazo committed Sep 2, 2016
1 parent da3db65 commit fce956b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
32 changes: 3 additions & 29 deletions lib/spack/llnl/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from contextlib import contextmanager

import llnl.util.tty as tty
from llnl.util.lang import dedupe, memoized
from llnl.util.lang import dedupe

__all__ = ['set_install_permissions', 'install', 'install_tree',
'traverse_tree',
Expand All @@ -47,8 +47,7 @@
'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink',
'set_executable', 'copy_mode', 'unset_executable_mode',
'remove_dead_links', 'remove_linked_tree', 'find_library_path',
'fix_darwin_install_name', 'to_link_flags', 'to_lib_name',
'find_libraries', 'LibraryList']
'fix_darwin_install_name', 'find_libraries', 'LibraryList']


def filter_file(regex, repl, *filenames, **kwargs):
Expand Down Expand Up @@ -445,31 +444,6 @@ def fix_darwin_install_name(path):
stdout=subprocess.PIPE).communicate()[0]
break

# FIXME : remove


def to_lib_name(library):
"""Transforms a path to the library /path/to/lib<name>.xyz into <name>
"""
# Assume libXYZ.suffix
return os.path.basename(library)[3:].split(".")[0]

# FIXME : remove


def to_link_flags(library):
"""Transforms a path to a <library> into linking flags -L<dir> -l<name>.
Return:
A string of linking flags.
"""
dir = os.path.dirname(library)
name = to_lib_name(library)
res = '-L%s -l%s' % (dir, name)
return res

# TODO : Check if it used anywhere else ...


def find_library_path(libname, *paths):
"""Searches for a file called <libname> in each path.
Expand Down Expand Up @@ -556,7 +530,7 @@ def __getitem__(self, item):
return cls(self.libraries[item])

def __add__(self, other):
return LibraryList(self.libraries + list(other))
return LibraryList(dedupe(self.libraries + list(other)))

def __eq__(self, other):
return self.libraries == other.libraries
Expand Down
11 changes: 10 additions & 1 deletion lib/spack/spack/test/library_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_flags(self):
self.assertTrue('-L/dir1' in search_flags)
self.assertTrue('-L/dir2' in search_flags)
self.assertTrue('-L/dir3' in search_flags)
self.assertIsInstance(search_flags, str)
self.assertTrue(isinstance(search_flags, str))

link_flags = self.liblist.link_flags
self.assertEqual(
Expand All @@ -88,3 +88,12 @@ def test_get_item(self):
self.assertEqual(type(b), type(self.liblist))
self.assertEqual(self.liblist, b)
self.assertTrue(self.liblist is not b)

def test_add(self):
another = LibraryList([
'/dir1/liblapack.a', # removed from the final list
'/dir2/libbaz.so',
'/dir4/libnew.a'
])
l = self.liblist + another
self.assertEqual(len(l), 7)
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def setup_dependent_package(self, module, dspec):
# different interface and threading layers.

name = 'libmkl_rt.%s' % dso_suffix
# FIXME : change the logic here
libdir = find_library_path(name, self.prefix.lib64, self.prefix.lib)

self.spec.blas_shared_lib = join_path(libdir, name)
Expand Down
1 change: 1 addition & 0 deletions var/spack/repos/builtin/packages/mkl/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def setup_dependent_package(self, module, dspec):
# different interface and threading layers.

name = 'libmkl_rt.%s' % dso_suffix
# FIXME : change the logic here
libdir = find_library_path(name, self.prefix.lib64, self.prefix.lib)

# Now set blas/lapack libs:
Expand Down

0 comments on commit fce956b

Please sign in to comment.