1From 74a0fee892235c722ac60ddea6ee79bc3d7a93f5 Mon Sep 17 00:00:00 2001 2From: Sascha Silbe <x-yo17@se-silbe.de> 3Date: Fri, 8 Jun 2018 13:55:10 +0200 4Subject: [PATCH] Relocate the repository directory for native builds 5 6Instead of hard-coding GOBJECT_INTROSPECTION_LIBDIR when 7gobject-introspection is built, use dladdr() to determine where 8GOBJECT_INTROSPECTION_LIBDIR is and use that path to calculate the 9repository directory. 10 11This fixes gobject-introspection-native accessing paths across build 12directories (e.g. if the build directories use the same shared state 13cache or sstate mirror). 14 15Upstream-Status: Inappropriate 16Signed-off-by: Sascha Silbe <x-yo17@se-silbe.de> 17 18--- 19 girepository/girepository.c | 15 +++++++++++++-- 20 girepository/meson.build | 2 +- 21 2 files changed, 14 insertions(+), 3 deletions(-) 22 23diff --git a/girepository/girepository.c b/girepository/girepository.c 24index 7d03485..20f4813 100644 25--- a/girepository/girepository.c 26+++ b/girepository/girepository.c 27@@ -21,6 +21,8 @@ 28 * Boston, MA 02111-1307, USA. 29 */ 30 31+#define _GNU_SOURCE 32+ 33 #include "config.h" 34 35 #include <stdio.h> 36@@ -34,6 +36,8 @@ 37 #include "gitypelib-internal.h" 38 #include "girepository-private.h" 39 40+#include <dlfcn.h> 41+ 42 /** 43 * SECTION:girepository 44 * @short_description: GObject Introspection repository manager 45@@ -215,9 +219,16 @@ init_globals (void) 46 g_free (custom_dirs); 47 } 48 49- libdir = GOBJECT_INTROSPECTION_LIBDIR; 50+ Dl_info gi_lib_info; 51 52- typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL); 53+ if (dladdr (g_irepository_get_default, &gi_lib_info)) { 54+ char *libdir = g_path_get_dirname (gi_lib_info.dli_fname); 55+ typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL); 56+ g_free (libdir); 57+ } else { 58+ libdir = GOBJECT_INTROSPECTION_LIBDIR; 59+ typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL); 60+ } 61 62 typelib_search_path = g_slist_prepend (typelib_search_path, typelib_dir); 63 64diff --git a/girepository/meson.build b/girepository/meson.build 65index 786749a..15cf2a9 100644 66--- a/girepository/meson.build 67+++ b/girepository/meson.build 68@@ -45,7 +45,7 @@ girepo_internals_lib = static_library('girepository-internals', 69 ], 70 c_args: gi_hidden_visibility_cflags + custom_c_args, 71 include_directories : configinc, 72- dependencies: [girepo_gthash_dep, libffi_dep], 73+ dependencies: [girepo_gthash_dep, libffi_dep, cc.find_library('dl')], 74 ) 75 76 girepo_internals_dep = declare_dependency( 77