diff options
author | Daniel Stone <daniels@collabora.com> | 2022-11-30 12:03:57 +0000 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2022-11-30 11:44:47 -0800 |
commit | a0514a7c4183a9e42d436865087d2f887d658d54 (patch) | |
tree | b1809a0710b47f320b847a6949ba03ef8179dc94 /mesonbuild/backend/backends.py | |
parent | 67da2ad0fb3a0e45bd878d21aa1c5d956214c483 (diff) | |
download | meson-a0514a7c4183a9e42d436865087d2f887d658d54.zip meson-a0514a7c4183a9e42d436865087d2f887d658d54.tar.gz meson-a0514a7c4183a9e42d436865087d2f887d658d54.tar.bz2 |
tests: Write out LD_LIBRARY_PATH for built shared libraries
When a test executable references a local shared library, make sure that
we apply the appropriate $LD_LIBRARY_PATH so that the linker can find it
at runtime.
The DT_RUNPATH entry does ensure that the binary references the path to
the shared library build, however the RUNPATH list is only searched
after $LD_LIBRARY_PATH. So if the user has a shared library of the same
name in their $LD_LIBRARY_PATH, this will be the version found and used
for running the test. This is bad if you're trying to use Meson to test
a shared library you're developing and have installed in a local prefix
which is under $LD_LIBRARY_PATH.
Fixes #1635
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r-- | mesonbuild/backend/backends.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index bc356b3..747d80e 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -18,6 +18,7 @@ from dataclasses import dataclass, InitVar from functools import lru_cache from itertools import chain from pathlib import Path +import copy import enum import json import os @@ -1141,9 +1142,21 @@ class Backend: cmd_args.extend(self.construct_target_rel_paths(a, t.workdir)) else: raise MesonException('Bad object in test command.') + + t_env = copy.deepcopy(t.env) + if not machine.is_windows() and not machine.is_cygwin() and not machine.is_darwin(): + ld_lib_path: T.Set[str] = set() + for d in depends: + if isinstance(d, build.BuildTarget): + for l in d.get_all_link_deps(): + if isinstance(l, build.SharedLibrary): + ld_lib_path.add(os.path.join(self.environment.get_build_dir(), l.get_subdir())) + if ld_lib_path: + t_env.prepend('LD_LIBRARY_PATH', list(ld_lib_path), ':') + ts = TestSerialisation(t.get_name(), t.project_name, t.suite, cmd, is_cross, exe_wrapper, self.environment.need_exe_wrapper(), - t.is_parallel, cmd_args, t.env, + t.is_parallel, cmd_args, t_env, t.should_fail, t.timeout, t.workdir, extra_paths, t.protocol, t.priority, isinstance(exe, build.Target), |