Skip to content

Commit 1b98549

Browse files
committed
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
1 parent e8727fc commit 1b98549

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mesonbuild/backend/backends.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,21 @@ def create_test_serialisation(self, tests: T.List['Test']) -> T.List[TestSeriali
11411141
cmd_args.extend(self.construct_target_rel_paths(a, t.workdir))
11421142
else:
11431143
raise MesonException('Bad object in test command.')
1144+
1145+
t_env = t.env
1146+
if not machine.is_windows() and not machine.is_cygwin() and not machine.is_darwin():
1147+
ld_lib_path: T.Set[str] = set()
1148+
for d in depends:
1149+
if isinstance(d, build.BuildTarget):
1150+
for l in d.get_all_link_deps():
1151+
if isinstance(l, build.SharedLibrary):
1152+
ld_lib_path.add(os.path.join(self.environment.get_build_dir(), l.get_subdir()))
1153+
if ld_lib_path:
1154+
t_env.prepend('LD_LIBRARY_PATH', list(ld_lib_path), ':')
1155+
11441156
ts = TestSerialisation(t.get_name(), t.project_name, t.suite, cmd, is_cross,
11451157
exe_wrapper, self.environment.need_exe_wrapper(),
1146-
t.is_parallel, cmd_args, t.env,
1158+
t.is_parallel, cmd_args, t_env,
11471159
t.should_fail, t.timeout, t.workdir,
11481160
extra_paths, t.protocol, t.priority,
11491161
isinstance(exe, build.Target),

0 commit comments

Comments
 (0)