From 728dc0319da1867f72838d7e6c4aff7d7f71cc1c Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Wed, 21 Feb 2024 11:49:10 +0100 Subject: [PATCH] vala: Follow the logic of GIrParser.locate_gir() to find gir files This adds the abilitiy to retrieve GI_GIRDIR from the enviroment, e.g. while passed to ./configure See https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/258 Fixes https://gitlab.gnome.org/GNOME/vala/issues/1518 --- configure.ac | 6 +++++ vala/valacodecontext.vala | 51 ++++++++++++++++++++++++++++++++++++++- vapi/config.vapi | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 869b39a04..f57cfa0ad 100644 --- a/configure.ac +++ b/configure.ac @@ -194,6 +194,12 @@ PKG_CHECK_MODULES(GMODULE, gmodule-2.0 >= $GLIB_REQUIRED) AC_SUBST(GMODULE_CFLAGS) AC_SUBST(GMODULE_LIBS) +AC_ARG_VAR([GI_GIRDIR],[Set an alternative system location of gir files]) +AC_MSG_CHECKING([for GI_GIRDIR]) +PKG_CHECK_VAR([GI_GIRDIR], [gobject-introspection-1.0], [girdir], [], [AC_MSG_ERROR([Unable to retrieve girdir from gobject-introspection-1.0.pc])]) +AC_MSG_RESULT([$GI_GIRDIR]) +AC_DEFINE_UNQUOTED(GI_GIRDIR, "$GI_GIRDIR", [Define to system location of gir files]) + AC_ARG_WITH(cgraph, AS_HELP_STRING([--with-cgraph], [Required flag for cross-compilation to define capability of graphviz]), [], with_cgraph=check) AC_ARG_ENABLE(valadoc, AS_HELP_STRING([--disable-valadoc], [Disable valadoc]), enable_valadoc=$enableval, enable_valadoc=yes) AS_IF([test "$VALAC" != :], [FOUND_VALAC_VERION=`$VALAC --version | sed 's/Vala *//'` diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 7610890fd..cf8119759 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -688,7 +688,56 @@ public class Vala.CodeContext { } public string? get_gir_path (string gir) { - return get_file_path (gir + ".gir", "gir-1.0", null, gir_directories); + const string GIR_SUFFIX = "gir-1.0"; + string girname = gir + ".gir"; + string path = null; + + foreach (unowned string dir in gir_directories) { + path = Path.build_path ("/", dir, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + } + + // Search $GI_GIR_PATH + unowned string? gi_gir_path = Environment.get_variable ("GI_GIR_PATH"); + if (gi_gir_path != null) { + var gir_dirs = gi_gir_path.split (Path.SEARCHPATH_SEPARATOR_S); + foreach (unowned string dir in gir_dirs) { + path = Path.build_path ("/", dir, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + } + } + + // Search $XDG_DATA_HOME + path = Path.build_path ("/", Environment.get_user_data_dir (), GIR_SUFFIX, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + + // Search $XDG_DATA_DIRS + foreach (unowned string dir in Environment.get_system_data_dirs ()) { + path = Path.build_path ("/", dir, GIR_SUFFIX, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + } + + // Search $GI_GIRDIR set by user or retrieved from gobject-introspection-1.0.pc + path = Path.build_path (Config.GI_GIRDIR, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + + // Search /usr/share + path = Path.build_path ("/", "usr", "share", GIR_SUFFIX, girname); + if (FileUtils.test (path, FileTest.EXISTS | FileTest.IS_REGULAR)) { + return path; + } + + return null; } public string? get_gresource_path (string gresource, string resource) { diff --git a/vapi/config.vapi b/vapi/config.vapi index c8b5d58a1..9d32a575c 100644 --- a/vapi/config.vapi +++ b/vapi/config.vapi @@ -26,4 +26,5 @@ namespace Config { public const string PACKAGE_SUFFIX; public const string PACKAGE_VALADOC_LIBDIR; public const string PACKAGE_VALADOC_ICONDIR; + public const string GI_GIRDIR; } -- 2.47.2