From a0514a7c4183a9e42d436865087d2f887d658d54 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 30 Nov 2022 12:03:57 +0000 Subject: 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 --- mesonbuild/backend/backends.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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), -- cgit v1.1