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 Posix.kill(this.compiler.pid, 9);
169 this.compiler = null;
173 public void deleteTemp()
175 if (this.tmpfile == "") {
178 if (GLib.FileUtils.test(this.tmpfile, GLib.FileTest.EXISTS)) {
179 GLib.FileUtils.unlink(this.tmpfile);
181 var cf = this.tmpfile.substring(0, this.tmpfile.length-4) + "c";
182 GLib.debug("try remove %s",cf);
183 if (GLib.FileUtils.test(cf, GLib.FileTest.EXISTS)) {
184 GLib.FileUtils.unlink(cf);
186 var ccf = GLib.Path.get_dirname(cf) + "/build/" + GLib.Path.get_basename(cf);
187 GLib.debug("try remove %s",ccf);
188 if (GLib.FileUtils.test(ccf, GLib.FileTest.EXISTS)) {
189 GLib.FileUtils.unlink(ccf);
193 public void onCompileComplete(int res, string output, string stderr)
196 this.compiler.isZombie();
197 GLib.debug("compile got %s", output);
199 BuilderApplication.showSpinner(false);
204 //GLib.debug("GOT output %s", output);
206 var pa = new Json.Parser();
207 pa.load_from_data(output);
208 var node = pa.get_root();
210 if (node.get_node_type () != Json.NodeType.OBJECT) {
211 BuilderApplication.showSpinner(false);
214 var ret = node.get_object ();
215 //CompileError.parseCompileResults(this,ret);
216 BuilderApplication.showSpinner(false);
222 } catch (GLib.Error e) {
223 GLib.debug("parsing output got error %s", e.message);
224 BuilderApplication.showSpinner(false);
228 if (this.requestType == ValaCompileRequestType.RUN) {
233 public void onOutput(string line)
238 public int totalErrors(string type, JsRender.JsRender? file=null)
240 var ar = this.errorByType.get(type);
242 GLib.debug("by type has no eroros %s", type);
249 for(var i =0 ;i< ar.get_n_items();i++) {
250 var ce = (CompileError) ar.get_item(i);
252 ret += (int)ce.lines.get_n_items();
253 GLib.debug("got lines type has no eroros %s", type);
258 if (ce.file.path == file.path) {
259 ret += (int)ce.lines.get_n_items();
265 public void runJavascript( )
267 //this.queue = queue;
269 var contents = this.alt_code == "" ? this.file.toSourceCode() : this.generateTempContents();
271 Javascript.singleton().validate(contents, this.file );
275 BuilderApplication.showSpinner(false);
276 BuilderApplication.updateCompileResults();
278 //this.queue.onCompileComplete(this);
281 // see pack file (from palete/palete..palete_palete_javascriptHasCompressionErrors.)
284 public void killChildren(int pid)
289 var cn = "/proc/%d/task/%d/children".printf(pid,pid);
290 if (!FileUtils.test(cn, GLib.FileTest.EXISTS)) {
291 GLib.debug("%s doesnt exist - killing %d", cn, pid);
297 FileUtils.get_contents(cn, out cpids);
300 if (cpids.length > 0) {
301 this.killChildren(int.parse(cpids));
304 } catch (GLib.FileError e) {
307 GLib.debug("killing %d", pid);
311 int terminal_pid = 0;
312 public void execResult()
315 this.killChildren(this.terminal_pid);
316 this.terminal_pid = 0;
318 var exe = this.target();
319 var pr = (Project.Gtk) this.file.project;
320 var cg = pr.compilegroups.get(exe);
322 if (!GLib.FileUtils.test(exe, GLib.FileTest.EXISTS)) {
323 print("Missing output file: %s\n",exe);
326 var gdb_cfg= pr.path + "/build/.gdb-script";
327 if (!GLib.FileUtils.test(gdb_cfg, GLib.FileTest.EXISTS)) {
328 pr.writeFile("build/.gdb-script", "set debuginfod enabled off\nr");
333 string[] args = "/usr/bin/gnome-terminal --disable-factory --wait -- /usr/bin/gdb -x".split(" ");
338 if (cg.execute_args.length > 0) {
340 var aa = cg.execute_args.split(" ");
341 for (var i =0; i < aa.length; i++) {
348 // should be home directory...
353 var exec = new Spawn(pr.path , args);
354 exec.env = GLib.Environ.get();
359 this.terminal_pid = exec.pid;
360 GLib.debug("Child PID = %d", this.terminal_pid);
362 } catch(GLib.Error e) {
363 GLib.debug("Failed to spawn: %s", e.message);