]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Follow the logic of GIrParser.locate_gir() to find gir files
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 21 Feb 2024 10:49:10 +0000 (11:49 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 21 Feb 2024 11:18:08 +0000 (12:18 +0100)
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
vala/valacodecontext.vala
vapi/config.vapi

index 869b39a044d590850054da716440f8cc1d42464c..f57cfa0ad92135d505e04dc45cd27beb72514b82 100644 (file)
@@ -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  *//'`
index 7610890fdcd186cf9f3065969d7ed081dca1eade..cf81197596a1a7637c7624903ede2480e74513fe 100644 (file)
@@ -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) {
index c8b5d58a1aea0387371c8baa1fe6f025810b863f..9d32a575c5668aeeb9f92865a863b27c7f41d5be 100644 (file)
@@ -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;
 }