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);
110 public bool run(ValaCompileQueue 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 this.queue.onCompileFail();
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 this.queue.onCompileFail();
214 var ret = node.get_object ();
215 CompileError.parseCompileResults(this,ret);
216 this.queue.onCompileComplete(this);
222 } catch (GLib.Error e) {
223 GLib.debug("parsing output got error %s", e.message);
224 this.queue.onCompileFail();
228 if (this.requestType == ValaCompileRequestType.RUN) {
229 this.queue.execResult(this);
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(ValaCompileQueue queue)
269 var contents = this.alt_code == "" ? this.file.toSourceCode() : this.generateTempContents();
271 var ret = Javascript.singleton().validate(contents, this.file.targetName());
273 CompileError.parseCompileResults(this,ret);
274 this.queue.onCompileComplete(this);
277 // see pack file (from palete/palete..palete_palete_javascriptHasCompressionErrors.)