diff --git a/easybuild/tools/toolchain/utilities.py b/easybuild/tools/toolchain/utilities.py index 0dceb36b5a..ce4314b4db 100644 --- a/easybuild/tools/toolchain/utilities.py +++ b/easybuild/tools/toolchain/utilities.py @@ -36,13 +36,15 @@ * Kenneth Hoste (Ghent University) """ import copy +import os import re import sys import easybuild.tools.toolchain from easybuild.base import fancylogger from easybuild.tools.build_log import EasyBuildError -from easybuild.tools.toolchain.toolchain import Toolchain +from easybuild.tools.environment import setvar +from easybuild.tools.toolchain.toolchain import Toolchain, RPATH_WRAPPERS_SUBDIR from easybuild.tools.utilities import get_subclasses, import_available_modules, nub @@ -157,6 +159,11 @@ def export_rpath_wrappers(targetdir, toolchain_name, toolchain_version, rpath_fi rpath_include_dirs=None): tc = get_toolchain({'name': toolchain_name, 'version': toolchain_version}, {}) + # Temporarily filter any existing RPATH wrappers from the PATH + orig_paths = os.getenv('PATH') + filtered_paths = [path for path in orig_paths.split(':') if RPATH_WRAPPERS_SUBDIR not in path] + setvar('PATH', ':'.join(filtered_paths)) + tc.prepare_rpath_wrappers( rpath_filter_dirs=rpath_filter_dirs, rpath_include_dirs=rpath_include_dirs, @@ -165,3 +172,6 @@ def export_rpath_wrappers(targetdir, toolchain_name, toolchain_version, rpath_fi disable_wrapper_log=True, ) _log.debug("Installed RPATH wrappers in command specific subdirectories of %s" % (str(targetdir))) + + # Restore the PATH + setvar('PATH', orig_paths) diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index 18c5b6882d..8c34bf39e3 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -2939,6 +2939,9 @@ def test_export_rpath(self): # enable --rpath for a toolchain so we test against it init_config(build_options={'rpath': True, 'silent': True}) tc = self.get_toolchain('gompi', version='2018a') + tc.set_options({'rpath': True}) + # allow the underlying toolchain to be in a prepared state (which may include rpath wrapping) + tc.prepare() # export the wrappers to a target location target_wrapper_dir = os.path.join(self.test_prefix, 'target')