[valencia] Configure blacklisted VAPIs



commit 81667537056a915c9b28b51ca121be95d91e1da9
Author: Jim Nelson <jim yorba org>
Date:   Mon Mar 31 18:30:25 2014 -0700

    Configure blacklisted VAPIs
    
    Blacklisted VAPIs aren't scanned when Valencia first parses symbols,
    meaning specific VAPI files can be skipped outright.  This is useful
    when multiple VAPIs hold the same or similar symbols (such as gtk+-2.0
    and gtk+-3.0, or gee-0.8 and gee-1.0) but a project is only using one
    of them.

 .gitignore    |    1 +
 program.vala  |   44 ++++++++++++++++++++++++++++++++++++++++++--
 settings.vala |   35 +++++++++++++++++++++++++++++------
 valencia.vala |    4 ++--
 4 files changed, 74 insertions(+), 10 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 802c2b1..a8efb9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 /libvalencia.so
 /valencia.gedit-plugin
 /valencia.plugin
+.valencia
diff --git a/program.vala b/program.vala
index ba2dfb1..6251619 100644
--- a/program.vala
+++ b/program.vala
@@ -904,9 +904,13 @@ public class ConfigurationFile : Object {
     const string clean_command_keyword = "clean_command";
     const string default_build_command = "make";
     const string default_clean_command = "make clean";
+    const string pkg_blacklist_keyword = "pkg_blacklist";
+    const string default_pkg_blacklist = "";
 
     string build_command;
     string clean_command;
+    string pkg_blacklist;
+    string[]? blacklisted_vapis = null;
 
     enum MatchValue {
         MATCHED,
@@ -981,6 +985,8 @@ public class ConfigurationFile : Object {
                 build_command = match2;
             else if (match1 == clean_command_keyword && match2 != null && clean_command == null)
                 clean_command = match2;
+            else if (match1 == pkg_blacklist_keyword && match2 != null && pkg_blacklist == null)
+                pkg_blacklist = match2;
             else {
                 warning("Incorrect file format, ignoring...\n");
                 return;
@@ -1002,10 +1008,33 @@ public class ConfigurationFile : Object {
         return clean_command == null ? default_clean_command : clean_command;
     }
     
-    public void update(string new_build_command, string new_clean_command) {
+    public string get_pkg_blacklist() {
+        if (pkg_blacklist == null)
+            load();
+        
+        return pkg_blacklist ?? default_pkg_blacklist;
+    }
+    
+    public string[] get_blacklisted_vapis() {
+        if (blacklisted_vapis == null) {
+            string blacklist = get_pkg_blacklist();
+            if (blacklist == null || blacklist.length == 0) {
+                blacklisted_vapis = new string[0];
+            } else {
+                blacklisted_vapis = blacklist.split(";");
+                for (int ctr = 0; ctr < blacklisted_vapis.length; ctr++)
+                    blacklisted_vapis[ctr] = blacklisted_vapis[ctr].strip() + ".vapi";
+            }
+        }
+        
+        return blacklisted_vapis;
+    }
+    
+    public void update(string new_build_command, string new_clean_command, string new_pkg_blacklist) {
         build_command = new_build_command;
         clean_command = new_clean_command;
-    
+        pkg_blacklist = new_pkg_blacklist;
+        
         string file_path = get_file_path();
         FileStream file = FileStream.open(file_path, "w");
         
@@ -1017,6 +1046,11 @@ public class ConfigurationFile : Object {
         file.printf("%s = %s\n", version_keyword, version);
         file.printf("%s = %s\n", build_command_keyword, build_command);
         file.printf("%s = %s\n", clean_command_keyword, clean_command);
+        file.printf("%s = %s\n", pkg_blacklist_keyword, pkg_blacklist);
+        
+        // clear to force a re-load; note that Valencia currently doesn't re-load the cache after
+        // the first pass, so this is kind of moot
+        blacklisted_vapis = null;
     }
 
     public void update_location(string old_directory) {
@@ -1278,6 +1312,12 @@ public class Program : Object {
             string path = Path.build_filename(directory, file);
 
             if (is_vala(file)) {
+                if (file in config_file.get_blacklisted_vapis()) {
+                    debug("Skipping blacklisted package %s", file);
+                    
+                    continue;
+                }
+                
                 sourcefile_paths.add(path);
                 
                 try {
diff --git a/settings.vala b/settings.vala
index 8395339..041f6a5 100644
--- a/settings.vala
+++ b/settings.vala
@@ -11,11 +11,14 @@ class ProjectSettingsDialog : Object {
     Gtk.Dialog dialog;
     Gtk.Entry build_entry;
     Gtk.Entry clean_entry;
+    Gtk.Entry blacklist_entry;
 
     string build_command;
     string clean_command;
+    string pkg_blacklist;
 
-    public signal void settings_changed(string new_build_command, string new_clean_command);
+    public signal void settings_changed(string new_build_command, string new_clean_command,
+        string pkg_blacklist);
 
     public ProjectSettingsDialog(Gtk.Window parent_win) {
         // Window creation
@@ -34,16 +37,28 @@ class ProjectSettingsDialog : Object {
         
         Gtk.Alignment align_clean_label = new Gtk.Alignment(0.0f, 0.5f, 0.0f, 0.0f);
         align_clean_label.add(clean_command_label);
-
+        
+        Gtk.Label blacklist_label = new Gtk.Label("VAPI blacklist:");
+        blacklist_entry = new Gtk.Entry();
+        blacklist_entry.activate.connect(on_entry_activated);
+        blacklist_entry.tooltip_text =
+            "Semicolon-delimited list of package names, i.e. \"gtk+-2.0;gee-1.0\"";
+        blacklist_entry.hexpand = true;
+        
+        Gtk.Alignment align_blacklist_label = new Gtk.Alignment(0.0f, 0.5f, 0.0f, 0.0f);
+        align_blacklist_label.add(blacklist_label);
+        
         Gtk.Grid grid = new Gtk.Grid();
         grid.set_column_spacing(12);
         grid.set_row_spacing(6);
         
         grid.attach(align_build_label, 0, 0, 1, 1);
         grid.attach(align_clean_label, 0, 1, 1, 1);
+        grid.attach(align_blacklist_label, 0, 2, 1, 1);
         grid.attach(build_entry, 1, 0, 1, 1);
         grid.attach(clean_entry, 1, 1, 1, 1);
-                     
+        grid.attach(blacklist_entry, 1, 2, 1, 1);
+         
         Gtk.Alignment alignment_box = new Gtk.Alignment(0.5f, 0.5f, 1.0f, 1.0f);
         alignment_box.set_padding(5, 6, 6, 5);
         alignment_box.add(grid);
@@ -68,9 +83,10 @@ class ProjectSettingsDialog : Object {
 
     void load_settings(string active_filename) {
         Program program = Program.find_containing(active_filename);
-            
+        
         build_command = program.config_file.get_build_command();
         clean_command = program.config_file.get_clean_command();
+        pkg_blacklist = program.config_file.get_pkg_blacklist();
     }
 
     public void show(string active_filename) {
@@ -79,6 +95,7 @@ class ProjectSettingsDialog : Object {
 
         build_entry.set_text(build_command);
         clean_entry.set_text(clean_command);
+        blacklist_entry.set_text(pkg_blacklist);
 
         dialog.set_focus(build_entry);
         int result = dialog.run();
@@ -99,6 +116,7 @@ class ProjectSettingsDialog : Object {
     void save_and_close() {
         string new_build_command = build_entry.get_text();
         string new_clean_command = clean_entry.get_text();
+        string new_pkg_blacklist = blacklist_entry.get_text();
 
         bool changed = false;
         if (new_build_command != build_command && new_build_command != "") {
@@ -109,10 +127,15 @@ class ProjectSettingsDialog : Object {
         if (new_clean_command != clean_command && new_clean_command != "") {
             clean_command = new_clean_command;
             changed = true;
-        }        
+        }
+       
+        if (new_pkg_blacklist != pkg_blacklist && new_pkg_blacklist != "") {
+            pkg_blacklist = new_pkg_blacklist;
+            changed = true;
+        }
        
         if (changed)
-            settings_changed(build_command, clean_command);
+            settings_changed(build_command, clean_command, pkg_blacklist);
 
         hide();
     }
diff --git a/valencia.vala b/valencia.vala
index 18c8c96..cf5d0b7 100644
--- a/valencia.vala
+++ b/valencia.vala
@@ -1484,9 +1484,9 @@ public class Instance : Peas.ExtensionBase, Gedit.WindowActivatable {
             settings_dialog.show(filename);
     }
     
-    void on_settings_changed(string new_build_command, string new_clean_command) {
+    void on_settings_changed(string new_build_command, string new_clean_command, string new_pkg_blacklist) {
         Program program = get_active_document_program();
-        program.config_file.update(new_build_command, new_clean_command);
+        program.config_file.update(new_build_command, new_clean_command, new_pkg_blacklist);
     }
 
 ////////////////////////////////////////////////////////////


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