5 public enum ValaCompileRequestType {
12 public class ValaCompileRequest : Object
14 ValaCompileRequestType requestType;
16 public JsRender.JsRender? file = null;
17 JsRender.Node? node = null;
18 JsRender.NodeProp? prop = null;
21 Spawn? compiler = null;
22 /// ValaCompileQueue? queue = null;
26 public Gee.HashMap<string,GLib.ListStore>? errorByType = null;
27 public Gee.HashMap<string,GLib.ListStore>? errorByFile = null;
30 public ValaCompileRequest (
31 ValaCompileRequestType requestType,
32 JsRender.JsRender file ,
34 JsRender.NodeProp? prop,
38 this.requestType = requestType;
42 this.alt_code = alt_code;
44 public bool eq(ValaCompileRequest c) {
46 if (this.node == null && c.node == null) {
48 } else if (this.node == null || c.node == null) {
51 neq = this.node.oid == c.node.oid ;
55 if (this.prop == null && c.prop == null) {
57 } else if (this.prop == null || c.prop == null) {
60 peq = this.prop.name == c.prop.name ;
65 this.requestType == c.requestType &&
66 this.file.path == c.file.path &&
68 this.alt_code == c.alt_code;
73 public string target()
75 var pr = (Project.Gtk) this.file.project;
76 return pr.firstBuildModuleWith(this.file);
80 string generateTempContents() {
83 var contents = this.alt_code;
84 if (this.requestType == ValaCompileRequestType.PROP_CHANGE) {
85 oldcode = this.prop.val;
86 this.prop.val = this.alt_code;
87 contents = this.file.toSourceCode();
88 this.prop.val = oldcode;
94 bool generateTempFile() {
96 var contents = this.generateTempContents();
98 var pr = this.file.project;
100 this.tmpfile = pr.path + "/build/tmp-%u.vala".printf( (uint) GLib.get_real_time()) ;
102 GLib.FileUtils.set_contents(this.tmpfile,contents);
103 } catch (GLib.FileError e) {
104 GLib.debug("Error creating temp build file %s : %s", tmpfile, e.message);
112 //this.queue = queue;
113 if ( this.target() == "") {
114 GLib.debug("missing target");
115 this.onCompileFail();
120 args += BuilderApplication._self;
121 if (this.requestType != ValaCompileRequestType.RUN) {
122 args += "--skip-linking";
125 args += this.file.project.path;
127 args += this.target();
128 if (this.requestType == ValaCompileRequestType.PROP_CHANGE || this.requestType == ValaCompileRequestType.FILE_CHANGE) {
130 if (!this.generateTempFile()) {
131 GLib.debug("failed to make temp file");
132 this.onCompileFail();
135 args += "--add-file";
136 args += this.tmpfile;
137 args += "--skip-file";
138 args += this.file.targetName(); // ?? bjs???
140 var pr = (Project.Gtk)(file.project);
142 pr.makeProjectSubdir("build");
143 this.compiler = new Spawn(pr.path + "/build", args);
144 } catch (GLib.Error e) {
145 GLib.debug("Spawn failed: %s", e.message);
147 this.onCompileFail();
150 this.compiler.output_line.connect(this.onOutput);
151 this.compiler.complete.connect(this.onCompileComplete);
154 } catch (GLib.Error e) {
155 GLib.debug("Spawn error %s", e.message);
156 this.onCompileFail();
159 return true; // it's running..
161 void onCompileFail() // only called before we start (assumes spinner has nto started etc..
163 this.compiler = null;
167 public void cancel() {
168 if (this.compiler != null && this.compiler.pid > 0) {
169 Posix.kill(this.compiler.pid, 9);
171 this.compiler = null;
175 public void deleteTemp()
177 if (this.tmpfile == "") {
180 if (GLib.FileUtils.test(this.tmpfile, GLib.FileTest.EXISTS)) {
181 GLib.FileUtils.unlink(this.tmpfile);
183 var cf = this.tmpfile.substring(0, this.tmpfile.length-4) + "c";
184 GLib.debug("try remove %s",cf);
185 if (GLib.FileUtils.test(cf, GLib.FileTest.EXISTS)) {
186 GLib.FileUtils.unlink(cf);
188 var ccf = GLib.Path.get_dirname(cf) + "/build/" + GLib.Path.get_basename(cf);
189 GLib.debug("try remove %s",ccf);
190 if (GLib.FileUtils.test(ccf, GLib.FileTest.EXISTS)) {
191 GLib.FileUtils.unlink(ccf);
195 public void onCompileComplete(int res, string output, string stderr)
198 this.compiler.isZombie();
199 GLib.debug("compile got %s", output);
201 BuilderApplication.showSpinner("face-sad", "compile failed - no error message?");
204 if (this.requestType == ValaCompileRequestType.RUN) {
205 BuilderApplication.showSpinner("");
210 // below is not used anymore - as we dont use this
212 //GLib.debug("GOT output %s", output);
214 var pa = new Json.Parser();
215 pa.load_from_data(output);
216 var node = pa.get_root();
218 if (node.get_node_type () != Json.NodeType.OBJECT) {
219 BuilderApplication.showSpinner("");
222 var ret = node.get_object ();
223 //CompileError.parseCompileResults(this,ret);
224 BuilderApplication.showSpinner("");
230 } catch (GLib.Error e) {
231 GLib.debug("parsing output got error %s", e.message);
232 BuilderApplication.showSpinner("");
238 public void onOutput(string line)
243 public int totalErrors(string type, JsRender.JsRender? file=null)
245 var ar = this.errorByType.get(type);
247 GLib.debug("by type has no eroros %s", type);
254 for(var i =0 ;i< ar.get_n_items();i++) {
255 var ce = (CompileError) ar.get_item(i);
257 ret += (int)ce.lines.get_n_items();
258 GLib.debug("got lines type has no eroros %s", type);
263 if (ce.file.path == file.path) {
264 ret += (int)ce.lines.get_n_items();
270 public void runJavascript( )
272 //this.queue = queue;
274 var contents = this.alt_code == "" ? this.file.toSourceCode() : this.generateTempContents();
276 Javascript.singleton().validate(contents, this.file );
279 BuilderApplication.showSpinner("");
280 BuilderApplication.updateCompileResults();
282 //this.queue.onCompileComplete(this);
285 // see pack file (from palete/palete..palete_palete_javascriptHasCompressionErrors.)
288 public void killChildren(int pid)
293 var cn = "/proc/%d/task/%d/children".printf(pid,pid);
294 if (!FileUtils.test(cn, GLib.FileTest.EXISTS)) {
295 GLib.debug("%s doesnt exist - killing %d", cn, pid);
301 FileUtils.get_contents(cn, out cpids);
304 if (cpids.length > 0) {
305 this.killChildren(int.parse(cpids));
308 } catch (GLib.FileError e) {
311 GLib.debug("killing %d", pid);
312 //Posix.kill(pid, 9);
315 public int terminal_pid = 0;
316 public void execResult()
319 this.killChildren(this.terminal_pid);
320 this.terminal_pid = 0;
322 var exe = this.target();
323 var pr = (Project.Gtk) this.file.project;
324 var cg = pr.compilegroups.get(exe);
326 var exbin = pr.path + "/build/" + exe;
327 if (!GLib.FileUtils.test(exbin, GLib.FileTest.EXISTS)) {
328 GLib.debug("Missing output file: %s\n",exbin);
331 var gdb_cfg = pr.path + "/build/.gdb-script";
332 if (!GLib.FileUtils.test(gdb_cfg, GLib.FileTest.EXISTS)) {
333 pr.writeFile("build/.gdb-script", "set debuginfod enabled off\nr");
337 string[] args = "/usr/bin/gnome-terminal --disable-factory --wait -- /usr/bin/gdb -x".split(" ");
342 if (cg.execute_args.length > 0) {
344 var aa = cg.execute_args.split(" ");
345 for (var i =0; i < aa.length; i++) {
352 // should be home directory...
357 var exec = new Spawn(pr.path , args);
358 exec.env = GLib.Environ.get();
363 this.terminal_pid = exec.pid;
364 GLib.debug("Child PID = %d", this.terminal_pid);
366 } catch(GLib.Error e) {
367 GLib.debug("Failed to spawn: %s", e.message);