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 var exe = GLib.Environment.find_program_in_path( "meson");
68 string[] args = { exe ,"setup", "build", "--prefix=/usr" };
69 GLib.debug("running meson");
71 this.spawn = new Spawn(this.project.path , args);
72 } catch (GLib.Error e) {
75 this.spawn.output_line.connect(( str) => {
78 var res = yield this.spawn.run_async();
84 if (!GLib.FileUtils.test(this.project.path + "/build", GLib.FileTest.EXISTS)) {
85 GLib.debug("build is missing");
86 return -1; //assume it's been set up.
88 var exe = GLib.Environment.find_program_in_path( "ninja");
89 string[] args = { exe };
91 this.spawn = new Spawn(this.project.path + "/build" , args);
92 } catch (GLib.Error e) {
95 this.spawn.output_line.connect(( str) => {
98 var res = yield this.spawn.run_async();
102 public void cancel() {
103 if (this.spawn != null && this.spawn.pid > 0) {
104 Posix.kill(this.spawn.pid, 9);
113 public int totalErrors(string type, JsRender.JsRender? file=null)
115 var ar = this.errorByType.get(type);
117 GLib.debug("by type has no eroros %s", type);
124 for(var i =0 ;i< ar.get_n_items();i++) {
125 var ce = (CompileError) ar.get_item(i);
127 ret += (int)ce.lines.get_n_items();
128 GLib.debug("got lines type has no eroros %s", type);
133 if (ce.file.path == file.path) {
134 ret += (int)ce.lines.get_n_items();
143 public void killChildren(int pid)
148 var cn = "/proc/%d/task/%d/children".printf(pid,pid);
149 if (!FileUtils.test(cn, GLib.FileTest.EXISTS)) {
150 GLib.debug("%s doesnt exist - killing %d", cn, pid);
156 FileUtils.get_contents(cn, out cpids);
159 if (cpids.length > 0) {
160 this.killChildren(int.parse(cpids));
163 } catch (GLib.FileError e) {
166 GLib.debug("killing %d", pid);
167 //Posix.kill(pid, 9);
170 public int terminal_pid = 0;
171 public bool execResult()
174 this.killChildren(this.terminal_pid);
175 this.terminal_pid = 0;
177 var exe = this.target;
178 var pr = (Project.Gtk) this.project;
179 var cg = pr.compilegroups.get(exe);
181 var exbin = pr.path + "/build/" + exe;
182 if (!GLib.FileUtils.test(exbin, GLib.FileTest.EXISTS)) {
183 GLib.debug("Missing output file: %s\n",exbin);
186 var gdb_cfg = pr.path + "/build/.gdb-script";
187 if (!GLib.FileUtils.test(gdb_cfg, GLib.FileTest.EXISTS)) {
188 pr.writeFile("build/.gdb-script", "set debuginfod enabled off\nr");
190 var gdb = GLib.Environment.find_program_in_path( "gdb");
191 var term = GLib.Environment.find_program_in_path( "gnome-terminal");
193 string[] args = @"$term --disable-factory --wait -- $gdb -x".split(" ");
198 if (cg.execute_args.length > 0) {
200 var aa = cg.execute_args.split(" ");
201 for (var i =0; i < aa.length; i++) {
208 // should be home directory...
213 var exec = new Spawn(pr.path , args);
214 exec.env = GLib.Environ.get();
219 this.terminal_pid = exec.pid;
220 GLib.debug("Child PID = %d", this.terminal_pid);
222 } catch(GLib.Error e) {
223 GLib.debug("Failed to spawn: %s", e.message);