authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-14 16:12:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:15-07:00
log363d4a107de3af95620f82e851e8777aa9f576c9
tree14a7536caf8366329f0f2f9286fa539d0fab3db2
parented33901218363b9d1baee4c37e85f573dc034e06

add compile log output to build runner


4 files changed, 38 insertions(+), 19 deletions(-)

lib/std/zig/ErrorBundle.zig+28-1
...@@ -32,6 +32,8 @@ pub const SourceLocationIndex = enum(u32) {...@@ -32,6 +32,8 @@ pub const SourceLocationIndex = enum(u32) {
32pub const ErrorMessageList = struct {32pub const ErrorMessageList = struct {
33 len: u32,33 len: u32,
34 start: u32,34 start: u32,
35 /// null-terminated string index. 0 means no compile log text.
36 compile_log_text: u32,
35};37};
3638
37/// Trailing:39/// Trailing:
...@@ -110,6 +112,10 @@ pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {...@@ -110,6 +112,10 @@ pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {
110 return @ptrCast([]const MessageIndex, eb.extra[start..][0..notes_len]);112 return @ptrCast([]const MessageIndex, eb.extra[start..][0..notes_len]);
111}113}
112114
115pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {
116 return nullTerminatedString(eb, getErrorMessageList(eb).compile_log_text);
117}
118
113/// Returns the requested data, as well as the new index which is at the start of the119/// Returns the requested data, as well as the new index which is at the start of the
114/// trailers for the object.120/// trailers for the object.
115fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } {121fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } {
...@@ -145,6 +151,7 @@ pub const RenderOptions = struct {...@@ -145,6 +151,7 @@ pub const RenderOptions = struct {
145 ttyconf: std.debug.TTY.Config,151 ttyconf: std.debug.TTY.Config,
146 include_reference_trace: bool = true,152 include_reference_trace: bool = true,
147 include_source_line: bool = true,153 include_source_line: bool = true,
154 include_log_text: bool = true,
148};155};
149156
150pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {157pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {
...@@ -158,6 +165,14 @@ pub fn renderToWriter(eb: ErrorBundle, options: RenderOptions, writer: anytype)...@@ -158,6 +165,14 @@ pub fn renderToWriter(eb: ErrorBundle, options: RenderOptions, writer: anytype)
158 for (eb.getMessages()) |err_msg| {165 for (eb.getMessages()) |err_msg| {
159 try renderErrorMessageToWriter(eb, options, err_msg, writer, "error", .Red, 0);166 try renderErrorMessageToWriter(eb, options, err_msg, writer, "error", .Red, 0);
160 }167 }
168
169 if (options.include_log_text) {
170 const log_text = eb.getCompileLogOutput();
171 if (log_text.len != 0) {
172 try writer.writeAll("\nCompile Log Output:\n");
173 try writer.writeAll(log_text);
174 }
175 }
161}176}
162177
163fn renderErrorMessageToWriter(178fn renderErrorMessageToWriter(
...@@ -314,6 +329,7 @@ pub const Wip = struct {...@@ -314,6 +329,7 @@ pub const Wip = struct {
314 assert(0 == try addExtra(wip, ErrorMessageList{329 assert(0 == try addExtra(wip, ErrorMessageList{
315 .len = 0,330 .len = 0,
316 .start = 0,331 .start = 0,
332 .compile_log_text = 0,
317 }));333 }));
318 }334 }
319335
...@@ -325,9 +341,10 @@ pub const Wip = struct {...@@ -325,9 +341,10 @@ pub const Wip = struct {
325 wip.* = undefined;341 wip.* = undefined;
326 }342 }
327343
328 pub fn toOwnedBundle(wip: *Wip) !ErrorBundle {344 pub fn toOwnedBundle(wip: *Wip, compile_log_text: []const u8) !ErrorBundle {
329 const gpa = wip.gpa;345 const gpa = wip.gpa;
330 if (wip.root_list.items.len == 0) {346 if (wip.root_list.items.len == 0) {
347 assert(compile_log_text.len == 0);
331 // Special encoding when there are no errors.348 // Special encoding when there are no errors.
332 wip.deinit();349 wip.deinit();
333 wip.* = .{350 wip.* = .{
...@@ -338,9 +355,19 @@ pub const Wip = struct {...@@ -338,9 +355,19 @@ pub const Wip = struct {
338 };355 };
339 return empty;356 return empty;
340 }357 }
358
359 const compile_log_str_index = if (compile_log_text.len == 0) 0 else str: {
360 const str = @intCast(u32, wip.string_bytes.items.len);
361 try wip.string_bytes.ensureUnusedCapacity(gpa, compile_log_text.len + 1);
362 wip.string_bytes.appendSliceAssumeCapacity(compile_log_text);
363 wip.string_bytes.appendAssumeCapacity(0);
364 break :str str;
365 };
366
341 wip.setExtra(0, ErrorMessageList{367 wip.setExtra(0, ErrorMessageList{
342 .len = @intCast(u32, wip.root_list.items.len),368 .len = @intCast(u32, wip.root_list.items.len),
343 .start = @intCast(u32, wip.extra.items.len),369 .start = @intCast(u32, wip.extra.items.len),
370 .compile_log_text = compile_log_str_index,
344 });371 });
345 try wip.extra.appendSlice(gpa, @ptrCast([]const u32, wip.root_list.items));372 try wip.extra.appendSlice(gpa, @ptrCast([]const u32, wip.root_list.items));
346 wip.root_list.clearAndFree(gpa);373 wip.root_list.clearAndFree(gpa);
src/Compilation.zig+2-6
...@@ -2705,7 +2705,8 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {...@@ -2705,7 +2705,8 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
27052705
2706 assert(self.totalErrorCount() == bundle.root_list.items.len);2706 assert(self.totalErrorCount() == bundle.root_list.items.len);
27072707
2708 return bundle.toOwnedBundle();2708 const compile_log_text = if (self.bin_file.options.module) |m| m.compile_log_text.items else "";
2709 return bundle.toOwnedBundle(compile_log_text);
2709}2710}
27102711
2711pub const ErrorNoteHashContext = struct {2712pub const ErrorNoteHashContext = struct {
...@@ -2954,11 +2955,6 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {...@@ -2954,11 +2955,6 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void {
2954 }2955 }
2955}2956}
29562957
2957pub fn getCompileLogOutput(self: *Compilation) []const u8 {
2958 const module = self.bin_file.options.module orelse return &[0]u8{};
2959 return module.compile_log_text.items;
2960}
2961
2962pub fn performAllTheWork(2958pub fn performAllTheWork(
2963 comp: *Compilation,2959 comp: *Compilation,
2964 main_progress_node: *std.Progress.Node,2960 main_progress_node: *std.Progress.Node,
src/Sema.zig+1-1
...@@ -2219,7 +2219,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {...@@ -2219,7 +2219,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
2219 wip_errors.init(gpa) catch unreachable;2219 wip_errors.init(gpa) catch unreachable;
2220 Compilation.addModuleErrorMsg(&wip_errors, err_msg.*) catch unreachable;2220 Compilation.addModuleErrorMsg(&wip_errors, err_msg.*) catch unreachable;
2221 std.debug.print("compile error during Sema:\n", .{});2221 std.debug.print("compile error during Sema:\n", .{});
2222 var error_bundle = wip_errors.toOwnedBundle() catch unreachable;2222 var error_bundle = wip_errors.toOwnedBundle("") catch unreachable;
2223 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });2223 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });
2224 crash_report.compilerPanic("unexpected compile error occurred", null, null);2224 crash_report.compilerPanic("unexpected compile error occurred", null, null);
2225 }2225 }
src/main.zig+7-11
...@@ -3886,10 +3886,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void...@@ -3886,10 +3886,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void
38863886
3887 if (errors.errorMessageCount() > 0) {3887 if (errors.errorMessageCount() > 0) {
3888 errors.renderToStdErr(renderOptions(comp.color));3888 errors.renderToStdErr(renderOptions(comp.color));
3889 const log_text = comp.getCompileLogOutput();
3890 if (log_text.len != 0) {
3891 std.debug.print("\nCompile Log Output:\n{s}", .{log_text});
3892 }
3893 return error.SemanticAnalyzeFail;3889 return error.SemanticAnalyzeFail;
3894 } else switch (hook) {3890 } else switch (hook) {
3895 .none => {},3891 .none => {},
...@@ -4512,7 +4508,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4512,7 +4508,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4512 &all_modules,4508 &all_modules,
4513 );4509 );
4514 if (wip_errors.root_list.items.len > 0) {4510 if (wip_errors.root_list.items.len > 0) {
4515 var errors = try wip_errors.toOwnedBundle();4511 var errors = try wip_errors.toOwnedBundle("");
4516 defer errors.deinit(gpa);4512 defer errors.deinit(gpa);
4517 errors.renderToStdErr(renderOptions(color));4513 errors.renderToStdErr(renderOptions(color));
4518 process.exit(1);4514 process.exit(1);
...@@ -4775,7 +4771,7 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -4775,7 +4771,7 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
4775 try wip_errors.init(gpa);4771 try wip_errors.init(gpa);
4776 defer wip_errors.deinit();4772 defer wip_errors.deinit();
4777 try Compilation.addZirErrorMessages(&wip_errors, &file);4773 try Compilation.addZirErrorMessages(&wip_errors, &file);
4778 var error_bundle = try wip_errors.toOwnedBundle();4774 var error_bundle = try wip_errors.toOwnedBundle("");
4779 defer error_bundle.deinit(gpa);4775 defer error_bundle.deinit(gpa);
4780 error_bundle.renderToStdErr(renderOptions(color));4776 error_bundle.renderToStdErr(renderOptions(color));
4781 process.exit(2);4777 process.exit(2);
...@@ -4981,7 +4977,7 @@ fn fmtPathFile(...@@ -4981,7 +4977,7 @@ fn fmtPathFile(
4981 try wip_errors.init(gpa);4977 try wip_errors.init(gpa);
4982 defer wip_errors.deinit();4978 defer wip_errors.deinit();
4983 try Compilation.addZirErrorMessages(&wip_errors, &file);4979 try Compilation.addZirErrorMessages(&wip_errors, &file);
4984 var error_bundle = try wip_errors.toOwnedBundle();4980 var error_bundle = try wip_errors.toOwnedBundle("");
4985 defer error_bundle.deinit(gpa);4981 defer error_bundle.deinit(gpa);
4986 error_bundle.renderToStdErr(renderOptions(fmt.color));4982 error_bundle.renderToStdErr(renderOptions(fmt.color));
4987 fmt.any_error = true;4983 fmt.any_error = true;
...@@ -5018,7 +5014,7 @@ fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color: Co...@@ -5018,7 +5014,7 @@ fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color: Co
50185014
5019 try putAstErrorsIntoBundle(gpa, tree, path, &wip_errors);5015 try putAstErrorsIntoBundle(gpa, tree, path, &wip_errors);
50205016
5021 var error_bundle = try wip_errors.toOwnedBundle();5017 var error_bundle = try wip_errors.toOwnedBundle("");
5022 defer error_bundle.deinit(gpa);5018 defer error_bundle.deinit(gpa);
5023 error_bundle.renderToStdErr(renderOptions(color));5019 error_bundle.renderToStdErr(renderOptions(color));
5024}5020}
...@@ -5622,7 +5618,7 @@ pub fn cmdAstCheck(...@@ -5622,7 +5618,7 @@ pub fn cmdAstCheck(
5622 try wip_errors.init(gpa);5618 try wip_errors.init(gpa);
5623 defer wip_errors.deinit();5619 defer wip_errors.deinit();
5624 try Compilation.addZirErrorMessages(&wip_errors, &file);5620 try Compilation.addZirErrorMessages(&wip_errors, &file);
5625 var error_bundle = try wip_errors.toOwnedBundle();5621 var error_bundle = try wip_errors.toOwnedBundle("");
5626 defer error_bundle.deinit(gpa);5622 defer error_bundle.deinit(gpa);
5627 error_bundle.renderToStdErr(renderOptions(color));5623 error_bundle.renderToStdErr(renderOptions(color));
5628 process.exit(1);5624 process.exit(1);
...@@ -5739,7 +5735,7 @@ pub fn cmdChangelist(...@@ -5739,7 +5735,7 @@ pub fn cmdChangelist(
5739 try wip_errors.init(gpa);5735 try wip_errors.init(gpa);
5740 defer wip_errors.deinit();5736 defer wip_errors.deinit();
5741 try Compilation.addZirErrorMessages(&wip_errors, &file);5737 try Compilation.addZirErrorMessages(&wip_errors, &file);
5742 var error_bundle = try wip_errors.toOwnedBundle();5738 var error_bundle = try wip_errors.toOwnedBundle("");
5743 defer error_bundle.deinit(gpa);5739 defer error_bundle.deinit(gpa);
5744 error_bundle.renderToStdErr(renderOptions(color));5740 error_bundle.renderToStdErr(renderOptions(color));
5745 process.exit(1);5741 process.exit(1);
...@@ -5774,7 +5770,7 @@ pub fn cmdChangelist(...@@ -5774,7 +5770,7 @@ pub fn cmdChangelist(
5774 try wip_errors.init(gpa);5770 try wip_errors.init(gpa);
5775 defer wip_errors.deinit();5771 defer wip_errors.deinit();
5776 try Compilation.addZirErrorMessages(&wip_errors, &file);5772 try Compilation.addZirErrorMessages(&wip_errors, &file);
5777 var error_bundle = try wip_errors.toOwnedBundle();5773 var error_bundle = try wip_errors.toOwnedBundle("");
5778 defer error_bundle.deinit(gpa);5774 defer error_bundle.deinit(gpa);
5779 error_bundle.renderToStdErr(renderOptions(color));5775 error_bundle.renderToStdErr(renderOptions(color));
5780 process.exit(1);5776 process.exit(1);