summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-05-20 14:35:35 +0200
committerGitHub <noreply@github.com>2021-05-20 14:35:35 +0200
commit584607902812467f9acd9ebaf372d2b3c80c8a41 (patch)
treef38c5c0dd6181717fe888c2a92beed950ca029c2
parent6d42be57395411af28afdcf3c31475eb4f1a7e2c (diff)
downloadspack-584607902812467f9acd9ebaf372d2b3c80c8a41.tar.gz
spack-584607902812467f9acd9ebaf372d2b3c80c8a41.tar.bz2
spack-584607902812467f9acd9ebaf372d2b3c80c8a41.tar.xz
spack-584607902812467f9acd9ebaf372d2b3c80c8a41.zip
Cray: fix extracting paths from module files (#23472)
Co-authored-by: Tiziano Müller <tm@dev-zero.ch>
-rw-r--r--lib/spack/spack/test/module_parsing.py6
-rw-r--r--lib/spack/spack/util/module_cmd.py10
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/spack/spack/test/module_parsing.py b/lib/spack/spack/test/module_parsing.py
index 8779deb0ac..a1d0142b92 100644
--- a/lib/spack/spack/test/module_parsing.py
+++ b/lib/spack/spack/test/module_parsing.py
@@ -123,3 +123,9 @@ def test_get_argument_from_module_line():
for bl in bad_lines:
with pytest.raises(ValueError):
get_path_args_from_module_line(bl)
+
+
+def test_lmod_quote_parsing():
+ lines = ['setenv("SOME_PARTICULAR_DIR","-L/opt/cray/pe/mpich/8.1.4/gtl/lib")']
+ result = get_path_from_module_contents(lines, 'some-module')
+ assert '/opt/cray/pe/mpich/8.1.4/gtl' == result
diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py
index 96ca98d39d..fa6996fcbd 100644
--- a/lib/spack/spack/util/module_cmd.py
+++ b/lib/spack/spack/util/module_cmd.py
@@ -195,9 +195,13 @@ def get_path_from_module_contents(text, module_name):
def match_flag_and_strip(line, flag, strip=[]):
flag_idx = line.find(flag)
if flag_idx >= 0:
- end = line.find(' ', flag_idx)
- if end >= 0:
- path = line[flag_idx + len(flag):end]
+ # Search for the first occurence of any separator marking the end of
+ # the path.
+ separators = (' ', '"', "'")
+ occurrences = [line.find(s, flag_idx) for s in separators]
+ indices = [idx for idx in occurrences if idx >= 0]
+ if indices:
+ path = line[flag_idx + len(flag):min(indices)]
else:
path = line[flag_idx + len(flag):]
path = strip_path(path, strip)