blob: ba85c317f6171d50dbc16638410ae899dec73eeb [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 4cf37d56fddcc22bcd818f6d470404f56d907f3c 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 1 file changed, 13 insertions(+), 2 deletions(-)
21
22diff --git a/girepository/girepository.c b/girepository/girepository.c
23index c1fa3d3..efa557e 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@@ -188,9 +192,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