Skip to content

Commit 17ddaa4

Browse files
authored
Merge pull request #3141 from boegel/fix_get_software_libdir
get_software_libdir: take into account that lib64 could be a symlink to lib (or vice versa)
2 parents 5e84c00 + 87898e4 commit 17ddaa4

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

easybuild/tools/modules.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,9 +1430,17 @@ def get_software_libdir(name, only_one=True, fs=None):
14301430
res = []
14311431
if root:
14321432
for lib_subdir in lib_subdirs:
1433-
if os.path.exists(os.path.join(root, lib_subdir)):
1434-
if fs is None or any([os.path.exists(os.path.join(root, lib_subdir, f)) for f in fs]):
1433+
lib_dir_path = os.path.join(root, lib_subdir)
1434+
if os.path.exists(lib_dir_path):
1435+
# take into account that lib64 could be a symlink to lib (or vice versa)
1436+
# see https://github.com/easybuilders/easybuild-framework/issues/3139
1437+
if any(os.path.samefile(lib_dir_path, os.path.join(root, x)) for x in res):
1438+
_log.debug("%s is the same as one of the other paths, so skipping it", lib_dir_path)
1439+
1440+
elif fs is None or any(os.path.exists(os.path.join(lib_dir_path, f)) for f in fs):
1441+
_log.debug("Retaining library subdir '%s' (found at %s)", lib_subdir, lib_dir_path)
14351442
res.append(lib_subdir)
1443+
14361444
elif build_option('extended_dry_run'):
14371445
res.append(lib_subdir)
14381446
break

test/framework/modules.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import easybuild.tools.modules as mod
4444
from easybuild.framework.easyblock import EasyBlock
4545
from easybuild.tools.build_log import EasyBuildError
46-
from easybuild.tools.filetools import adjust_permissions, copy_file, copy_dir, mkdir, read_file, remove_file, write_file
46+
from easybuild.tools.filetools import adjust_permissions, copy_file, copy_dir, mkdir
47+
from easybuild.tools.filetools import read_file, remove_dir, remove_file, symlink, write_file
4748
from easybuild.tools.modules import EnvironmentModules, EnvironmentModulesC, EnvironmentModulesTcl, Lmod, NoModulesTool
4849
from easybuild.tools.modules import curr_module_paths, get_software_libdir, get_software_root, get_software_version
4950
from easybuild.tools.modules import invalidate_module_caches_for, modules_tool, reset_module_caches
@@ -462,7 +463,7 @@ def test_get_software_root_version_libdir(self):
462463
for (name, env_var_name) in test_cases:
463464
# mock stuff that get_software_X functions rely on
464465
root = os.path.join(tmpdir, name)
465-
os.makedirs(os.path.join(root, 'lib'))
466+
mkdir(os.path.join(root, 'lib'), parents=True)
466467
os.environ['EBROOT%s' % env_var_name] = root
467468
version = '0.0-%s' % root
468469
os.environ['EBVERSION%s' % env_var_name] = version
@@ -476,7 +477,7 @@ def test_get_software_root_version_libdir(self):
476477

477478
# check expected result of get_software_libdir with multiple lib subdirs
478479
root = os.path.join(tmpdir, name)
479-
os.makedirs(os.path.join(root, 'lib64'))
480+
mkdir(os.path.join(root, 'lib64'))
480481
os.environ['EBROOT%s' % env_var_name] = root
481482
self.assertErrorRegex(EasyBuildError, "Multiple library subdirectories found.*", get_software_libdir, name)
482483
self.assertEqual(get_software_libdir(name, only_one=False), ['lib', 'lib64'])
@@ -485,6 +486,19 @@ def test_get_software_root_version_libdir(self):
485486
open(os.path.join(root, 'lib64', 'foo'), 'w').write('foo')
486487
self.assertEqual(get_software_libdir(name, fs=['foo']), 'lib64')
487488

489+
# duplicate paths due to symlink get filtered
490+
remove_dir(os.path.join(root, 'lib64'))
491+
symlink(os.path.join(root, 'lib'), os.path.join(root, 'lib64'))
492+
self.assertEqual(get_software_libdir(name), 'lib')
493+
494+
# same goes for lib symlinked to lib64
495+
remove_file(os.path.join(root, 'lib64'))
496+
remove_dir(os.path.join(root, 'lib'))
497+
mkdir(os.path.join(root, 'lib64'))
498+
symlink(os.path.join(root, 'lib64'), os.path.join(root, 'lib'))
499+
# still returns 'lib' because that's the first subdir considered
500+
self.assertEqual(get_software_libdir(name), 'lib')
501+
488502
# clean up for previous tests
489503
os.environ.pop('EBROOT%s' % env_var_name)
490504

0 commit comments

Comments
 (0)