summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-05-20 14:35:35 +0200
committerGreg Becker <becker33@llnl.gov>2021-09-21 16:58:41 -0700
commit7f29dd238f43a99c74a0967e5392ecc0ef69c8ab (patch)
tree5b9e9b447e4cafe8a386f4251d9324924fbaffe0
parent0f486080b38a4cc9bbe6b9fca05c181dcbe3d3ca (diff)
downloadspack-7f29dd238f43a99c74a0967e5392ecc0ef69c8ab.tar.gz
spack-7f29dd238f43a99c74a0967e5392ecc0ef69c8ab.tar.bz2
spack-7f29dd238f43a99c74a0967e5392ecc0ef69c8ab.tar.xz
spack-7f29dd238f43a99c74a0967e5392ecc0ef69c8ab.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 8dc06b058b..068b40762b 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 bc994fd4b4..18522002ce 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)