|
36 | 36 | import sys |
37 | 37 |
|
38 | 38 |
|
| 39 | +def is_new_existing_path(new_path, paths): |
| 40 | + """ |
| 41 | + Check whether specified path exists 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 | + |
39 | 59 | cmd = sys.argv[1] |
40 | 60 | rpath_filter = sys.argv[2] |
41 | 61 | rpath_include = sys.argv[3] |
|
60 | 80 |
|
61 | 81 | add_rpath_args = True |
62 | 82 | cmd_args, cmd_args_rpath = [], [] |
| 83 | +rpath_lib_paths = [] |
63 | 84 |
|
64 | 85 | # process list of original command line arguments |
65 | 86 | idx = 0 |
|
95 | 116 | else: |
96 | 117 | lib_path = arg[2:] |
97 | 118 |
|
| 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 |
98 | 122 | 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) |
108 | 131 |
|
109 | 132 | # replace --enable-new-dtags with --disable-new-dtags if it's used; |
110 | 133 | # --enable-new-dtags would result in copying rpath to runpath, |
|
123 | 146 | # unless they are there already |
124 | 147 | for lib_path in os.getenv('LIBRARY_PATH', '').split(os.pathsep): |
125 | 148 | 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) |
129 | 153 |
|
130 | 154 | if add_rpath_args: |
131 | 155 | # try to make sure that RUNPATH is not used by always injecting --disable-new-dtags |
|
0 commit comments