From 19f14589d35dacc68d4313235d7d93e7aab784c6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 10 Feb 2021 11:45:26 +0000 Subject: [PATCH] Add GI_GIR_PATH environment variable This is searched after any command-line includes paths, but before the XDG_DATA_DIRS or any built-in paths. For example, if libraries are installed in /opt/gnome and GObject-Introspection was configured with -Dgir_dir_prefix=lib64, you could set either GI_GIR_PATH=/opt/gnome/lib64/gir-1.0 or XDG_DATA_DIRS=/opt/gnome/lib64:/opt/gnome/share:${XDG_DATA_DIRS}. Use this to communicate the ../gir directory to giscanner instead of modifying Python's builtins. Helps: #323, #455 Signed-off-by: Simon McVittie --- girparser.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/girparser.c b/girparser.c index b5b5771c2..f13e08715 100644 --- a/girparser.c +++ b/girparser.c @@ -58,6 +58,7 @@ struct _GIrParser { gchar **includes; + gchar **gi_gir_path; GList *parsed_modules; /* All previously parsed modules */ }; @@ -184,6 +185,10 @@ GIrParser * _g_ir_parser_new (void) { GIrParser *parser = g_slice_new0 (GIrParser); + const char *gi_gir_path = g_getenv ("GI_GIR_PATH"); + + if (gi_gir_path != NULL) + parser->gi_gir_path = g_strsplit (gi_gir_path, G_SEARCHPATH_SEPARATOR_S, 0); return parser; } @@ -193,8 +198,8 @@ _g_ir_parser_free (GIrParser *parser) { GList *l; - if (parser->includes) - g_strfreev (parser->includes); + g_strfreev (parser->includes); + g_strfreev (parser->gi_gir_path); for (l = parser->parsed_modules; l; l = l->next) _g_ir_module_free (l->data); @@ -206,8 +211,7 @@ void _g_ir_parser_set_includes (GIrParser *parser, const gchar *const *includes) { - if (parser->includes) - g_strfreev (parser->includes); + g_strfreev (parser->includes); parser->includes = g_strdupv ((char **)includes); } @@ -307,6 +311,22 @@ locate_gir (GIrParser *parser, g_clear_pointer (&path, g_free); } } + + if (parser->gi_gir_path != NULL) + { + for (dir = (const gchar *const *) parser->gi_gir_path; *dir; dir++) + { + if (**dir == '\0') + continue; + + path = g_build_filename (*dir, girname, NULL); + g_debug ("Trying %s from GI_GIR_PATH", path); + if (g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) + return g_steal_pointer (&path); + g_clear_pointer (&path, g_free); + } + } + for (dir = datadirs; *dir; dir++) { path = g_build_filename (*dir, GIR_SUFFIX, girname, NULL);