@@ -41,11 +41,21 @@ def set_rpath(filepath: Path, old: List[str], rpath: List[str]) -> None:
41
41
@classmethod
42
42
def fix_rpath (cls , filepath : Path , libs_relative_path : str ) -> None :
43
43
old_rpath = cls .get_rpath (filepath )
44
- new_rpath = []
45
- for path in old_rpath :
46
- if path .startswith (cls .origin ):
47
- path = os .path .join (cls .origin , libs_relative_path )
48
- new_rpath .append (path )
44
+ new_rpath = old_rpath [:]
45
+
46
+ # When an executable, libray, or Python extension module is
47
+ # dynamically linked to a library built as part of the project, Meson
48
+ # adds a build RPATH pointing to the build directory, in the form of a
49
+ # relative RPATH entry. We can use the presence of any RPATH entries
50
+ # relative to ``$ORIGIN`` as an indicator that the installed object
51
+ # depends on shared libraries internal to the project. In this case we
52
+ # need to add an RPATH entry pointing to the meson-python shared
53
+ # library install location. This heuristic is not perfect: RPATH
54
+ # entries relative to ``$ORIGIN`` can exist for other reasons.
55
+ # However, this only results in harmless additional RPATH entries.
56
+ if any (path .startswith (cls .origin ) for path in old_rpath ):
57
+ new_rpath .append (os .path .join (cls .origin , libs_relative_path ))
58
+
49
59
new_rpath = unique (new_rpath )
50
60
if new_rpath != old_rpath :
51
61
cls .set_rpath (filepath , old_rpath , new_rpath )
0 commit comments