Skip to content

Commit 5f69825

Browse files
authored
Merge pull request #3367 from ocaisa/revert_sorting
Respect order of paths in variables such as LD_LIBRARY_PATH
2 parents d66c0e5 + 642b76b commit 5f69825

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

easybuild/framework/easyblock.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,11 +1374,11 @@ def make_module_req(self):
13741374
if self.dry_run:
13751375
self.dry_run_msg(" $%s: %s" % (key, ', '.join(reqs)))
13761376
# Don't expand globs or do any filtering below for dry run
1377-
paths = sorted(reqs)
1377+
paths = reqs
13781378
else:
13791379
# Expand globs but only if the string is non-empty
13801380
# empty string is a valid value here (i.e. to prepend the installation prefix, cfr $CUDA_HOME)
1381-
paths = sorted(sum((glob.glob(path) if path else [path] for path in reqs), [])) # sum flattens to list
1381+
paths = sum((glob.glob(path) if path else [path] for path in reqs), []) # sum flattens to list
13821382

13831383
# If lib64 is just a symlink to lib we fixup the paths to avoid duplicates
13841384
lib64_is_symlink = (all(os.path.isdir(path) for path in ['lib', 'lib64'])
@@ -1395,8 +1395,13 @@ def make_module_req(self):
13951395
if fixed_paths != paths:
13961396
self.log.info("Fixed symlink lib64 in paths for %s: %s -> %s", key, paths, fixed_paths)
13971397
paths = fixed_paths
1398-
# Use a set to remove duplicates, e.g. by having lib64 and lib which get fixed to lib and lib above
1399-
paths = sorted(set(paths))
1398+
# remove duplicate paths
1399+
# don't use 'set' here, since order in 'paths' is important!
1400+
uniq_paths = []
1401+
for path in paths:
1402+
if path not in uniq_paths:
1403+
uniq_paths.append(path)
1404+
paths = uniq_paths
14001405
if key in keys_requiring_files:
14011406
# only retain paths that contain at least one file
14021407
retained_paths = [

test/framework/easyblock.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,31 @@ def test_make_module_req(self):
421421
else:
422422
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
423423

424+
# check for correct order of prepend statements when providing a list (and that no duplicates are allowed)
425+
eb.make_module_req_guess = lambda: {'LD_LIBRARY_PATH': ['lib/pathC', 'lib/pathA', 'lib/pathB', 'lib/pathA']}
426+
for path in ['pathA', 'pathB', 'pathC']:
427+
os.mkdir(os.path.join(eb.installdir, 'lib', path))
428+
open(os.path.join(eb.installdir, 'lib', path, 'libfoo.so'), 'w').write('test')
429+
txt = eb.make_module_req()
430+
if get_module_syntax() == 'Tcl':
431+
self.assertTrue(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathC\n" +
432+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n" +
433+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n",
434+
txt, re.M))
435+
self.assertFalse(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n" +
436+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n",
437+
txt, re.M))
438+
elif get_module_syntax() == 'Lua':
439+
self.assertTrue(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathC"\)\)\n' +
440+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n' +
441+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n',
442+
txt, re.M))
443+
self.assertFalse(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n' +
444+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n',
445+
txt, re.M))
446+
else:
447+
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
448+
424449
# cleanup
425450
eb.close_log()
426451
os.remove(eb.logfile)

0 commit comments

Comments
 (0)