6262from easybuild .tools .build_log import EasyBuildError , dry_run_msg , print_warning
6363from easybuild .tools .config import build_option , install_path
6464from easybuild .tools .environment import setvar
65- from easybuild .tools .filetools import adjust_permissions , find_eb_script , read_file , which , write_file
65+ from easybuild .tools .filetools import adjust_permissions , copy_file , find_eb_script , mkdir , read_file , which , write_file
6666from easybuild .tools .module_generator import dependencies_for
6767from easybuild .tools .modules import get_software_root , get_software_root_env_var_name
6868from easybuild .tools .modules import get_software_version , get_software_version_env_var_name
@@ -985,6 +985,8 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None
985985 Put RPATH wrapper script in place for compiler and linker commands
986986
987987 :param rpath_filter_dirs: extra directories to include in RPATH filter (e.g. build dir, tmpdir, ...)
988+ :param rpath_include_dirs: extra directories to include in RPATH
989+ :param rpath_wrappers_dir: directory in which to create RPATH wrappers (tmpdir is created if None)
988990 """
989991 if get_os_type () == LINUX :
990992 self .log .info ("Putting RPATH wrappers in place..." )
@@ -994,6 +996,11 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None
994996 if rpath_filter_dirs is None :
995997 rpath_filter_dirs = []
996998
999+ # only enable logging by RPATH wrapper scripts in debug mode
1000+ enable_wrapper_log = build_option ('debug' )
1001+
1002+ copy_rpath_args_py = False
1003+
9971004 # always include filter for 'stubs' library directory,
9981005 # cfr. https://github.com/easybuilders/easybuild-framework/issues/2683
9991006 # (since CUDA 11.something the stubs are in $EBROOTCUDA/stubs/lib64)
@@ -1002,19 +1009,35 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None
10021009 if lib_stubs_pattern not in rpath_filter_dirs :
10031010 rpath_filter_dirs .append (lib_stubs_pattern )
10041011
1005- # directory where all wrappers will be placed
1006- disable_wrapper_log = False
1012+ # directory where all RPATH wrapper script will be placed;
10071013 if rpath_wrappers_dir is None :
1008- wrappers_dir = os . path . join ( tempfile .mkdtemp (), RPATH_WRAPPERS_SUBDIR )
1014+ wrappers_dir = tempfile .mkdtemp ()
10091015 else :
1010- wrappers_dir = os .path .join (rpath_wrappers_dir , RPATH_WRAPPERS_SUBDIR )
1011- # No logging when we may be exporting wrappers
1012- disable_wrapper_log = True
1016+ wrappers_dir = rpath_wrappers_dir
1017+ # disable logging in RPATH wrapper scripts when they may be exported for use outside of EasyBuild
1018+ enable_wrapper_log = False
1019+ # copy rpath_args.py script to sit alongside RPATH wrapper scripts
1020+ copy_rpath_args_py = True
1021+
1022+ # it's important to honor RPATH_WRAPPERS_SUBDIR, see is_rpath_wrapper method
1023+ wrappers_dir = os .path .join (wrappers_dir , RPATH_WRAPPERS_SUBDIR )
1024+ mkdir (wrappers_dir , parents = True )
10131025
10141026 # must also wrap compilers commands, required e.g. for Clang ('gcc' on OS X)?
10151027 c_comps , fortran_comps = self .compilers ()
10161028
10171029 rpath_args_py = find_eb_script ('rpath_args.py' )
1030+
1031+ # copy rpath_args.py script along RPATH wrappers, if desired
1032+ if copy_rpath_args_py :
1033+ copy_file (rpath_args_py , wrappers_dir )
1034+ # use path for %(rpath_args)s template value relative to location of the RPATH wrapper script,
1035+ # to avoid that the RPATH wrapper scripts rely on a script that's located elsewhere;
1036+ # that's mostly important when RPATH wrapper scripts are retained to be used outside of EasyBuild;
1037+ # we assume that each RPATH wrapper script is created in a separate subdirectory (see wrapper_dir below);
1038+ # ${TOPDIR} is defined in template for RPATH wrapper scripts, refers to parent dir of RPATH wrapper script
1039+ rpath_args_py = os .path .join ('${TOPDIR}' , '..' , os .path .basename (rpath_args_py ))
1040+
10181041 rpath_wrapper_template = find_eb_script ('rpath_wrapper_template.sh.in' )
10191042
10201043 # figure out list of patterns to use in rpath filter
@@ -1056,8 +1079,8 @@ def prepare_rpath_wrappers(self, rpath_filter_dirs=None, rpath_include_dirs=None
10561079 raise EasyBuildError ("Refusing to create a fork bomb, which(%s) == %s" , cmd , orig_cmd )
10571080
10581081 # enable debug mode in wrapper script by specifying location for log file
1059- if build_option ( 'debug' ) and not disable_wrapper_log :
1060- rpath_wrapper_log = os .path .join (tempfile .gettempdir (), 'rpath_wrapper_%s .log' % cmd )
1082+ if enable_wrapper_log :
1083+ rpath_wrapper_log = os .path .join (tempfile .gettempdir (), f 'rpath_wrapper_{ cmd } .log' )
10611084 else :
10621085 rpath_wrapper_log = '/dev/null'
10631086
0 commit comments