Skip to content

Commit 25577b3

Browse files
author
John Donners
authored
Merge pull request #1 from boegel/abs_rpath
enhance test to catch fixed bug + re-instate injection of $ORIGIN/../lib and $ORIGIN/../lib64
2 parents 2d8ed12 + eb5edab commit 25577b3

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

easybuild/framework/easyblock.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,12 +1737,14 @@ def prepare_step(self, start_dir=True):
17371737
if not self.build_in_installdir:
17381738
self.rpath_filter_dirs.append(self.builddir)
17391739

1740-
# always include self.installdir+'/lib' and self.installdir+'/lib64' and $ORIGIN
1740+
# always include '<installdir>/lib', '<installdir>/lib64', $ORIGIN, $ORIGIN/../lib and $ORIGIN/../lib64
17411741
# $ORIGIN will be resolved by the loader to be the full path to the executable or shared object
17421742
# see also https://linux.die.net/man/8/ld-linux;
1743-
self.rpath_include_dirs.append(self.installdir+'/lib')
1744-
self.rpath_include_dirs.append(self.installdir+'/lib64')
1743+
self.rpath_include_dirs.append(os.path.join(self.installdir, 'lib'))
1744+
self.rpath_include_dirs.append(os.path.join(self.installdir, 'lib64'))
17451745
self.rpath_include_dirs.append('$ORIGIN')
1746+
self.rpath_include_dirs.append('$ORIGIN/../lib')
1747+
self.rpath_include_dirs.append('$ORIGIN/../lib64')
17461748

