sync
[app.Builder.js] / src / Project / Gtk.vala
index 4fbba44..bca1667 100644 (file)
@@ -33,7 +33,11 @@ namespace Project {
                        this.xtype = "Gtk";
                        var gid = "project-gtk-%d".printf(gtk_id++);
                        this.id = gid;
-                       this.loadConfig();
+                       try {
+                               this.loadConfig();
+                       } catch (GLib.Error e )  {
+                               // is tihs ok?
+                       }
                
                }
                public Gee.HashMap<string,GtkValaSettings> compilegroups;
@@ -139,7 +143,7 @@ namespace Project {
                                if (    bb.length < target.length &&
                                        target.substring(0, bb.length) == bb) {
                                        
-                                       return prefix + target.substring(bb.length +1);
+                                       return prefix + target.substring(bb.length );
                                }
                                if (bb.length < 1) {
                                        throw new Error.INVALID_FORMAT ("Could not work out relative path %s to %s",
@@ -163,14 +167,14 @@ namespace Project {
                 *  
                 */
                
-               public Gee.ArrayList<string> filesAll(string in_path)
+               public Gee.ArrayList<string> filesAll(string in_path,bool abspath = true)
                {
                        var ret =  new Gee.ArrayList<string>();
                        
                        var dirname = this.resolve_path(
                                this.resolve_path_combine_path(this.firstPath(),in_path));
                        
-                       GLib.debug("SCAN %s\n", dirname);
+                       GLib.debug("SCAN %s", dirname);
                                // scan the directory for files -- ending with vala || c
                        
 
@@ -179,11 +183,11 @@ namespace Project {
                                GLib.debug("SCAN %s - skip - does not exist\n", dirname);
                                return ret;
                        }
-         
+                       var pathprefix = abspath ? dirname : in_path;
           
                        try {
                                var file_enum = dir.enumerate_children(
-                                       GLib.FileAttribute.STANDARD_DISPLAY_NAME
+                                       "standard::*"
                                        GLib.FileQueryInfoFlags.NONE, 
                                        null
                                );
@@ -193,9 +197,16 @@ namespace Project {
                                while ((next_file = file_enum.next_file(null)) != null) {
                                        var fn = next_file.get_display_name();
                                        
-                                       GLib.debug("SCAN %s - checking %s\n", dirname, fn);
+                                       if (next_file.get_file_type () == GLib.FileType.DIRECTORY) {
                                         
-                                       ret.add(in_path + "/" + fn);
+                                               GLib.debug("SKIP %s not regular  ", fn);
+                                               continue;
+                                       }
+                                       if (!Regex.match_simple("^text", next_file.get_content_type())) {
+                                               continue;
+                                       }
+                                       GLib.debug("SCAN ADD %s : %s", fn, next_file.get_content_type());
+                                       ret.add(pathprefix + "/" + fn);
                                         
                                        // any other valid types???
                                
@@ -208,9 +219,9 @@ namespace Project {
                        return ret;
                }
                
-               public Gee.ArrayList<string> filesForCompile(string in_path)
+               public Gee.ArrayList<string> filesForCompile(string in_path, bool abspath = true)
                {
-                       var allfile = this.fileAll();
+                       var allfiles = this.filesAll(in_path,abspath);
                        var ret =  new Gee.ArrayList<string>();
                        
                        
@@ -234,7 +245,7 @@ namespace Project {
                                        
                                         
                                        
-                                       var vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
+                                       var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
                                
                                        
                                                
@@ -249,7 +260,7 @@ namespace Project {
                        }
                        // sort.
                        ret.sort((fa,fb) => {
-                               return ((string)fa).collate(string) fb);
+                               return ((string)fa).collate((string) fb);
                        });
                        return ret;
                        
@@ -257,28 +268,63 @@ namespace Project {
                
                public Gee.ArrayList<string> filesForOpen(string in_path)
                {
-                       var allfiles = this.fileAll();
+                       var allfiles = this.filesAll(in_path);
                        var ret =  new Gee.ArrayList<string>();
-                       
+                       GLib.debug("SCAN %s - %d files",in_path, allfiles.size);
                        
                        for (var i = 0; i < allfiles.size; i ++) {
-                               var fn = cfiles.get(i);
+                               var fn = allfiles.get(i);
+                               var bn  = GLib.Path.get_basename(fn);
                                try {
                                        
                                        if (Regex.match_simple("\\.vala\\.c$", fn)) {
+                                               GLib.debug("SKIP %s - vala.c",fn);
+
                                                continue;
                                        }
                                        
                                        if (Regex.match_simple("\\.bjs$", fn)) {
+                                               GLib.debug("SKIP %s - .bjs",fn);
                                                continue;
                                        }
                                        
+                                       if (Regex.match_simple("\\~$", fn)) {
+                                               GLib.debug("SKIP %s - ~",fn);
+                                               continue;
+                                       }
+                                       if (Regex.match_simple("\\.stamp$", fn)) {
+                                               GLib.debug("SKIP %s - .o",fn);
+                                               continue;
+                                       }
+                                       if ("stamp-h1" == bn) {
+                                               GLib.debug("SKIP %s - .o",fn);
+                                               continue;
+                                       }
+                                       
+                                       // confgure.am
+                                       if ("config.h" == bn || "config.h.in" == bn || "config.log" == bn  || "configure" == bn ) {
+                                               if (allfiles.index_of( in_path +"/configure.ac") > -1) {
+                                                       continue;
+                                               }
+                                       }
+                                       // makefile
+                                       if ("Makefile" == bn || "Makefile.in" == bn ) {
+                                               if (allfiles.index_of( in_path +"/Makefile.am") > -1) {
+                                                       continue;
+                                               }
+                                       }
+                                       
+                                       if (Regex.match_simple("^\\.", bn)) {
+                                               GLib.debug("SKIP %s - hidden",fn);
+                                               continue;
+                                       }
                                        if (Regex.match_simple("\\.vala$", fn)) {
-                                               var vv = (new Regex("\\.vala$")).replace( fn, fn, 0, ".bjs");
+                                               var vv = (new Regex("\\.vala$")).replace( fn, fn.length, 0, ".bjs");
                                                if (allfiles.index_of( vv) > -1) {
+                                                       GLib.debug("SKIP %s - .vala (got bjs)",fn);
                                                        continue;
                                                }
-                                               
+                                               GLib.debug("ADD %s",fn);
                                                ret.add( fn);
                                                continue;
                                        }
@@ -287,10 +333,12 @@ namespace Project {
                                        // not a c file...
                                        if (Regex.match_simple("\\.c$", fn)) {
                                                
-                                               var vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
+                                               var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
                                                if (allfiles.index_of( vv) > -1) {
+                                                       GLib.debug("SKIP %s - .c (got vala)",fn);
                                                        continue;
                                                }
+                                               GLib.debug("ADD %s",fn);                                                
                                                ret.add( fn);
                                                continue;
                                        }
@@ -300,106 +348,24 @@ namespace Project {
                                        }
                                        // not .c / not .vala /not .bjs.. -- other type of file..
                                        // allow ???
-                                       
+                                       GLib.debug("ADD %s",fn);
                                        // add the 'c' file..
                                        ret.add(fn);
                                } catch (Error e) {
+                                       GLib.debug("Exception %s",e.message);
                                        continue;
                                }
                        }
                        // sort.
                        ret.sort((fa,fb) => {
-                               return ((string)fa).collate(string) fb);
+                               return ((string)fa).collate((string) fb);
                        });
                        return ret;
                        
                }
                
                
-               
-               
-               public Gee.ArrayList<string> files(string in_path)
-               {
-                       var ret =  new Gee.ArrayList<string>();
-                       var cfiles =  new Gee.ArrayList<string>();
-                       
-                       var dirname = this.resolve_path(
-                               this.resolve_path_combine_path(this.firstPath(),in_path));
-                       
-                       GLib.debug("SCAN %s\n", dirname);
-                               // scan the directory for files -- ending with vala || c
-                       
-
-                       var dir = File.new_for_path(dirname);
-                       if (!dir.query_exists()) {
-                               GLib.debug("SCAN %s - skip - does not exist\n", dirname);
-                               return ret;
-                       }
-         
-          
-                       try {
-                               var file_enum = dir.enumerate_children(
-                                       GLib.FileAttribute.STANDARD_DISPLAY_NAME, 
-                                       GLib.FileQueryInfoFlags.NONE, 
-                                       null
-                               );
-               
-                
-                               FileInfo next_file; 
-                               while ((next_file = file_enum.next_file(null)) != null) {
-                                       var fn = next_file.get_display_name();
-                                       
-                                       GLib.debug("SCAN %s - checking %s\n", dirname, fn);
-                                       if (Regex.match_simple("\\.vala$", fn)) {
-                                               ret.add(in_path + "/" + fn);
-                                               continue;
-                                       }
-                                       
-                                       if (Regex.match_simple("\\.vala\\.c$", fn)) {
-                                               continue;
-                                       }
-                                       if (Regex.match_simple("\\.c$", fn)) {
-                                               
-                                               // if we have a vala file with the same name 
-                                               // then do not add it...
-                                               
-                                               cfiles.add(in_path + "/" + fn);
-                                               continue;
-                                       }
-                                       // any other valid types???
-                               
-                               }
-                               
-                       } catch(Error e) {
-                               GLib.warning("oops - something went wrong scanning the projects\n");
-                       }       
-                        
-                                
-                               // add the cfiles to ret - if they do not have a vala...
-                       for (var i = 0; i < cfiles.size; i ++) {
-                               
-                               var fn = cfiles.get(i);
-                               vv = fn;
-                               try {
-                                       vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
-                               } catch (Error e) {
-                                       continue;
-                               }
-                                       
-                                               
-                               if (ret.index_of( vv) > -1) {
-                                       continue;
-                               }
-                               ret.add(fn);
-                       }
-                                               
-                        
-                       GLib.debug("SCAN %s = returning %d", dirname, ret.size);
-                        
-                       return ret;
-                       
-
-               }
+                
  
 
                public   string  resolve_path_combine_path(string first, string second)
@@ -484,7 +450,27 @@ namespace Project {
                        return ret;
                        
                }
+               public string[] sourcedirs()
+               {
+                       string[] ret = {};
+                       var sources = this.compilegroups.get("_default_").sources;
+                       ret += this.firstPath();  
+                       for(var i =0; i< sources.size; i++) {
+                               
+                               var path = this.resolve_path( this.firstPath(), sources.get(i));
+                               if (path == this.firstPath()) {
+                                       continue;
+                               }
+                               if (Path.get_basename (path) == "vapi") {
+                                       continue;
+               
+                               }
+               //                      GLib.debug("Adding VAPIDIR: %s\n", path);
+                               ret += path;            
+                       }
+                       return ret;
                        
+               }       
 
        }
        // an object describing a build config (or generic ...)
@@ -497,7 +483,9 @@ namespace Project {
                public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
                public string target_bin;
 
-
+               public string execute_args;
+               
+               
                public GtkValaSettings(string name) 
                {
                        this.name = name;
@@ -505,6 +493,7 @@ namespace Project {
                        this.target_bin = "";
                        this.packages = new Gee.ArrayList<string>();
                        this.sources = new Gee.ArrayList<string>();
+                       this.execute_args = "";
                                
                }
                
@@ -514,14 +503,19 @@ namespace Project {
                        
                        this.name = el.get_string_member("name");
                        this.compile_flags = el.get_string_member("compile_flags");
+                       if ( el.has_member("execute_args")) {
+                               this.execute_args = el.get_string_member("execute_args");
+                       } else {
+                               this.execute_args = "";
+                       }
                        this.target_bin = el.get_string_member("target_bin");
                        // sources and packages.
                        this.sources = this.readArray(el.get_array_member("sources"));
                        this.packages = this.readArray(el.get_array_member("packages"));
-                       
+
                }
                
-               
+               // why not array of strings?
                
                public Gee.ArrayList<string> readArray(Json.Array ar) 
                {
@@ -537,6 +531,7 @@ namespace Project {
                        var ret = new Json.Object();
                        ret.set_string_member("name", this.name);
                        ret.set_string_member("compile_flags", this.compile_flags);
+                       ret.set_string_member("execute_args", this.execute_args);
                        ret.set_string_member("target_bin", this.target_bin);
                        ret.set_array_member("sources", this.writeArray(this.sources));
                        ret.set_array_member("packages", this.writeArray(this.packages));