|
55 | 55 | from easybuild.tools.systemtools import get_shared_lib_ext |
56 | 56 | from easybuild.tools.toolchain.mpi import get_mpi_cmd_template |
57 | 57 | from easybuild.tools.toolchain.toolchain import env_vars_external_module |
58 | | -from easybuild.tools.toolchain.utilities import get_toolchain, search_toolchain |
| 58 | +from easybuild.tools.toolchain.utilities import get_toolchain, search_toolchain, export_rpath_wrappers |
59 | 59 | from easybuild.toolchains.compiler.clang import Clang |
60 | 60 |
|
61 | 61 | easybuild.tools.toolchain.compiler.systemtools.get_compiler_family = lambda: st.POWER |
@@ -3137,6 +3137,62 @@ def test_toolchain_prepare_rpath(self): |
3137 | 3137 | self.assertTrue(os.path.samefile(res[1], fake_gxx)) |
3138 | 3138 | self.assertFalse(any(os.path.samefile(x, fake_gxx) for x in res[2:])) |
3139 | 3139 |
|
| 3140 | + def test_export_rpath(self): |
| 3141 | + """Test tools.toolchain.export_rpath_wrappers()""" |
| 3142 | + |
| 3143 | + # put fake 'g++' command in place that just echos its arguments |
| 3144 | + fake_gxx = os.path.join(self.test_prefix, 'fake', 'g++') |
| 3145 | + write_file(fake_gxx, '#!/bin/bash\necho "$@"') |
| 3146 | + adjust_permissions(fake_gxx, stat.S_IXUSR) |
| 3147 | + os.environ['PATH'] = '%s:%s' % (os.path.join(self.test_prefix, 'fake'), os.getenv('PATH', '')) |
| 3148 | + |
| 3149 | + # enable --rpath for a toolchain so we test against it |
| 3150 | + init_config(build_options={'rpath': True, 'silent': True}) |
| 3151 | + tc = self.get_toolchain('gompi', version='2018a') |
| 3152 | + tc.set_options({'rpath': True}) |
| 3153 | + # allow the underlying toolchain to be in a prepared state (which may include rpath wrapping) |
| 3154 | + tc.prepare() |
| 3155 | + |
| 3156 | + # export the wrappers to a target location |
| 3157 | + target_wrapper_dir = os.path.join(self.test_prefix, 'target') |
| 3158 | + export_rpath_wrappers(targetdir=target_wrapper_dir, toolchain_name='gompi', toolchain_version='2018a', |
| 3159 | + rpath_filter_dirs=['/filter_path'], rpath_include_dirs=['/include_path']) |
| 3160 | + |
| 3161 | + # check that wrapper was created |
| 3162 | + target_wrapper = os.path.join(target_wrapper_dir, 'gxx_wrapper', 'g++') |
| 3163 | + self.assertTrue(os.path.exists(target_wrapper)) |
| 3164 | + # Make sure it is a wrapper |
| 3165 | + self.assertTrue(b'rpath_args.py $CMD' in read_file(target_wrapper, mode='rb')) |
| 3166 | + # Make sure it wraps our fake 'g++' |
| 3167 | + self.assertTrue(fake_gxx.encode(encoding="utf-8") in read_file(target_wrapper, mode='rb')) |
| 3168 | + # Make sure the wrapper is not in PATH (we export only) |
| 3169 | + self.assertFalse(any(os.path.samefile(x, target_wrapper) for x in which('g++', retain_all=True))) |
| 3170 | + |
| 3171 | + # check whether fake g++ was wrapped and that arguments are what they should be |
| 3172 | + # no -rpath for /path because of rpath filter |
| 3173 | + mkdir(os.path.join(self.test_prefix, 'foo'), parents=True) |
| 3174 | + cmd = ' '.join([ |
| 3175 | + target_wrapper, |
| 3176 | + '${USER}.c', |
| 3177 | + '-L%s/foo' % self.test_prefix, |
| 3178 | + '-L/filter_path', |
| 3179 | + "'$FOO'", |
| 3180 | + '-DX="\\"\\""', |
| 3181 | + ]) |
| 3182 | + res = run_shell_cmd(cmd, hidden=True) |
| 3183 | + self.assertEqual(res.exit_code, 0) |
| 3184 | + expected = ' '.join([ |
| 3185 | + '-Wl,-rpath=/include_path', |
| 3186 | + '-Wl,--disable-new-dtags', |
| 3187 | + '-Wl,-rpath=%s/foo' % self.test_prefix, |
| 3188 | + '%(user)s.c', |
| 3189 | + '-L%s/foo' % self.test_prefix, |
| 3190 | + '-L/filter_path', |
| 3191 | + '$FOO', |
| 3192 | + '-DX=""', |
| 3193 | + ]) |
| 3194 | + self.assertEqual(res.output.strip(), expected % {'user': os.getenv('USER')}) |
| 3195 | + |
3140 | 3196 | def test_prepare_openmpi_tmpdir(self): |
3141 | 3197 | """Test handling of long $TMPDIR path for OpenMPI 2.x""" |
3142 | 3198 |
|
|
0 commit comments