[gnome-builder/gnome-builder-3-20] vala: add vala versioned and unversioned vapidir



commit 1036b5483e223957ab0e76419199b863ab1b218b
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 6 10:03:04 2016 +0300

    vala: add vala versioned and unversioned vapidir
    
    This ensures we have the vala vapidirs such as:
    
      /usr/share/vala/vapi
      /usr/share/vala-0.32/vapi
    
    available to the code context.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764752

 plugins/vala-pack/Makefile.am         |    1 +
 plugins/vala-pack/ide-vala-index.vala |   52 ++++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/plugins/vala-pack/Makefile.am b/plugins/vala-pack/Makefile.am
index ee14f93..65113af 100644
--- a/plugins/vala-pack/Makefile.am
+++ b/plugins/vala-pack/Makefile.am
@@ -68,6 +68,7 @@ libvala_pack_plugin_la_VALAFLAGS = \
        --pkg gtksourceview-3.0 \
        --pkg libvala-$(VALA_VERSION) \
        --pkg posix \
+       --pkg gio-2.0 \
        --pkg template-glib-1.0 \
        $(NULL)
 
diff --git a/plugins/vala-pack/ide-vala-index.vala b/plugins/vala-pack/ide-vala-index.vala
index d663420..b7124a8 100644
--- a/plugins/vala-pack/ide-vala-index.vala
+++ b/plugins/vala-pack/ide-vala-index.vala
@@ -33,6 +33,8 @@ namespace Ide
 {
        public class ValaIndex: GLib.Object
        {
+               static const int VALA_VERSION = 32;
+
                Ide.Context context;
                Vala.CodeContext code_context;
                Vala.Parser parser;
@@ -84,7 +86,7 @@ namespace Ide
 
                        this.code_context.run_output = false;
 
-                       for (var i = 2; i <= 32; i += 2) {
+                       for (var i = 2; i <= VALA_VERSION; i += 2) {
                                this.code_context.add_define ("VALA_0_%d".printf (i));
                        }
 
@@ -92,9 +94,19 @@ namespace Ide
                                this.code_context.add_define ("GLIB_2_%d".printf (i));
                        }
 
-                       this.code_context.vapi_directories = {
-                               Path.build_filename (Config.PACKAGE_DATADIR, "vapi"),
-                       };
+                       this.code_context.vapi_directories = {};
+
+                       /* $prefix/share/vala-0.32/vapi */
+                       string versioned_vapidir = get_versioned_vapidir ();
+                       if (versioned_vapidir != null) {
+                               this.add_vapidir_locked (versioned_vapidir);
+                       }
+
+                       /* $prefix/share/vala/vapi */
+                       string unversioned_vapidir = get_unversioned_vapidir ();
+                       if (unversioned_vapidir != null) {
+                               this.add_vapidir_locked (unversioned_vapidir);
+                       }
 
                        this.code_context.add_external_package ("glib-2.0");
                        this.code_context.add_external_package ("gobject-2.0");
@@ -157,6 +169,7 @@ namespace Ide
                                }
                        }
 
+                       debug ("Adding vapidir %s", vapidir);
                        dirs += vapidir;
                        this.code_context.vapi_directories = dirs;
                }
@@ -498,6 +511,37 @@ namespace Ide
 
                        return ret;
                }
+
+               string? get_versioned_vapidir ()
+               {
+                       try {
+                               var pkgname = "libvala-0.%d".printf (VALA_VERSION);
+                               string outstr = null;
+                               var subprocess = new GLib.Subprocess (GLib.SubprocessFlags.STDOUT_PIPE,
+                                                                         "pkg-config",
+                                                                         "--variable=vapidir",
+                                                                         pkgname,
+                                                                         null);
+                               subprocess.communicate_utf8 (null, null, out outstr, null);
+                               outstr = outstr.strip();
+                               return outstr;
+                       } catch (GLib.Error er) {
+                               warning ("%s", er.message);
+                               return null;
+                       }
+               }
+
+               string? get_unversioned_vapidir ()
+               {
+                       string versioned_vapidir = get_versioned_vapidir ();
+
+                       if (versioned_vapidir != null) {
+                               return GLib.Path.build_filename (versioned_vapidir,
+                                                                "..", "..", "vala", "vapi", null);
+                       }
+
+                       return null;
+               }
        }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]