7 public class ValaCompileRequest : Object
13 public signal void onOutput(string str);
15 public Gee.HashMap<string,GLib.ListStore>? errorByType = null;
16 public Gee.HashMap<string,GLib.ListStore>? errorByFile = null;
19 public ValaCompileRequest (
24 this.project = project;
32 public async bool run()
36 if ( this.target == "") {
37 GLib.debug("missing target");
42 BuilderApplication.showSpinner("spinner", "running meson");
44 var res = yield this.runMeson();
47 GLib.debug("Failed to run Meson");
48 BuilderApplication.showSpinner("");
51 BuilderApplication.showSpinner("spinner", "running ninja");
52 res = yield this.runNinja();
54 GLib.debug("Failed to run ninja");
58 BuilderApplication.showSpinner("");
59 return this.execResult();
63 async int runMeson() {
64 if (GLib.FileUtils.test(this.project.path + "/build/meson-info", GLib.FileTest.EXISTS)) {
65 return 0; //assume it's been set up.
67 string[] args = { "/usr/bin/meson" ,"setup", "build", "--prefix=/" };
68 GLib.debug("running meson");
69 this.spawn = new Spawn(this.project.path , args);
70 this.spawn.output_line.connect(( str) => {
73 var res = yield this.spawn.run_async();
79 if (!GLib.FileUtils.test(this.project.path + "/build", GLib.FileTest.EXISTS)) {
80 GLib.debug("build is missing");
81 return -1; //assume it's been set up.
83 string[] args = { "/usr/bin/ninja"};
85 this.spawn = new Spawn(this.project.path + "/build" , args);
86 this.spawn.output_line.connect(( str) => {
89 var res = yield this.spawn.run_async();
93 public void cancel() {
94 if (this.spawn != null && this.spawn.pid > 0) {
95 Posix.kill(this.spawn.pid, 9);
104 public int totalErrors(string type, JsRender.JsRender? file=null)
106 var ar = this.errorByType.get(type);
108 GLib.debug("by type has no eroros %s", type);
115 for(var i =0 ;i< ar.get_n_items();i++) {
116 var ce = (CompileError) ar.get_item(i);
118 ret += (int)ce.lines.get_n_items();
119 GLib.debug("got lines type has no eroros %s", type);
124 if (ce.file.path == file.path) {
125 ret += (int)ce.lines.get_n_items();
134 public void killChildren(int pid)
139 var cn = "/proc/%d/task/%d/children".printf(pid,pid);
140 if (!FileUtils.test(cn, GLib.FileTest.EXISTS)) {
141 GLib.debug("%s doesnt exist - killing %d", cn, pid);
147 FileUtils.get_contents(cn, out cpids);
150 if (cpids.length > 0) {
151 this.killChildren(int.parse(cpids));
154 } catch (GLib.FileError e) {
157 GLib.debug("killing %d", pid);
158 //Posix.kill(pid, 9);
161 public int terminal_pid = 0;
162 public bool execResult()
165 this.killChildren(this.terminal_pid);
166 this.terminal_pid = 0;
168 var exe = this.target;
169 var pr = (Project.Gtk) this.project;
170 var cg = pr.compilegroups.get(exe);
172 var exbin = pr.path + "/build/" + exe;
173 if (!GLib.FileUtils.test(exbin, GLib.FileTest.EXISTS)) {
174 GLib.debug("Missing output file: %s\n",exbin);
177 var gdb_cfg = pr.path + "/build/.gdb-script";
178 if (!GLib.FileUtils.test(gdb_cfg, GLib.FileTest.EXISTS)) {
179 pr.writeFile("build/.gdb-script", "set debuginfod enabled off\nr");
183 string[] args = "/usr/bin/gnome-terminal --disable-factory --wait -- /usr/bin/gdb -x".split(" ");
188 if (cg.execute_args.length > 0) {
190 var aa = cg.execute_args.split(" ");
191 for (var i =0; i < aa.length; i++) {
198 // should be home directory...
203 var exec = new Spawn(pr.path , args);
204 exec.env = GLib.Environ.get();
209 this.terminal_pid = exec.pid;
210 GLib.debug("Child PID = %d", this.terminal_pid);
212 } catch(GLib.Error e) {
213 GLib.debug("Failed to spawn: %s", e.message);