From: Rico Tzschichholz Date: Wed, 21 Feb 2024 10:49:10 +0000 (+0100) Subject: vala: Follow the logic of GIrParser.locate_gir() to find gir files X-Git-Tag: 0.56.15~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9d38070ce86d7994b949f7cb426fbf670a953d8;p=thirdparty%2Fvala.git 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 --- diff --git a/configure.ac b/configure.ac index 088e8f3b5..4b599eb83 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 5e6775846..8461403c6 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; }