From 373e46c2b2258b6a5476e099f452289b49b93ee5 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Tue, 2 Mar 2021 13:15:50 +0000 Subject: [PATCH] gio/tests/{meson.build,pollable.c}: Determine libutil SONAME at build time Calling `dlopen()` with `libutil.so` makes the installed tests depend on having glibc's development files installed. To avoid this, we can work out the runtime library name at build time and `dlopen` that instead. This approach is [taken from libfprint][1], thanks to Marco Trevisan. [1]: https://gitlab.freedesktop.org/libfprint/fprintd/-/commit/f401f399a85dbeb2de165b9b9162eb552ab6eea7 --- gio/tests/meson.build | 15 +++++++++++++++ gio/tests/pollable.c | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gio/tests/meson.build b/gio/tests/meson.build index 881f07ccc..a926ae01a 100644 --- a/gio/tests/meson.build +++ b/gio/tests/meson.build @@ -12,6 +12,21 @@ test_c_args = [ '-UG_DISABLE_ASSERT', ] +# workaround for https://github.com/mesonbuild/meson/issues/6880 +if build_machine.system() == 'linux' + libutil_name = 'libutil' + libutil = run_command('sh', '-c', + '''ldconfig -p | grep -o "[[:space:]]@0@\.so\(\.[0-9]\+\)\?\b"''' + .format(libutil_name)).stdout().strip().split('\n') + + if libutil.length() > 0 + message('Found libutil as @0@'.format(libutil[0])) + test_c_args += '-DLIBUTIL_SONAME="@0@"'.format(libutil[0]) + else + warning('libutil not found') + endif # libutil.length() > 0 +endif # build_machine.system() == 'linux' + if host_machine.system() == 'windows' common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')] endif diff --git a/gio/tests/pollable.c b/gio/tests/pollable.c index d57c4733a..516d7f4e4 100644 --- a/gio/tests/pollable.c +++ b/gio/tests/pollable.c @@ -187,14 +187,15 @@ test_pollable_unix_pty (void) { int (*openpty_impl) (int *, int *, char *, void *, void *); int a, b, status; -#ifdef __linux__ +#ifdef LIBUTIL_SONAME void *handle; #endif g_test_summary ("Test that PTYs are considered pollable"); -#ifdef __linux__ - handle = dlopen ("libutil.so", RTLD_GLOBAL | RTLD_LAZY); +#ifdef LIBUTIL_SONAME + handle = dlopen (LIBUTIL_SONAME, RTLD_GLOBAL | RTLD_LAZY); + g_assert_nonnull (handle); #endif openpty_impl = dlsym (RTLD_DEFAULT, "openpty"); @@ -223,7 +224,7 @@ test_pollable_unix_pty (void) close (b); close_libutil: -#ifdef __linux__ +#ifdef LIBUTIL_SONAME dlclose (handle); #else return;