Skip to content

Commit 7aed532

Browse files
committed
filter out duplicate paths in RPATH wrapper script
1 parent a492dec commit 7aed532

File tree

2 files changed

+217
-82
lines changed

2 files changed

+217
-82
lines changed

easybuild/scripts/rpath_args.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
import sys
3737

3838

39+
def is_new_existing_path(new_path, paths):
40+
"""
41+
Check whether specified path exsits and is a new path compared to provided list of paths.
42+
"""
43+
44+
# assume path is new, until proven otherwise
45+
res = True
46+
47+
if os.path.exists(new_path):
48+
for path in paths:
49+
if os.path.exists(path) and os.path.samefile(new_path, path):
50+
res = False
51+
break
52+
else:
53+
# path doesn't exist
54+
res = False
55+
56+
return res
57+
58+
3959
cmd = sys.argv[1]
4060
rpath_filter = sys.argv[2]
4161
rpath_include = sys.argv[3]
@@ -60,6 +80,7 @@
6080

6181
add_rpath_args = True
6282
cmd_args, cmd_args_rpath = [], []
83+
rpath_lib_paths = []
6384

6485
# process list of original command line arguments
6586
idx = 0
@@ -95,16 +116,18 @@
95116
else:
96117
lib_path = arg[2:]
97118

119+
# don't RPATH in empty or relative paths, or paths that are filtered out;
120+
# linking relative paths via RPATH doesn't make much sense,
121+
# and it can also break the build because it may result in reordering lib paths
98122
if lib_path and os.path.isabs(lib_path) and (rpath_filter is None or not rpath_filter.match(lib_path)):
99-
# inject -rpath flag in front for every -L with an absolute path,
100-
# also retain the -L flag (without reordering!)
101-
cmd_args_rpath.append(flag_prefix + '-rpath=%s' % lib_path)
102-
cmd_args.append('-L%s' % lib_path)
103-
else:
104-
# don't RPATH in empty or relative paths, or paths that are filtered out;
105-
# linking relative paths via RPATH doesn't make much sense,
106-
# and it can also break the build because it may result in reordering lib paths
107-
cmd_args.append('-L%s' % lib_path)
123+
# avoid using duplicate library paths
124+
if is_new_existing_path(lib_path, rpath_lib_paths):
125+
# inject -rpath flag in front for every -L with an absolute path,
126+
rpath_lib_paths.append(lib_path)
127+
cmd_args_rpath.append(flag_prefix + '-rpath=%s' % lib_path)
128+
129+
# always retain -L flag (without reordering!)
130+
cmd_args.append('-L%s' % lib_path)
108131

109132
# replace --enable-new-dtags with --disable-new-dtags if it's used;
110133
# --enable-new-dtags would result in copying rpath to runpath,
@@ -123,9 +146,10 @@
123146
# unless they are there already
124147
for lib_path in os.getenv('LIBRARY_PATH', '').split(os.pathsep):
125148
if lib_path and os.path.isabs(lib_path) and (rpath_filter is None or not rpath_filter.match(lib_path)):
126-
rpath_arg = flag_prefix + '-rpath=%s' % lib_path
127-
if rpath_arg not in cmd_args_rpath:
128-
cmd_args_rpath.append(rpath_arg)
149+
# avoid using duplicate library paths
150+
if is_new_existing_path(lib_path, rpath_lib_paths):
151+
rpath_lib_paths.append(lib_path)
152+
cmd_args_rpath.append(flag_prefix + '-rpath=%s' % lib_path)
129153

130154
if add_rpath_args:
131155
# try to make sure that RUNPATH is not used by always injecting --disable-new-dtags

0 commit comments

Comments
 (0)