summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-10-19 20:40:25 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2018-10-19 21:42:50 +0300
commit32e91a8e5a13f69296c338a8e457cb5f0a20229b (patch)
treeb0654d80ebe4adb1f4be3c679b2d12191adc594b
parent2915f27f12072d70a68a4be06c8986e800c9fbea (diff)
downloadmeson-relrpath.tar.gz
Order rpaths so that internal ones come first.relrpath
-rw-r--r--mesonbuild/compilers/compilers.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 977c0a7e4..c7c4e78b1 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -503,6 +503,22 @@ def get_base_link_args(options, linker, is_shared_module):
pass
return args
+def prepare_rpaths(raw_rpaths, build_dir, from_dir):
+ internal_format_rpaths = [evaluate_rpath(p, build_dir, from_dir) for p in raw_rpaths]
+ ordered_rpaths = order_rpaths(internal_format_rpaths)
+ return ordered_rpaths
+
+def order_rpaths(rpath_list):
+ # We want rpaths that point inside our build dir to always override
+ # those pointing to other places in the file system. This is so built
+ # binaries prefer our libraries to the ones that may lie somewhere
+ # in the file system, such as /lib/x86_64-linux-gnu.
+ #
+ # The correct thing to do here would be C++'s std::stable_partition.
+ # Python standard library does not have it, so replicate it with
+ # sort, which is guaranteed to be stable.
+ return sorted(rpath_list, key=os.path.isabs)
+
def evaluate_rpath(p, build_dir, from_dir):
if p == from_dir:
return '' # relpath errors out in this case
@@ -1112,7 +1128,7 @@ class Compiler:
# The rpaths we write must be relative if they point to the build dir,
# because otherwise they have different length depending on the build
# directory. This breaks reproducible builds.
- processed_rpaths = [evaluate_rpath(p, build_dir, from_dir) for p in rpath_paths]
+ processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
# Need to deduplicate rpaths, as macOS's install_name_tool
# is *very* allergic to duplicate -delete_rpath arguments
# when calling depfixer on installation.