Skip to content

Commit 848c008

Browse files
committed
mesonproject: more detailed message on configuration failure
On configuration failure, read meson-info.json and show the error list to the user.
1 parent 516d428 commit 848c008

1 file changed

Lines changed: 59 additions & 36 deletions

File tree

‎src/projects/mesonproject.vala‎

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,47 +203,46 @@ class Vls.MesonProject : Project {
203203
Cancellable? cancellable = null) throws Error {
204204
// first, try to load the file in ${build_dir}/meson-info/intro-${command}.json
205205
try {
206-
var input_file = File.new_build_filename (build_dir, "meson-info", @"intro-$command.json");
206+
File input_file;
207+
if (command == "info")
208+
input_file = File.new_build_filename (build_dir, "meson-info", "meson-info.json");
209+
else
210+
input_file = File.new_build_filename (build_dir, "meson-info", @"intro-$command.json");
207211
debug ("loading file %s ...", input_file.get_path ());
208212
parser.load_from_stream (input_file.read (cancellable), cancellable);
209-
} catch (IOError e) {
210-
if (e is IOError.NOT_FOUND) {
211-
// retry with the other method: get output of `meson introspect --${command} ${build_dir}`
212-
string subst_command = command.replace("_", "-");
213-
string[] spawn_args = {"meson", "introspect", @"--$subst_command", "."};
214-
string proc_stdout, proc_stderr;
215-
int proc_status;
216-
217-
string command_str = "";
218-
foreach (string part in spawn_args) {
219-
if (command_str != "")
220-
command_str += " ";
221-
command_str += part;
222-
}
213+
} catch (IOError.NOT_FOUND e) {
214+
// retry with the other method: get output of `meson introspect --${command} ${build_dir}`
215+
string subst_command = command.replace("_", "-");
216+
string[] spawn_args = {"meson", "introspect", @"--$subst_command", "."};
217+
string proc_stdout, proc_stderr;
218+
int proc_status;
223219

224-
debug ("file does not exist, fallback to %s", command_str);
225-
226-
Process.spawn_sync (
227-
build_dir,
228-
spawn_args,
229-
null,
230-
SpawnFlags.SEARCH_PATH,
231-
null,
232-
out proc_stdout,
233-
out proc_stderr,
234-
out proc_status);
235-
236-
if (proc_status != 0) {
237-
warning ("command `%s' in %s failed with exit code %d\n----stdout:\n%s\n----stderr:\n%s",
238-
command_str, build_dir, proc_status, proc_stdout, proc_stderr);
239-
throw new ProjectError.INTROSPECTION (@"meson command `$command_str' failed with exit code $proc_status");
240-
}
220+
string command_str = "";
221+
foreach (string part in spawn_args) {
222+
if (command_str != "")
223+
command_str += " ";
224+
command_str += part;
225+
}
241226

242-
parser.load_from_data (proc_stdout);
243-
} else {
244-
// otherwise, rethrow
245-
throw e;
227+
debug ("file does not exist, fallback to %s", command_str);
228+
229+
Process.spawn_sync (
230+
build_dir,
231+
spawn_args,
232+
null,
233+
SpawnFlags.SEARCH_PATH,
234+
null,
235+
out proc_stdout,
236+
out proc_stderr,
237+
out proc_status);
238+
239+
if (proc_status != 0) {
240+
warning ("command `%s' in %s failed with exit code %d\n----stdout:\n%s\n----stderr:\n%s",
241+
command_str, build_dir, proc_status, proc_stdout, proc_stderr);
242+
throw new ProjectError.INTROSPECTION (@"meson command `$command_str' failed with exit code $proc_status");
246243
}
244+
245+
parser.load_from_data (proc_stdout);
247246
}
248247
}
249248

@@ -310,6 +309,30 @@ class Vls.MesonProject : Project {
310309
if (proc_status != 0) {
311310
warning ("configuration failed with exit code %d\n----stdout:\n%s\n----stderr:\n%s",
312311
proc_status, proc_stdout, proc_stderr);
312+
313+
// try to provide a more detailed error message
314+
try {
315+
var parser = new Json.Parser.immutable_new ();
316+
load_introspection_json (parser, build_dir, "info", cancellable);
317+
debug ("loaded introspection json");
318+
if (parser.get_root ()?.get_node_type () == Json.NodeType.OBJECT) {
319+
debug ("parsing 'info' json");
320+
var array = parser.get_root ().get_object ().get_array_member ("error_list");
321+
var builder = new StringBuilder ("meson configuration failed:\n");
322+
var orig_len = builder.len;
323+
array.foreach_element ((array, i, x) => {
324+
var message = x.get_string ();
325+
if (message != null)
326+
builder.append (" - ").append (message);
327+
});
328+
if (builder.len > orig_len)
329+
throw new ProjectError.CONFIGURATION (builder.str);
330+
}
331+
} catch (IOError e) {
332+
debug ("failed to load info json: %s", e.message);
333+
}
334+
335+
// fallback
313336
throw new ProjectError.CONFIGURATION (@"meson configuration failed with exit code $proc_status");
314337
}
315338

0 commit comments

Comments
 (0)