diff --git a/mesonpy/_rpath.py b/mesonpy/_rpath.py index 317e776e4..8018e9db2 100644 --- a/mesonpy/_rpath.py +++ b/mesonpy/_rpath.py @@ -26,10 +26,13 @@ def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None: subprocess.run(['patchelf','--set-rpath', ':'.join(rpath), os.fspath(filepath)], check=True) def fix_rpath(filepath: Path, libs_relative_path: str) -> None: - rpath = _get_rpath(filepath) - if '$ORIGIN/' in rpath: - rpath = [('$ORIGIN/' + libs_relative_path if path == '$ORIGIN/' else path) for path in rpath] - _set_rpath(filepath, rpath) + old_rpath = _get_rpath(filepath) + for path in old_rpath: + if path.startswith('$ORIGIN/'): + path = '$ORIGIN/' + libs_relative_path + new_rpath.append(path) + if new_rpath != old_rpath: + _set_rpath(filepath, new_rpath) elif sys.platform == 'darwin': @@ -50,9 +53,9 @@ def _replace_rpath(filepath: Path, old: str, new: str) -> None: subprocess.run(['install_name_tool', '-rpath', old, new, os.fspath(filepath)], check=True) def fix_rpath(filepath: Path, libs_relative_path: str) -> None: - rpath = _get_rpath(filepath) - if '@loader_path/' in rpath: - _replace_rpath(filepath, '@loader_path/', '@loader_path/' + libs_relative_path) + for path in _get_rpath(filepath): + if path.startswith('@loader_path/'): + _replace_rpath(filepath, path, '@loader_path/' + libs_relative_path) else: diff --git a/tests/packages/link-against-local-lib/examplemod.c b/tests/packages/link-against-local-lib/examplemod.c index abe63ed54..7d0204754 100644 --- a/tests/packages/link-against-local-lib/examplemod.c +++ b/tests/packages/link-against-local-lib/examplemod.c @@ -4,7 +4,7 @@ #include -#include "examplelib.h" +#include "lib/examplelib.h" static PyObject* example_sum(PyObject* self, PyObject *args) { diff --git a/tests/packages/link-against-local-lib/examplelib.c b/tests/packages/link-against-local-lib/lib/examplelib.c similarity index 100% rename from tests/packages/link-against-local-lib/examplelib.c rename to tests/packages/link-against-local-lib/lib/examplelib.c diff --git a/tests/packages/link-against-local-lib/examplelib.h b/tests/packages/link-against-local-lib/lib/examplelib.h similarity index 100% rename from tests/packages/link-against-local-lib/examplelib.h rename to tests/packages/link-against-local-lib/lib/examplelib.h diff --git a/tests/packages/link-against-local-lib/lib/meson.build b/tests/packages/link-against-local-lib/lib/meson.build new file mode 100644 index 000000000..51167f9d1 --- /dev/null +++ b/tests/packages/link-against-local-lib/lib/meson.build @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2022 The meson-python developers +# +# SPDX-License-Identifier: MIT + +example_lib = shared_library( + 'example', + 'examplelib.c', + install: true, +) diff --git a/tests/packages/link-against-local-lib/meson.build b/tests/packages/link-against-local-lib/meson.build index 52d5fec32..a45168cb4 100644 --- a/tests/packages/link-against-local-lib/meson.build +++ b/tests/packages/link-against-local-lib/meson.build @@ -4,11 +4,7 @@ project('link-against-local-lib', 'c', version: '1.0.0') -example_lib = shared_library( - 'example', - 'examplelib.c', - install: true, -) +subdir('lib') py = import('python').find_installation()