17471749
# prepare toolchain: load toolchain module and dependencies, set up build environment
17481750
self.toolchain.prepare(self.cfg['onlytcmod'], silent=self.silent, rpath_filter_dirs=self.rpath_filter_dirs,

test/framework/toolchain.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,13 @@ def test_rpath_args_script(self):
10651065
"""Test rpath_args.py script"""
10661066
script = find_eb_script('rpath_args.py')
10671067

1068-
rpath_inc = '%(prefix)s/lib,%(prefix)s/lib64,$ORIGIN' % {'prefix': self.test_prefix}
1068+
rpath_inc = ','.join([
1069+
os.path.join(self.test_prefix, 'lib'),
1070+
os.path.join(self.test_prefix, 'lib64'),
1071+
'$ORIGIN',
1072+
'$ORIGIN/../lib',
1073+
'$ORIGIN/../lib64',
1074+
])
10691075

10701076
# simplest possible compiler command
10711077
out, ec = run_cmd("%s gcc '' '%s' -c foo.c" % (script, rpath_inc), simple=False)
@@ -1074,6 +1080,8 @@ def test_rpath_args_script(self):
10741080
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
10751081
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
10761082
"'-Wl,-rpath=$ORIGIN'",
1083+
"'-Wl,-rpath=$ORIGIN/../lib'",
1084+
"'-Wl,-rpath=$ORIGIN/../lib64'",
10771085
"'-Wl,--disable-new-dtags'",
10781086
"'-c'",
10791087
"'foo.c'",
@@ -1083,15 +1091,12 @@ def test_rpath_args_script(self):
10831091
# linker command, --enable-new-dtags should be replaced with --disable-new-dtags
10841092
out, ec = run_cmd("%s ld '' '%s' --enable-new-dtags foo.o" % (script, rpath_inc), simple=False)
10851093
self.assertEqual(ec, 0)
1086-
expected = '\n'.join([
1087-
"CMD_ARGS=('foo.o')",
1088-
"RPATH_ARGS='--disable-new-dtags -rpath=%(prefix)s/lib -rpath=%(prefix)s/lib64 -rpath=$ORIGIN'" %
1089-
{'prefix': self.test_prefix},''
1090-
])
10911094
cmd_args = [
10921095
"'-rpath=%s/lib'" % self.test_prefix,
10931096
"'-rpath=%s/lib64'" % self.test_prefix,
10941097
"'-rpath=$ORIGIN'",
1098+
"'-rpath=$ORIGIN/../lib'",
1099+
"'-rpath=$ORIGIN/../lib64'",
10951100
"'--disable-new-dtags'",
10961101
"'--disable-new-dtags'",
10971102
"'foo.o'",
@@ -1105,6 +1110,8 @@ def test_rpath_args_script(self):
11051110
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
11061111
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
11071112
"'-Wl,-rpath=$ORIGIN'",
1113+
"'-Wl,-rpath=$ORIGIN/../lib'",
1114+
"'-Wl,-rpath=$ORIGIN/../lib64'",
11081115
"'-Wl,--disable-new-dtags'",
11091116
]
11101117
self.assertEqual(out.strip(), "CMD_ARGS=(%s)" % ' '.join(cmd_args))
@@ -1116,6 +1123,8 @@ def test_rpath_args_script(self):
11161123
"'-rpath=%s/lib'" % self.test_prefix,
11171124
"'-rpath=%s/lib64'" % self.test_prefix,
11181125
"'-rpath=$ORIGIN'",
1126+
"'-rpath=$ORIGIN/../lib'",
1127+
"'-rpath=$ORIGIN/../lib64'",
11191128
"'--disable-new-dtags'",
11201129
"''",
11211130
]
@@ -1128,6 +1137,8 @@ def test_rpath_args_script(self):
11281137
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
11291138
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
11301139
"'-Wl,-rpath=$ORIGIN'",
1140+
"'-Wl,-rpath=$ORIGIN/../lib'",
1141+
"'-Wl,-rpath=$ORIGIN/../lib64'",
11311142
"'-Wl,--disable-new-dtags'",
11321143
"'-Wl,-rpath=/foo'",
11331144
"'foo.c'",
@@ -1143,6 +1154,8 @@ def test_rpath_args_script(self):
11431154
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
11441155
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
11451156
"'-Wl,-rpath=$ORIGIN'",
1157+
"'-Wl,-rpath=$ORIGIN/../lib'",
1158+
"'-Wl,-rpath=$ORIGIN/../lib64'",
11461159
"'-Wl,--disable-new-dtags'",
11471160
"'foo.c'",
11481161
"'-L../lib'",
@@ -1157,6 +1170,8 @@ def test_rpath_args_script(self):
11571170
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
11581171
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
11591172
"'-Wl,-rpath=$ORIGIN'",
1173+
"'-Wl,-rpath=$ORIGIN/../lib'",
1174+
"'-Wl,-rpath=$ORIGIN/../lib64'",
11601175
"'-Wl,--disable-new-dtags'",
11611176
"'-Wl,-rpath=/foo'",
11621177
"'foo.c'",
@@ -1172,6 +1187,8 @@ def test_rpath_args_script(self):
11721187
"'-rpath=%s/lib'" % self.test_prefix,
11731188
"'-rpath=%s/lib64'" % self.test_prefix,
11741189
"'-rpath=$ORIGIN'",
1190+
"'-rpath=$ORIGIN/../lib'",
1191+
"'-rpath=$ORIGIN/../lib64'",
11751192
"'--disable-new-dtags'",
11761193
"'-rpath=/foo'",
11771194
"'-rpath=/lib64'",
@@ -1194,6 +1211,8 @@ def test_rpath_args_script(self):
11941211
"'-rpath=%s/lib'" % self.test_prefix,
11951212
"'-rpath=%s/lib64'" % self.test_prefix,
11961213
"'-rpath=$ORIGIN'",
1214+
"'-rpath=$ORIGIN/../lib'",
1215+
"'-rpath=$ORIGIN/../lib64'",
11971216
"'--disable-new-dtags'",
11981217
"'-rpath=/lib64'",
11991218
"'-L/foo'",
@@ -1228,6 +1247,8 @@ def test_rpath_args_script(self):
12281247
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
12291248
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
12301249
"'-Wl,-rpath=$ORIGIN'",
1250+
"'-Wl,-rpath=$ORIGIN/../lib'",
1251+
"'-Wl,-rpath=$ORIGIN/../lib64'",
12311252
"'-Wl,--disable-new-dtags'",
12321253
"'-Wl,-rpath=/icc/lib/intel64'",
12331254
"'-Wl,-rpath=/imkl/lib'",
@@ -1271,6 +1292,8 @@ def test_rpath_args_script(self):
12711292
"'-Wl,-rpath=%s/lib'" % self.test_prefix,
12721293
"'-Wl,-rpath=%s/lib64'" % self.test_prefix,
12731294
"'-Wl,-rpath=$ORIGIN'",
1295+
"'-Wl,-rpath=$ORIGIN/../lib'",
1296+
"'-Wl,-rpath=$ORIGIN/../lib64'",
12741297
"'-Wl,--disable-new-dtags'",
12751298
"'-DHAVE_CONFIG_H'",
12761299
"'-I.'",

