aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManlio Perillo <[email protected]>2023-04-17 15:52:57 +0200
committerManlio Perillo <[email protected]>2023-04-18 12:57:03 +0200
commitc6e055dd8340981b4eedec5b6a41b944caf9c722 (patch)
treec76105c6b5603d995bcf0198a959377ef0b69f30
parentb39c7e61ef3d0b2ac28a2ce70ef549f2fac834b1 (diff)
downloadziglings-c6e055dd8340981b4eedec5b6a41b944caf9c722.tar.xz
ziglings-c6e055dd8340981b4eedec5b6a41b944caf9c722.zip
build: don't print errors in ZiglingStep.eval
Move the code for printing compiler errors and messages to the new ZiglingStep.printErrors method. Call printErrors in the Zigling.doCompile method, both in the normal and error flow. When handling an error from the Zig IPC, add the case when the compiler was unable to return the executable path. Before using the IPC, the error was "The following command exited with error code 1" now it is "The following command failed to communicate the compilation result"
-rw-r--r--build.zig47
1 files changed, 33 insertions, 14 deletions
diff --git a/build.zig b/build.zig
index d512e25..e906ee4 100644
--- a/build.zig
+++ b/build.zig
@@ -690,6 +690,9 @@ const ZiglingStep = struct {
builder: *Build,
use_healed: bool,
+ result_messages: []const u8 = "",
+ result_error_bundle: std.zig.ErrorBundle = std.zig.ErrorBundle.empty,
+
pub fn create(builder: *Build, exercise: Exercise, use_healed: bool) *@This() {
const self = builder.allocator.create(@This()) catch unreachable;
self.* = .{
@@ -829,6 +832,8 @@ const ZiglingStep = struct {
const argv = zig_args.items;
var code: u8 = undefined;
const file_name = self.eval(argv, &code, prog_node) catch |err| {
+ self.printErrors();
+
switch (err) {
error.FileNotFound => {
print("{s}{s}: Unable to spawn the following command: file not found{s}\n", .{ red_text, self.exercise.main_file, reset_text });
@@ -845,11 +850,21 @@ const ZiglingStep = struct {
for (argv) |v| print("{s} ", .{v});
print("\n", .{});
},
+ error.ZigIPCError => {
+ print("{s}{s}: The following command failed to communicate the compilation result:{s}\n", .{
+ red_text,
+ self.exercise.main_file,
+ reset_text,
+ });
+ for (argv) |v| print("{s} ", .{v});
+ print("\n", .{});
+ },
else => {},
}
return err;
};
+ self.printErrors();
return file_name;
}
@@ -908,17 +923,7 @@ const ZiglingStep = struct {
return error.ZigVersionMismatch;
},
.error_bundle => {
- const error_bundle = try ipc.parseErrorBundle(allocator, body);
-
- // Print the compiler error bundle now.
- // TODO: use the same ttyconf from the builder.
- const ttyconf: std.debug.TTY.Config = if (use_color_escapes)
- .escape_codes
- else
- .no_color;
- error_bundle.renderToStdErr(
- .{ .ttyconf = ttyconf },
- );
+ self.result_error_bundle = try ipc.parseErrorBundle(allocator, body);
},
.progress => {
node_name.clearRetainingCapacity();
@@ -937,9 +942,7 @@ const ZiglingStep = struct {
const stderr = poller.fifo(.stderr);
if (stderr.readableLength() > 0) {
- // Print the additional log and verbose messages now.
- const messages = try stderr.toOwnedSlice();
- print("{s}\n", .{messages});
+ self.result_messages = try stderr.toOwnedSlice();
}
// Send EOF to stdin.
@@ -965,6 +968,22 @@ const ZiglingStep = struct {
return result orelse return error.ZigIPCError;
}
+
+ fn printErrors(self: *ZiglingStep) void {
+ // Print the additional log and verbose messages.
+ // TODO: use colors?
+ if (self.result_messages.len > 0) print("{s}", .{self.result_messages});
+
+ // Print the compiler errors.
+ // TODO: use the same ttyconf from the builder.
+ const ttyconf: std.debug.TTY.Config = if (use_color_escapes)
+ .escape_codes
+ else
+ .no_color;
+ if (self.result_error_bundle.errorMessageCount() > 0) {
+ self.result_error_bundle.renderToStdErr(.{ .ttyconf = ttyconf });
+ }
+ }
};
// Print a message to stderr.