Skip to content

Commit 0e33f99

Browse files
committed
For PATH, CPATH, {LD_,}LIBRARY_PATH only add useful entries.
This avoids adding useless entries in the environment, an example being GCCcore which adds lib and include which are both empty apart from subdirectories.
1 parent 56dbe0c commit 0e33f99

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

easybuild/framework/easyblock.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,12 @@ def make_module_req(self):
13011301
# only use glob if the string is non-empty
13021302
if path and not self.dry_run:
13031303
paths = sorted(glob.glob(path))
1304+
if key in ('PATH', 'CPATH', 'LIBRARY_PATH', 'LD_LIBRARY_PATH') and len(paths) == 1:
1305+
req = paths[0]
1306+
if os.path.isdir(req):
1307+
# only add paths with regular files in there (e.g. not only directories)
1308+
if not any([os.path.isfile(os.path.join(req, f)) for f in os.listdir(req)]):
1309+
paths = []
13041310
else:
13051311
# empty string is a valid value here (i.e. to prepend the installation prefix, cfr $CUDA_HOME)
13061312
paths = [path]

test/framework/easyblock.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def test_make_module_req(self):
318318
open(os.path.join(eb.installdir, 'foo.jar'), 'w').write('foo.jar')
319319
open(os.path.join(eb.installdir, 'bla.jar'), 'w').write('bla.jar')
320320
os.mkdir(os.path.join(eb.installdir, 'bin'))
321+
os.mkdir(os.path.join(eb.installdir, 'bin', 'testdir'))
321322
os.mkdir(os.path.join(eb.installdir, 'share'))
322323
os.mkdir(os.path.join(eb.installdir, 'share', 'man'))
323324
# this is not a path that should be picked up
@@ -329,17 +330,27 @@ def test_make_module_req(self):
329330
self.assertTrue(re.search(r"^prepend-path\s+CLASSPATH\s+\$root/bla.jar$", guess, re.M))
330331
self.assertTrue(re.search(r"^prepend-path\s+CLASSPATH\s+\$root/foo.jar$", guess, re.M))
331332
self.assertTrue(re.search(r"^prepend-path\s+MANPATH\s+\$root/share/man$", guess, re.M))
332-
self.assertTrue(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
333+
self.assertFalse(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
333334
self.assertFalse(re.search(r"^prepend-path\s+CPATH\s+.*$", guess, re.M))
334335
elif get_module_syntax() == 'Lua':
335336
self.assertTrue(re.search(r'^prepend_path\("CLASSPATH", pathJoin\(root, "bla.jar"\)\)$', guess, re.M))
336337
self.assertTrue(re.search(r'^prepend_path\("CLASSPATH", pathJoin\(root, "foo.jar"\)\)$', guess, re.M))
337338
self.assertTrue(re.search(r'^prepend_path\("MANPATH", pathJoin\(root, "share/man"\)\)$', guess, re.M))
338-
self.assertTrue(re.search(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', guess, re.M))
339+
self.assertFalse(re.search(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', guess, re.M))
339340
self.assertFalse(re.search(r'^prepend_path\("CPATH", .*\)$', guess, re.M))
340341
else:
341342
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
342343

344+
# check that bin is only added to PATH if there are files in there
345+
open(os.path.join(eb.installdir, 'bin', 'test'), 'w').write('test')
346+
guess = eb.make_module_req()
347+
if get_module_syntax() == 'Tcl':
348+
self.assertTrue(re.search(r"^prepend-path\s+PATH\s+\$root/bin$", guess, re.M))
349+
elif get_module_syntax() == 'Lua':
350+
self.assertTrue(re.search(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', guess, re.M))
351+
else:
352+
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
353+
343354
# check for behavior when a string value is used as dict value by make_module_req_guesses
344355
eb.make_module_req_guess = lambda: {'PATH': 'bin'}
345356
txt = eb.make_module_req()

0 commit comments

Comments
 (0)