1From 4e1aa0ddbc43403ff24f644b4c4912b737290c41 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 girepository/girepository.c | 15 +++++++++++++--
19 girepository/meson.build    |  2 +-
20 2 files changed, 14 insertions(+), 3 deletions(-)
21
22diff --git a/girepository/girepository.c b/girepository/girepository.c
23index 12eaf36..876382c 100644
24--- a/girepository/girepository.c
25+++ b/girepository/girepository.c
26@@ -21,6 +21,8 @@
27  * Boston, MA 02111-1307, USA.
28  */
29
30+#define _GNU_SOURCE
31+
32 #include "config.h"
33
34 #include <stdio.h>
35@@ -34,6 +36,8 @@
36 #include "gitypelib-internal.h"
37 #include "girepository-private.h"
38
39+#include <dlfcn.h>
40+
41 /**
42  * SECTION:girepository
43  * @short_description: GObject Introspection repository manager
44@@ -222,9 +226,16 @@ init_globals (void)
45           g_free (custom_dirs);
46         }
47
48-      libdir = GOBJECT_INTROSPECTION_LIBDIR;
49+      Dl_info gi_lib_info;
50
51-      typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL);
52+      if (dladdr (g_irepository_get_default, &gi_lib_info)) {
53+        char *libdir = g_path_get_dirname (gi_lib_info.dli_fname);
54+        typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL);
55+        g_free (libdir);
56+      } else {
57+        libdir = GOBJECT_INTROSPECTION_LIBDIR;
58+        typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL);
59+      }
60
61       typelib_search_path = g_slist_prepend (typelib_search_path, typelib_dir);
62
63diff --git a/girepository/meson.build b/girepository/meson.build
64index 5ced59e..a580d9b 100644
65--- a/girepository/meson.build
66+++ b/girepository/meson.build
67@@ -47,7 +47,7 @@ girepo_internals_lib = static_library('girepository-internals',
68   ],
69   c_args: gi_hidden_visibility_cflags + custom_c_args,
70   include_directories : configinc,
71-  dependencies: [girepo_gthash_dep, libffi_dep],
72+  dependencies: [girepo_gthash_dep, libffi_dep, cc.find_library('dl')],
73 )
74
75 girepo_internals_dep = declare_dependency(
76