sync
[app.Builder.js] / src / Palete / ValaSource.vala
index ecff7cf..b171698 100644 (file)
@@ -2,18 +2,59 @@
 // valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
 
 namespace Palete {
+        
        
        public class ValaSourceReport  : Vala.Report {
 
-
+               public JsRender.JsRender file;
                
-
+               //public Gee.ArrayList<ValaSourceNotice> notices;
+                
                public Gee.HashMap<int,string> line_errors;
-
-               public ValaSourceReport()
+               
+               public void  compile_notice(string type, string filename, int line, string message) {
+                       GLib.Idle.add(() => {
+                               this.file.compile_notice(type,filename,line,message);
+                               return false;
+                       });
+               }
+               
+        
+               public ValaSourceReport(JsRender.JsRender file)
                {
                        base();
+                       this.file = file;
                        this.line_errors = new Gee.HashMap<int,string> ();
+                       //this.notices = new Gee.ArrayList<ValaSourceNotice>();
+               }
+               
+               public override void warn (Vala.SourceReference? source, string message) {
+                        
+                       if (source == null) {
+                               return;
+                               //stderr.printf ("My error: %s\n", message);
+                       }
+                       
+                       if (source.file.filename != "~~~~~testfile.vala") {
+                               this.compile_notice("WARN", source.file.filename , source.begin.line, message);
+                               return;
+                       }
+                       this.compile_notice("WARN", this.file.path, source.begin.line, message);
+                       
+               }
+               public override void depr (Vala.SourceReference? source, string message) {
+                        
+                       if (source == null) {
+                               return;
+                               //stderr.printf ("My error: %s\n", message);
+                       }
+                       
+                       if (source.file.filename != "~~~~~testfile.vala") {
+                               this.compile_notice("DEPR", source.file.filename, source.begin.line, message);
+                               return;
+                       }
+                       this.compile_notice("DEPR",  this.file.path, source.begin.line, message);
+                       
                }
                
                public override void err (Vala.SourceReference? source, string message) {
@@ -23,6 +64,7 @@ namespace Palete {
                                //stderr.printf ("My error: %s\n", message);
                        }
                        if (source.file.filename != "~~~~~testfile.vala") {
+                               this.compile_notice("ERR", source.file.filename, source.begin.line, message);
                                print ("Other file: Got error error: %d:  %s\n", source.begin.line, message);
                                return;
                        }
@@ -32,6 +74,7 @@ namespace Palete {
                                
                        }
                        line_errors.set(source.begin.line, pre +  message);
+                       this.compile_notice("ERR", this.file.path, source.begin.line, message);
                        print ("Test file: Got error error: %d: %s\n", source.begin.line, message);
                }
                public void dump()
@@ -67,11 +110,11 @@ namespace Palete {
                        return this.checkString(JsRender.NodeToVala.mungeFile(this.file));
                }
 
-               async public Gee.HashMap<int,string> checkFileWithNodePropChange(
-                          JsRender.Node node, 
-                           string prop,
-                           string ptype,
-                           string val)
+               public async Gee.HashMap<int,string> checkFileWithNodePropChange(
+                                       JsRender.Node node, 
+                                       string prop,
+                                       string ptype,
+                                       string val)
                {
                        Gee.HashMap<int,string> ret = new Gee.HashMap<int,string> ();
                        var hash = ptype == "listener" ? node.listeners : node.props;
@@ -88,6 +131,8 @@ namespace Palete {
                        
                        hash.set(prop, newval);
                        var tmpstring = JsRender.NodeToVala.mungeFile(this.file);
+                       hash.set(prop, old);
+                       //print("%s\n", tmpstring);
                        var bits = tmpstring.split("/*--VALACHECK-START--*/");
                        var offset =0;
                        if (bits.length > 0) {
@@ -96,7 +141,7 @@ namespace Palete {
                        //this.dumpCode(tmpstring);
                        //print("offset %d\n", offset);
                        yield this.checkStringThread(tmpstring);
-                       hash.set(prop, old);
+                       
                        // modify report
                        
                        var iter = this.report.line_errors.map_iterator();
@@ -132,27 +177,60 @@ namespace Palete {
                
                
                public Gee.HashMap<int,string> checkString(string contents)
-        {
+               {
                        // init context:
+                       var valac = "valac " ;
                        
                        context = new Vala.CodeContext ();
                        Vala.CodeContext.push (context);
                
                        context.experimental = false;
                        context.experimental_non_null = false;
+                       
+#if VALA_0_28
+                       var ver=28;
+#elif VALA_0_26        
+                       var ver=26;
+#elif VALA_0_24
+                       var ver=24;
+#elif VALA_0_22        
+                       var ver=22;
+#endif
+                       
+                       for (int i = 2; i <= ver; i += 2) {
+                               context.add_define ("VALA_0_%d".printf (i));
+                       }
+                       
+                       
+                       
+                       
+                       
+                       
+                       
                        var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
-                       vapidirs +=  "/usr/share/vala-0.24/vapi" ;
-
+                       // what's the current version of vala???
+                       
+                       
+                       vapidirs +=  Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
+                       
+                       for(var i =0 ; i < vapidirs.length; i++) {
+                               valac += " --vapidir=" + vapidirs[i];
+                       }
+                               
+                       
                        // or context.get_vapi_path("glib-2.0"); // should return path..
                        context.vapi_directories = vapidirs;
                        context.report.enable_warnings = true;
                        context.metadata_directories = { };
                        context.gir_directories = {};
-                       this.report = new ValaSourceReport();;
+                       context.thread = true;
+                       
+                       
+                       this.report = new ValaSourceReport(this.file);
                        context.report = this.report;
                        
                        
-                       context.basedir = Posix.realpath (".");
+                       context.basedir = "/tmp"; //Posix.realpath (".");
                
                        context.directory = context.basedir;
                
@@ -179,20 +257,37 @@ namespace Palete {
                                var cg =  pr.compilegroups.get(this.file.build_module);
                                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 == this.file.path) {
+                                                       pr.resolve_path_combine_path(pr.firstPath(),cg.sources.get(i)));
+                                                       
+                                       if (!FileUtils.test(path, FileTest.EXISTS)) {
+                                               continue;
+                                       }       
+                        
+                                       if (path == this.file.path.replace(".bjs", ".vala")) {
+                                               valac += " " + path;
                                                continue;
                                        }
                                        if (FileUtils.test(path, FileTest.IS_DIR)) {
                                                continue;
                                        }
-                                       print("Add source file %s\n", path);
+                                       //print("Add source file %s\n", path);
+                                       
+                                       valac += " " + path;
+                                       
+                                       if (Regex.match_simple("\\.c$", path)) {
+                                               context.add_c_source_file(path);
+                                               continue;
+                                       }
+                                       
+                                       
                                        var xsf = new Vala.SourceFile (
                                                context,
                                                Vala.SourceFileType.SOURCE, 
                                                path
                                        );
                                        xsf.add_using_directive (ns_ref);
+                                       context.add_source_file(xsf);
+                                       
                                }
                        }
                        // default.. packages..
@@ -202,8 +297,8 @@ namespace Palete {
                        
                var dcg = pr.compilegroups.get("_default_");
                for (var i = 0; i < dcg.packages.size; i++) {
+                               valac += " --pkg " + dcg.packages.get(i);
                                context.add_external_package (dcg.packages.get(i));
-                               
                        }
                
                         //Vala.Config.PACKAGE_SUFFIX.substring (1)
@@ -214,7 +309,7 @@ namespace Palete {
                        
                        //context.add_external_package ("libvala-0.24");
                        
-                       
+                       this.report.compile_notice("START", "", 0, "");
 
                
                        //add_documented_files (context, settings.source_files);
@@ -225,24 +320,45 @@ namespace Palete {
                        if (context.report.get_errors () > 0) {
                                print("parse got errors");
                                ((ValaSourceReport)context.report).dump();
+                               
                                Vala.CodeContext.pop ();
+                               this.report.compile_notice("END", "", 0, "");
                                return this.report.line_errors;
                        }
 
 
-                       /*
+                       
                        // check context:
                        context.check ();
                        if (context.report.get_errors () > 0) {
                                print("check got errors");
                                ((ValaSourceReport)context.report).dump();
                                Vala.CodeContext.pop ();
+                               this.report.compile_notice("END", "", 0, "");
                                return this.report.line_errors;
                                
                        }
+                       
+                       context.codegen = new Vala.GDBusServerModule ();
+                       
+                        
+                       context.output = "/tmp/testbuild";
+                       valac += " -o " +context.output;
+                       context.codegen.emit (context);
+                       /*
+                       var ccompiler = new Vala.CCodeCompiler ();
+                       var cc_command = Environment.get_variable ("CC");
+                       var pkg_config_command = Environment.get_variable ("PKG_CONFIG");
+#if VALA_0_28
+                       ccompiler.compile (context, cc_command, new string[] { }, pkg_config_command);
+#else
+                       ccompiler.compile (context, cc_command, new string[] { });
+#endif
                        */
                        Vala.CodeContext.pop ();
-                       
+                       this.report.compile_notice("END", "", 0, "");
+                       print("%s\n", valac);
                        print("ALL OK?\n");
                        return this.report.line_errors;
                }