summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/module_parsing.py14
-rw-r--r--lib/spack/spack/util/module_cmd.py13
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/spack/spack/test/module_parsing.py b/lib/spack/spack/test/module_parsing.py
index f798c272b8..f1cea356b5 100644
--- a/lib/spack/spack/test/module_parsing.py
+++ b/lib/spack/spack/test/module_parsing.py
@@ -58,6 +58,7 @@ def save_env():
def test_get_path_from_module(save_env):
lines = ['prepend-path LD_LIBRARY_PATH /path/to/lib',
+ 'prepend-path CRAY_LD_LIBRARY_PATH /path/to/lib',
'setenv MOD_DIR /path/to',
'setenv LDFLAGS -Wl,-rpath/path/to/lib',
'setenv LDFLAGS -L/path/to/lib',
@@ -67,7 +68,6 @@ def test_get_path_from_module(save_env):
module_func = '() { eval `echo ' + line + ' bash filler`\n}'
os.environ['BASH_FUNC_module()'] = module_func
path = get_path_from_module('mod')
-
assert path == '/path/to'
os.environ['BASH_FUNC_module()'] = '() { eval $(echo fill bash $*)\n}'
@@ -77,6 +77,8 @@ def test_get_path_from_module(save_env):
def test_get_path_from_module_contents():
+ # A line with "MODULEPATH" appears early on, and the test confirms that it
+ # is not extracted as the package's path
module_show_output = """
os.environ["MODULEPATH"] = "/path/to/modules1:/path/to/modules2";
----------------------------------------------------------------------------
@@ -96,6 +98,16 @@ prepend_path("MANPATH","/path/to/cmake/cmake-3.9.2/share/man")
'/path/to/cmake-3.9.2')
+def test_pkg_dir_from_module_name():
+ module_show_lines = ['setenv FOO_BAR_DIR /path/to/foo-bar']
+
+ assert (get_path_from_module_contents(module_show_lines, 'foo-bar') ==
+ '/path/to/foo-bar')
+
+ assert (get_path_from_module_contents(module_show_lines, 'foo-bar/1.0') ==
+ '/path/to/foo-bar')
+
+
def test_get_argument_from_module_line():
lines = ['prepend-path LD_LIBRARY_PATH /lib/path',
'prepend-path LD_LIBRARY_PATH /lib/path',
diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py
index d3e258792a..8b268b9848 100644
--- a/lib/spack/spack/util/module_cmd.py
+++ b/lib/spack/spack/util/module_cmd.py
@@ -185,16 +185,25 @@ def get_path_from_module(mod):
def get_path_from_module_contents(text, module_name):
+ tty.debug("Module name: " + module_name)
+ pkg_var_prefix = module_name.replace('-', '_').upper()
+ components = pkg_var_prefix.split('/')
+ # For modules with multiple components like foo/1.0.1, retrieve the package
+ # name "foo" from the module name
+ if len(components) > 1:
+ pkg_var_prefix = components[-2]
+ tty.debug("Package directory variable prefix: " + pkg_var_prefix)
+
# If it sets the LD_LIBRARY_PATH or CRAY_LD_LIBRARY_PATH, use that
for line in text:
- pattern = r'\WLD_LIBRARY_PATH'
+ pattern = r'\W(CRAY_)?LD_LIBRARY_PATH'
if re.search(pattern, line):
path = get_path_arg_from_module_line(line)
return path[:path.find('/lib')]
# If it lists its package directory, return that
for line in text:
- pattern = r'\W{0}_DIR'.format(module_name.upper())
+ pattern = r'\W{0}_DIR'.format(pkg_var_prefix)
if re.search(pattern, line):
return get_path_arg_from_module_line(line)