Skip to content

Commit

Permalink
rework LibSymlink to make it less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Dec 7, 2024
1 parent a514a42 commit 7f96240
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@


class LibSymlink(Enum):
"""Possible states for symlinking of library directories"""
NONE, LIB, LIB64, NEITHER = range(0, 4)
"""
Possible states for symlinking of lib/lib64 subdirectories:
- UNKNOWN: has not been determined yet
- LIB_TO_LIB64: 'lib' is a symlink to 'lib64'
- LIB64_TO_LIB: 'lib64' is a symlink to 'lib'
- NEITHER: neither 'lib' is a symlink to 'lib64', nor 'lib64 is a symlink to 'lib'
- """
UNKNOWN, LIB_TO_LIB64, LIB64_TO_LIB, NEITHER = range(0, 4)


class EasyBlock(object):
Expand Down Expand Up @@ -216,7 +222,7 @@ def __init__(self, ec):
self.install_subdir = None

# track status of symlink between library directories
self.install_lib_symlink = LibSymlink.NONE
self.install_lib_symlink = LibSymlink.UNKNOWN

# indicates whether build should be performed in installation dir
self.build_in_installdir = self.cfg['buildininstalldir']
Expand Down Expand Up @@ -1682,7 +1688,7 @@ def expand_module_search_path(self, search_path, top_level, fake=False):
exp_search_paths = [abs_glob] if search_path == "" else glob.glob(abs_glob)

# Explicitly check symlink state between lib dirs if it is still undefined (e.g. --module-only)
if self.install_lib_symlink == LibSymlink.NONE:
if self.install_lib_symlink == LibSymlink.UNKNOWN:
self.check_install_lib_symlink()

retained_search_paths = []
Expand All @@ -1693,10 +1699,10 @@ def expand_module_search_path(self, search_path, top_level, fake=False):

# avoid duplicate entries between symlinked library dirs
tentative_sep = tentative_path + os.path.sep
if self.install_lib_symlink == LibSymlink.LIB64 and tentative_sep.startswith("lib64" + os.path.sep):
if self.install_lib_symlink == LibSymlink.LIB64_TO_LIB and tentative_sep.startswith('lib64' + os.path.sep):
self.log.debug("Discarded search path to symlinked lib64 directory: %s", tentative_path)
break
if self.install_lib_symlink == LibSymlink.LIB and tentative_sep.startswith("lib" + os.path.sep):
if self.install_lib_symlink == LibSymlink.LIB_TO_LIB64 and tentative_sep.startswith('lib' + os.path.sep):
self.log.debug("Discarded search path to symlinked lib directory: %s", tentative_path)
break

Expand All @@ -1716,9 +1722,9 @@ def check_install_lib_symlink(self):
if os.path.exists(lib_dir) and os.path.exists(lib64_dir):
self.install_lib_symlink = LibSymlink.NEITHER
if os.path.islink(lib_dir) and os.path.samefile(lib_dir, lib64_dir):
self.install_lib_symlink = LibSymlink.LIB
self.install_lib_symlink = LibSymlink.LIB_TO_LIB64
elif os.path.islink(lib64_dir) and os.path.samefile(lib_dir, lib64_dir):
self.install_lib_symlink = LibSymlink.LIB64
self.install_lib_symlink = LibSymlink.LIB64_TO_LIB

def make_module_req_guess(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import easybuild.tools.systemtools as st
from easybuild.base import fancylogger
from easybuild.framework.easyblock import LibSymlink, EasyBlock, get_easyblock_instance
from easybuild.framework.easyblock import EasyBlock, LibSymlink, get_easyblock_instance
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.framework.easyconfig.tools import avail_easyblocks, process_easyconfig
Expand Down Expand Up @@ -503,7 +503,7 @@ def test_make_module_req(self):
write_file(os.path.join(eb.installdir, 'lib', 'libfoo.so'), 'test')
shutil.rmtree(os.path.join(eb.installdir, 'lib64'))
os.symlink('lib', os.path.join(eb.installdir, 'lib64'))
eb.install_lib_symlink = LibSymlink.LIB64
eb.install_lib_symlink = LibSymlink.LIB64_TO_LIB
with eb.module_generator.start_module_creation():
guess = eb.make_module_req()
if get_module_syntax() == 'Tcl':
Expand Down

0 comments on commit 7f96240

Please sign in to comment.