diff --git a/easybuild/tools/toolchain/toolchain.py b/easybuild/tools/toolchain/toolchain.py index e21bd66869..b797db481c 100644 --- a/easybuild/tools/toolchain/toolchain.py +++ b/easybuild/tools/toolchain/toolchain.py @@ -944,7 +944,8 @@ def is_rpath_wrapper(path): calls_rpath_args = b'rpath_args.py $CMD' in read_file(path, mode='rb') return in_rpath_wrappers_dir and calls_rpath_args - def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None): + def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None, new_wrapper_dir=None, + disable_wrapper_log=False, cmdDir=None): """ Put RPATH wrapper script in place for compiler and linker commands @@ -967,7 +968,12 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None rpath_filter_dirs.append(lib_stubs_pattern) # directory where all wrappers will be placed - wrappers_dir = os.path.join(tempfile.mkdtemp(), RPATH_WRAPPERS_SUBDIR) + if new_wrapper_dir is None: + wrappers_dir = os.path.join(tempfile.mkdtemp(), RPATH_WRAPPERS_SUBDIR) + else: + wrappers_dir = new_wrapper_dir + if not os.path.exists(wrappers_dir): + os.mkdir(wrappers_dir) # must also wrap compilers commands, required e.g. for Clang ('gcc' on OS X)? c_comps, fortran_comps = self.compilers() @@ -989,6 +995,15 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None # create wrappers for cmd in nub(c_comps + fortran_comps + ['ld', 'ld.gold', 'ld.bfd']): orig_cmd = which(cmd) + if cmdDir is not None and os.path.exists(cmdDir): + orig_cmd = os.path.join(cmdDir, cmd) + + # TODO: dirty hack to let module-shipped rpath wrappers point to EESSI software layer's ld + if cmdDir is not None and "ld" in cmd: + orig_cmd = which(cmd, retain_all=True) + orig_cmd = [a for a in orig_cmd if "/tmp" not in a][0] + + self.log.debug("orig_cmd: %s", orig_cmd) if orig_cmd: # bail out early if command already is a wrapped; @@ -1011,7 +1026,7 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None raise EasyBuildError("Refusing the create a fork bomb, which(%s) == %s", cmd, orig_cmd) # enable debug mode in wrapper script by specifying location for log file - if build_option('debug'): + if build_option('debug') and not disable_wrapper_log: rpath_wrapper_log = os.path.join(tempfile.gettempdir(), 'rpath_wrapper_%s.log' % cmd) else: rpath_wrapper_log = '/dev/null' @@ -1027,7 +1042,7 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None 'wrapper_dir': wrapper_dir, } write_file(cmd_wrapper, cmd_wrapper_txt) - adjust_permissions(cmd_wrapper, stat.S_IXUSR) + adjust_permissions(cmd_wrapper, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) # prepend location to this wrapper to $PATH setvar('PATH', '%s:%s' % (wrapper_dir, os.getenv('PATH'))) @@ -1036,6 +1051,8 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None else: self.log.debug("Not installing RPATH wrapper for non-existing command '%s'", cmd) + return wrappers_dir + def handle_sysroot(self): """ Extra stuff to be done when alternate system root is specified via --sysroot EasyBuild configuration option. diff --git a/easybuild/tools/toolchain/utilities.py b/easybuild/tools/toolchain/utilities.py index d9a6c02412..6119422fa9 100644 --- a/easybuild/tools/toolchain/utilities.py +++ b/easybuild/tools/toolchain/utilities.py @@ -36,6 +36,7 @@ import copy import re import sys +import os import easybuild.tools.toolchain from easybuild.base import fancylogger @@ -148,3 +149,17 @@ def get_toolchain(tc, tcopts, mns=None, tcdeps=None, modtool=None): tc_inst.set_options(tcopts) return tc_inst + + +def create_rpath_wrappers(targetdir, toolchain_name, toolchain_version, rpath_filter_dirs=None, + rpath_include_dirs=None): + tc = get_toolchain({'name': toolchain_name, 'version': toolchain_version}, {}) + + wrapperpath = tc.prepare_rpath_wrappers( + rpath_filter_dirs=rpath_filter_dirs, + rpath_include_dirs=rpath_include_dirs, + new_wrapper_dir=targetdir, + disable_wrapper_log=True, + cmdDir=os.path.join(targetdir, '..') + ) + _log.debug("Installed RPATH wrappers in %s" % (str(wrapperpath)))