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 <smcv@debian.org>
This commit is contained in:
Simon McVittie 2021-02-10 11:45:26 +00:00 committed by Simon McVittie
parent 59ae4e65d2
commit 19f14589d3

View File

@ -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->gi_gir_path);
for (l = parser->parsed_modules; l; l = l->next)
_g_ir_module_free (l->data);
@ -206,7 +211,6 @@ void
_g_ir_parser_set_includes (GIrParser *parser,
const gchar *const *includes)
{
if (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);