test/framework/toy_build.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,10 +1644,40 @@ def test_toy_iter(self):
16441644

16451645
def test_toy_rpath(self):
16461646
"""Test toy build using --rpath."""
1647-
self.test_toy_build(extra_args=['--rpath', '--experimental'], raise_error=True)
1647+
def grab_gcc_rpath_wrapper_filter_arg():
1648+
"""Helper function to grab filter argument from last RPATH wrapper for 'gcc'."""
1649+
rpath_wrappers_dir = glob.glob(os.path.join(os.getenv('TMPDIR'), '*', '*', 'rpath_wrappers'))[0]
1650+
gcc_rpath_wrapper_txt = read_file(os.path.join(rpath_wrappers_dir, 'gcc'))
1651+
1652+
rpath_args_regex = re.compile(r"^rpath_args_out=.*rpath_args.py \$CMD '([^ ]*)'.*", re.M)
1653+
res = rpath_args_regex.search(gcc_rpath_wrapper_txt)
1654+
self.assertTrue(res, "Pattern '%s' found in: %s" % (rpath_args_regex.pattern, gcc_rpath_wrapper_txt))
1655+
1656+
shutil.rmtree(rpath_wrappers_dir)
1657+
1658+
return res.group(1)
1659+
1660+
args = ['--rpath', '--experimental']
1661+
self.test_toy_build(extra_args=args, raise_error=True)
1662+
1663+
# by default, /lib and /usr are included in RPATH filter,
1664+
# together with temporary directory and build directory
1665+
rpath_filter_paths = grab_gcc_rpath_wrapper_filter_arg().split(',')
1666+
self.assertTrue('/lib.*' in rpath_filter_paths)
1667+
self.assertTrue('/usr.*' in rpath_filter_paths)
1668+
self.assertTrue(any(p.startswith(os.getenv('TMPDIR')) for p in rpath_filter_paths))
1669+
self.assertTrue(any(p.startswith(self.test_buildpath) for p in rpath_filter_paths))
16481670

16491671
# also test use of --rpath-filter
1650-
self.test_toy_build(extra_args=['--rpath', '--rpath-filter=/test.*,/foo.*', '--experimental'], raise_error=True)
1672+
args.extend(['--rpath-filter=/test.*,/foo/bar.*', '--disable-cleanup-tmpdir'])
1673+
outtxt = self.test_toy_build(extra_args=args, raise_error=True)
1674+
1675+
# check whether rpath filter was set correctly
1676+
rpath_filter_paths = grab_gcc_rpath_wrapper_filter_arg().split(',')
1677+
self.assertTrue('/test.*' in rpath_filter_paths)
1678+
self.assertTrue('/foo/bar.*' in rpath_filter_paths)
1679+
self.assertTrue(any(p.startswith(os.getenv('TMPDIR')) for p in rpath_filter_paths))
1680+
self.assertTrue(any(p.startswith(self.test_buildpath) for p in rpath_filter_paths))
16511681

16521682
# test use of rpath toolchain option
16531683
test_ecs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')

0 commit comments

Comments
 (0)