Skip to content

Commit 6bc0094

Browse files
authored
Merge pull request #4761 from lexming/fix-lib-dual-symlink
add BOTH_TO_DIR state to LibSymlink
2 parents cde21cb + ad73222 commit 6bc0094

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

easybuild/framework/easyblock.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ class LibSymlink(Enum):
133133
- LIB_TO_LIB64: 'lib' is a symlink to 'lib64'
134134
- LIB64_TO_LIB: 'lib64' is a symlink to 'lib'
135135
- NEITHER: neither 'lib' is a symlink to 'lib64', nor 'lib64' is a symlink to 'lib'
136+
- BOTH_TO_DIR: 'lib' and 'lib64' are symlinks to some other directory
136137
- """
137-
LIB_TO_LIB64, LIB64_TO_LIB, NEITHER = range(3)
138+
LIB_TO_LIB64, LIB64_TO_LIB, NEITHER, BOTH_TO_DIR = range(4)
138139

139140

140141
class EasyBlock(object):
@@ -1760,7 +1761,9 @@ def check_install_lib_symlink(self):
17601761

17611762
self._install_lib_symlink = LibSymlink.NEITHER
17621763
if os.path.exists(lib_dir) and os.path.exists(lib64_dir):
1763-
if os.path.islink(lib_dir) and os.path.samefile(lib_dir, lib64_dir):
1764+
if os.path.islink(lib_dir) and os.path.islink(lib64_dir):
1765+
self._install_lib_symlink = LibSymlink.BOTH_TO_DIR
1766+
elif os.path.islink(lib_dir) and os.path.samefile(lib_dir, lib64_dir):
17641767
self._install_lib_symlink = LibSymlink.LIB_TO_LIB64
17651768
elif os.path.islink(lib64_dir) and os.path.samefile(lib_dir, lib64_dir):
17661769
self._install_lib_symlink = LibSymlink.LIB64_TO_LIB

test/framework/easyblock.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from easybuild.tools.config import get_module_syntax, update_build_option
5353
from easybuild.tools.environment import modify_env
5454
from easybuild.tools.filetools import change_dir, copy_dir, copy_file, mkdir, read_file, remove_dir, remove_file
55-
from easybuild.tools.filetools import verify_checksum, write_file
55+
from easybuild.tools.filetools import symlink, verify_checksum, write_file
5656
from easybuild.tools.module_generator import module_generator
5757
from easybuild.tools.modules import EnvironmentModules, Lmod, ModEnvVarType, reset_module_caches
5858
from easybuild.tools.version import get_git_revision, this_is_easybuild
@@ -627,6 +627,43 @@ def test_make_module_req(self):
627627
logtxt = read_file(eb.logfile)
628628
self.assertTrue(re.search(r"WARNING Non-path variables found in module load env.*NONPATH", logtxt, re.M))
629629

630+
delattr(eb.module_load_environment, 'NONPATH')
631+
632+
# make sure that entries that symlink to another directory are retained;
633+
# the test case inspired by the directory structure for old imkl versions (like 2020.4)
634+
remove_dir(eb.installdir)
635+
636+
# lib/ symlinked to libraries/
637+
real_libdir = os.path.join(eb.installdir, 'libraries')
638+
mkdir(real_libdir, parents=True)
639+
symlink(real_libdir, os.path.join(eb.installdir, 'lib'))
640+
641+
# lib/intel64/ symlinked to lib/intel64_lin/
642+
mkdir(os.path.join(eb.installdir, 'lib', 'intel64_lin'), parents=True)
643+
symlink(os.path.join(eb.installdir, 'lib', 'intel64_lin'), os.path.join(eb.installdir, 'lib', 'intel64'))
644+
645+
# library file present in lib/intel64
646+
write_file(os.path.join(eb.installdir, 'lib', 'intel64', 'libfoo.so'), 'libfoo.so')
647+
648+
# lib64/ symlinked to lib/
649+
symlink(os.path.join(eb.installdir, 'lib'), os.path.join(eb.installdir, 'lib64'))
650+
651+
eb.module_load_environment.LD_LIBRARY_PATH = [os.path.join('lib', 'intel64')]
652+
eb.module_load_environment.LIBRARY_PATH = eb.module_load_environment.LD_LIBRARY_PATH
653+
with eb.module_generator.start_module_creation():
654+
txt = eb.make_module_req()
655+
656+
if get_module_syntax() == 'Tcl':
657+
self.assertTrue(re.search(r"^prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/intel64$", txt, re.M))
658+
self.assertTrue(re.search(r"^prepend-path\s+LIBRARY_PATH\s+\$root/lib/intel64\n$", txt, re.M))
659+
elif get_module_syntax() == 'Lua':
660+
self.assertTrue(re.search(r'^prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/intel64"\)\)$',
661+
txt, re.M))
662+
self.assertTrue(re.search(r'^prepend_path\("LIBRARY_PATH", pathJoin\(root, "lib/intel64"\)\)$',
663+
txt, re.M))
664+
else:
665+
self.fail("Unknown module syntax: %s" % get_module_syntax())
666+
630667
# cleanup
631668
eb.close_log()
632669
os.remove(eb.logfile)
@@ -3312,6 +3349,25 @@ def test_expand_module_search_path(self):
33123349
self.assertEqual(test_emsp("lib*", ModEnvVarType.PATH_WITH_FILES), ["lib64"])
33133350
self.assertEqual(test_emsp("lib*", ModEnvVarType.PATH_WITH_TOP_FILES), ["lib64"])
33143351

3352+
# test both lib and lib64 symlinked to some other folder
3353+
remove_dir(os.path.join(eb.installdir, "lib64"))
3354+
remove_file(os.path.join(eb.installdir, "lib"))
3355+
os.mkdir(os.path.join(eb.installdir, "random_lib_dir"))
3356+
write_file(os.path.join(eb.installdir, "random_lib_dir", "libtest.so"), "not actually a lib")
3357+
os.symlink("random_lib_dir", os.path.join(eb.installdir, "lib"))
3358+
os.symlink("random_lib_dir", os.path.join(eb.installdir, "lib64"))
3359+
eb.check_install_lib_symlink()
3360+
self.assertEqual(eb.install_lib_symlink, LibSymlink.BOTH_TO_DIR)
3361+
self.assertEqual(test_emsp("lib", ModEnvVarType.PATH), ["lib"])
3362+
self.assertEqual(test_emsp("lib", ModEnvVarType.PATH_WITH_FILES), ["lib"])
3363+
self.assertEqual(test_emsp("lib", ModEnvVarType.PATH_WITH_TOP_FILES), ["lib"])
3364+
self.assertEqual(test_emsp("lib64", ModEnvVarType.PATH), ["lib64"])
3365+
self.assertEqual(test_emsp("lib64", ModEnvVarType.PATH_WITH_FILES), ["lib64"])
3366+
self.assertEqual(test_emsp("lib64", ModEnvVarType.PATH_WITH_TOP_FILES), ["lib64"])
3367+
self.assertEqual(sorted(test_emsp("lib*", ModEnvVarType.PATH)), ["lib", "lib64"])
3368+
self.assertEqual(sorted(test_emsp("lib*", ModEnvVarType.PATH_WITH_FILES)), ["lib", "lib64"])
3369+
self.assertEqual(sorted(test_emsp("lib*", ModEnvVarType.PATH_WITH_TOP_FILES)), ["lib", "lib64"])
3370+
33153371

33163372
def suite():
33173373
""" return all the tests in this file """

0 commit comments

Comments
 (0)