src/Builder4/About.vala.c
[app.Builder.js] / src / Palete / ValaSource.vala
index bdc1920..33d6be3 100644 (file)
@@ -36,7 +36,7 @@ namespace Palete {
                public ValaSource( ) 
                {
                        base();
-                
+                       this.compiler = null;
                }
                public void dumpCode(string str) 
                {
@@ -51,7 +51,7 @@ namespace Palete {
                //      return this.checkString(JsRender.NodeToVala.mungeFile(this.file));
                //}
 
-               public void checkFileWithNodePropChange(
+               public bool checkFileWithNodePropChange(
                  
                                        JsRender.JsRender file,
                                        JsRender.Node node, 
@@ -62,15 +62,17 @@ namespace Palete {
                {
                        this.file = file;
                        
+                       if (this.compiler != null) {
+                               return false;
+                       }
                        
-                       Gee.HashMap<int,string> ret = new Gee.HashMap<int,string> ();
+                        
                        var hash = ptype == "listener" ? node.listeners : node.props;
                        
                        // untill we get a smarter renderer..
                        // we have some scenarios where changing the value does not work
                        if (prop == "* xns" || prop == "xtype") {
-                               this.compiled(new Json.Object());
-                               return ;
+                               return  false;
                        }
                                
                        
@@ -91,7 +93,7 @@ namespace Palete {
                        
                        //this.dumpCode(tmpstring);
                        //print("offset %d\n", offset);
-                       this.checkStringSpawn(tmpstring );
+                       return this.checkStringSpawn(tmpstring );
                        
                        // modify report
                        
@@ -100,11 +102,15 @@ namespace Palete {
                }
                Spawn compiler;
                 
-               public void checkStringSpawn(
-                                       string contents 
-                               )
+               public bool checkStringSpawn(
+                               string contents 
+                       )
                {
                        
+                       if (this.compiler != null) {
+                               return false;
+                       }
+                       
                        FileIOStream iostream;
                        var tmpfile = File.new_tmp ("test-XXXXXX.vala", out iostream);
                        tmpfile.ref();
@@ -117,14 +123,10 @@ namespace Palete {
                        try {             
                           var  regex = new Regex("\\.bjs$");
                        
-                        
-                               valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
+                               valafn = regex.replace(this.file.path,this.file.path.length , 0 , ".vala");
                         } catch (GLib.RegexError e) {
-                               var ret = new Json.Object();
-                               ret.set_boolean_member("success", false);
-                               ret.set_string_member("message", e.message);
-                           this.compiled(ret);
-                           return;
+                                
+                           return false;
                        }   
                        
                        string[] args = {};
@@ -146,26 +148,144 @@ namespace Palete {
                        try {
                                this.compiler.run(); 
                        } catch (GLib.SpawnError e) {
-                               var ret = new Json.Object();
-                               ret.set_boolean_member("success", false);
-                               ret.set_string_member("message", e.message);
-                           this.compiled(ret);
+                               GLib.debug(e.message);
+                               this.compiler = null;
+                               return false;
+
+                       }
+                       return true;
+                        
+               }
+               
+               public bool checkFileSpawn(JsRender.JsRender file )
+               {
+                       // race condition..
+                       if (this.compiler != null) { 
+                               return false;
+                       }
+                       
+                       this.file = file;
+                       this.line_offset = 0;
+                         
+                       string[] args = {};
+                       args += BuilderApplication._self;
+                       args += "--project";
+                       args += this.file.project.fn;
+                       args += "--target";
+                       args += this.file.build_module;
+                        
+                        
+                       
+                       
+                       try {
+                           this.compiler = new Spawn("/tmp", args);
+                           this.compiler.complete.connect(spawnResult);
+                       
+                           this.compiler.run(); 
+                       
+                        
+                       } catch (GLib.Error e) {
+                           GLib.debug(e.message);
+                           this.compiler = null;
+                           return false;
+                       }
+                       return true;
+                        
+               }
+               /**
+               * Used to compile a non builder file..
+               */
+                
+               public bool checkPlainFileSpawn(  JsRender.JsRender file, string contents )
+               {
+                       // race condition..
+                       if (this.compiler != null) { 
+                               return false;
+                       }
+                       var pr = (Project.Gtk)(file.project);
+                       
+                       var m = pr.firstBuildModule();
+                       var cg = pr.compilegroups.get(m);
+                       var foundit = false;
+                       for (var i = 0; i < cg.sources.size; i++) {
+                           var path = pr.resolve_path(
+                                   pr.resolve_path_combine_path(pr.firstPath(),cg.sources.get(i)));
+                           if (path == file.path) {
+                               foundit = true;
+                               break;
+                                       }
+                       
+                       }
+                       if (!foundit) {
+                         
+                           this.compiler = null;
+                       
+                           return false; // do not run the compile..
+                       }
+                       // is the file in the module?
+                       
+                       
+                       FileIOStream iostream;
+                       var tmpfile = File.new_tmp ("test-XXXXXX.vala", out iostream);
+                       tmpfile.ref();
+
+                       OutputStream ostream = iostream.output_stream;
+                       DataOutputStream dostream = new DataOutputStream (ostream);
+                       dostream.put_string (contents);
+                       
+                       
+                       this.file = null;
+                       this.line_offset = 0;
+                         
+                       string[] args = {};
+                       args += BuilderApplication._self;
+                       args += "--project";
+                       args +=  file.project.fn;
+                       args += "--target";
+                       args += pr.firstBuildModule();
+                       args += "--add-file";
+                       args +=  tmpfile.get_path();
+                       args += "--skip-file";
+                       args += file.path;
+                        
+                       
+                       
+                       
+                       try {
+                           this.compiler = new Spawn("/tmp", args);
+                           this.compiler.complete.connect(spawnResult);
+                           this.compiler.run(); 
+                       } catch (GLib.Error e) {
+                           
+                           this.compiler = null;
+                           return false;
                        }
+                       return true;
                         
                }
+               
+               
                public void spawnResult(int res, string output, string stderr)
                {
                         
                                
                        try { 
-                               GLib.debug("GOT output %s", output);
+                               //GLib.debug("GOT output %s", output);
                                
                                var pa = new Json.Parser();
                                pa.load_from_data(output);
                                var node = pa.get_root();
 
                                if (node.get_node_type () != Json.NodeType.OBJECT) {
-                                       throw new ValaSourceError.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
+                                       var ret = new Json.Object();
+                                       ret.set_boolean_member("success", false);
+                                       ret.set_string_member("message", 
+                                               "Compiler returned Unexpected element type %s".printf( 
+                                                       node.type_name ()
+                                               )
+                                       );
+                                       this.compiled(ret);
+                                       this.compiler = null;
                                }
                                var ret = node.get_object ();
                                ret.set_int_member("line_offset", this.line_offset);
@@ -173,12 +293,13 @@ namespace Palete {
                                this.compiled(ret);
                                
                                
-                       } catch (Error e) {
+                       } catch (GLib.Error e) {
                                var ret = new Json.Object();
                                ret.set_boolean_member("success", false);
                                ret.set_string_member("message", e.message);
                                this.compiled(ret);
                        }
+                       this.compiler = null;
                        //compiler.unref();
                        //tmpfile.unref();