From 351aee8ace6eec6b655da321a48a120b020b54c4 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 15 Nov 2021 20:34:38 +0530 Subject: [PATCH] Don't wipe out RPATHs specified by dependencies Since we scan all dependencies for build-only RPATHs now (which are removed on install), we must take care not to add build-only RPATHs pointing to directories that dependencies explicitly add -Wl,-rpath link args for, otherwise the paths will get wiped on install. Caught by LinuxlikeTests::test_usage_pkgconfig_prefixes --- mesonbuild/backend/backends.py | 8 +++++++- mesonbuild/mesonlib/universal.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 177f24a9f590..8e62d381267c 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -708,7 +708,6 @@ def _libdir_is_system(libdir: str, compilers: T.Mapping[str, 'Compiler'], env: ' return False def get_external_rpath_dirs(self, target: build.BuildTarget) -> T.Set[str]: - dirs: T.Set[str] = set() args: T.List[str] = [] for lang in LANGUAGES_USING_LDFLAGS: try: @@ -719,6 +718,11 @@ def get_external_rpath_dirs(self, target: build.BuildTarget) -> T.Set[str]: args.extend(e) except Exception: pass + return self.get_rpath_dirs_from_link_args(args) + + @staticmethod + def get_rpath_dirs_from_link_args(args: T.List[str]) -> T.Set[str]: + dirs: T.Set[str] = set() # Match rpath formats: # -Wl,-rpath= # -Wl,-rpath, @@ -777,6 +781,8 @@ def rpaths_for_non_system_absolute_shared_libraries(self, target: build.BuildTar paths.add(os.path.join(self.build_to_src, rel_to_src)) else: paths.add(libdir) + # Don't remove rpaths specified by the dependency + paths.difference_update(self.get_rpath_dirs_from_link_args(dep.link_args)) for i in chain(target.link_targets, target.link_whole_targets): if isinstance(i, build.BuildTarget): paths.update(self.rpaths_for_non_system_absolute_shared_libraries(i, exclude_system)) diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index f193889f8b73..53e9514c2c50 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -1756,6 +1756,10 @@ def update(self, iterable: T.Iterable[_T]) -> None: def difference(self, set_: T.Union[T.Set[_T], 'OrderedSet[_T]']) -> 'OrderedSet[_T]': return type(self)(e for e in self if e not in set_) + def difference_update(self, iterable: T.Iterable[_T]) -> None: + for item in iterable: + self.discard(item) + def relpath(path: str, start: str) -> str: # On Windows a relative path can't be evaluated for paths on two different # drives (i.e. c:\foo and f:\bar). The only thing left to do is to use the