Module path parsing: CRAY_LD_LIBRARY_PATH and PACKAGE_DIR (#9374)

Fix two bugs with module file parsing:

* Detection of the CRAY_LD_LIBRARY_PATH variable was broken by #9100.
  This fixes it and adds a test for it.
* For module names like "foo-bar/1.0", the associated PACKAGE_DIR
  environment variable name would be "FOO_BAR_DIR", but Spack was not
  parsing the components and not converting "-" to "_"
This commit is contained in:
Peter Scheibel 2018-09-27 19:40:22 -07:00 committed by GitHub
parent 1e75aef0e9
commit 28f6a4a095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -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 @@ def test_get_path_from_module_contents():
'/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',

View File

@ -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)