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");
70 this.spawn = new Spawn(this.project.path , args);
71 this.spawn.output_line.connect(( str) => {
74 var res = yield this.spawn.run_async();
80 if (!GLib.FileUtils.test(this.project.path + "/build", GLib.FileTest.EXISTS)) {
81 GLib.debug("build is missing");
82 return -1; //assume it's been set up.
84 var exe = GLib.Environment.find_program_in_path( "ninja");
85 string[] args = { exe };
87 this.spawn = new Spawn(this.project.path + "/build" , args);
88 this.spawn.output_line.connect(( str) => {
91 var res = yield this.spawn.run_async();
95 public void cancel() {
96 if (this.spawn != null && this.spawn.pid > 0) {
97 Posix.kill(this.spawn.pid, 9);
106 public int totalErrors(string type, JsRender.JsRender? file=null)
108 var ar = this.errorByType.get(type);
110 GLib.debug("by type has no eroros %s", type);
117 for(var i =0 ;i< ar.get_n_items();i++) {
118 var ce = (CompileError) ar.get_item(i);
120 ret += (int)ce.lines.get_n_items();
121 GLib.debug("got lines type has no eroros %s", type);
126 if (ce.file.path == file.path) {
127 ret += (int)ce.lines.get_n_items();
136 public void killChildren(int pid)
141 var cn = "/proc/%d/task/%d/children".printf(pid,pid);
142 if (!FileUtils.test(cn, GLib.FileTest.EXISTS)) {
143 GLib.debug("%s doesnt exist - killing %d", cn, pid);
149 FileUtils.get_contents(cn, out cpids);
152 if (cpids.length > 0) {
153 this.killChildren(int.parse(cpids));
156 } catch (GLib.FileError e) {
159 GLib.debug("killing %d", pid);
160 //Posix.kill(pid, 9);
163 public int terminal_pid = 0;
164 public bool execResult()
167 this.killChildren(this.terminal_pid);
168 this.terminal_pid = 0;
170 var exe = this.target;
171 var pr = (Project.Gtk) this.project;
172 var cg = pr.compilegroups.get(exe);
174 var exbin = pr.path + "/build/" + exe;
175 if (!GLib.FileUtils.test(exbin, GLib.FileTest.EXISTS)) {
176 GLib.debug("Missing output file: %s\n",exbin);
179 var gdb_cfg = pr.path + "/build/.gdb-script";
180 if (!GLib.FileUtils.test(gdb_cfg, GLib.FileTest.EXISTS)) {
181 pr.writeFile("build/.gdb-script", "set debuginfod enabled off\nr");
183 var gdb = GLib.Environment.find_program_in_path( "gdb");
184 var term = GLib.Environment.find_program_in_path( "gnome-terminal");
186 string[] args = @"$term --disable-factory --wait -- $gdb -x").split(" ");
191 if (cg.execute_args.length > 0) {
193 var aa = cg.execute_args.split(" ");
194 for (var i =0; i < aa.length; i++) {
201 // should be home directory...
206 var exec = new Spawn(pr.path , args);
207 exec.env = GLib.Environ.get();
212 this.terminal_pid = exec.pid;
213 GLib.debug("Child PID = %d", this.terminal_pid);
215 } catch(GLib.Error e) {
216 GLib.debug("Failed to spawn: %s", e.message);