diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 91443a093a..2dfc574809 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -733,7 +733,7 @@ fn runStepNames( if (run.prominent_compile_errors and total_compile_errors > 0) { for (step_stack.keys()) |s| { if (s.result_error_bundle.errorMessageCount() > 0) { - s.result_error_bundle.renderToStdErr(renderOptions(ttyconf)); + s.result_error_bundle.renderToStdErr(.{ .ttyconf = ttyconf, .include_reference_trace = (b.reference_trace orelse 0) > 0 }); } } @@ -1112,7 +1112,11 @@ fn workerMakeOneStep( defer std.debug.unlockStdErr(); const gpa = b.allocator; - printErrorMessages(gpa, s, run.ttyconf, run.stderr, run.prominent_compile_errors) catch {}; + const options: std.zig.ErrorBundle.RenderOptions = .{ + .ttyconf = run.ttyconf, + .include_reference_trace = (b.reference_trace orelse 0) > 0, + }; + printErrorMessages(gpa, s, options, run.stderr, run.prominent_compile_errors) catch {}; } handle_result: { @@ -1168,7 +1172,7 @@ fn workerMakeOneStep( pub fn printErrorMessages( gpa: Allocator, failing_step: *Step, - ttyconf: std.io.tty.Config, + options: std.zig.ErrorBundle.RenderOptions, stderr: File, prominent_compile_errors: bool, ) !void { @@ -1183,6 +1187,7 @@ pub fn printErrorMessages( } // Now, `step_stack` has the subtree that we want to print, in reverse order. + const ttyconf = options.ttyconf; try ttyconf.setColor(stderr, .dim); var indent: usize = 0; while (step_stack.popOrNull()) |s| : (indent += 1) { @@ -1208,8 +1213,9 @@ pub fn printErrorMessages( } } - if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0) - try failing_step.result_error_bundle.renderToWriter(renderOptions(ttyconf), stderr.writer()); + if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0) { + try failing_step.result_error_bundle.renderToWriter(options, stderr.writer()); + } for (failing_step.result_error_msgs.items) |msg| { try ttyconf.setColor(stderr, .red); @@ -1410,14 +1416,6 @@ fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config { }; } -fn renderOptions(ttyconf: std.io.tty.Config) std.zig.ErrorBundle.RenderOptions { - return .{ - .ttyconf = ttyconf, - .include_source_line = ttyconf != .no_color, - .include_reference_trace = ttyconf != .no_color, - }; -} - fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn { std.debug.print(f ++ "\n access the help menu with 'zig build -h'\n", args); process.exit(1); diff --git a/lib/std/Build/Fuzz.zig b/lib/std/Build/Fuzz.zig index 6e837ebec2..4ebdfdf8e5 100644 --- a/lib/std/Build/Fuzz.zig +++ b/lib/std/Build/Fuzz.zig @@ -127,7 +127,7 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, ttyconf: std.io.tty.Config, par if (show_error_msgs or show_compile_errors or show_stderr) { std.debug.lockStdErr(); defer std.debug.unlockStdErr(); - build_runner.printErrorMessages(gpa, &compile.step, ttyconf, stderr, false) catch {}; + build_runner.printErrorMessages(gpa, &compile.step, .{ .ttyconf = ttyconf }, stderr, false) catch {}; } const rebuilt_bin_path = result catch |err| switch (err) { @@ -155,7 +155,7 @@ fn fuzzWorkerRun( const stderr = std.io.getStdErr(); std.debug.lockStdErr(); defer std.debug.unlockStdErr(); - build_runner.printErrorMessages(gpa, &run.step, ttyconf, stderr, false) catch {}; + build_runner.printErrorMessages(gpa, &run.step, .{ .ttyconf = ttyconf }, stderr, false) catch {}; return; }, else => { diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 7897c341b9..d2521be1ba 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -54,11 +54,8 @@ pub const Color = enum { } pub fn renderOptions(color: Color) std.zig.ErrorBundle.RenderOptions { - const ttyconf = get_tty_conf(color); return .{ - .ttyconf = ttyconf, - .include_source_line = ttyconf != .no_color, - .include_reference_trace = ttyconf != .no_color, + .ttyconf = get_tty_conf(color), }; } };