authorgravatar for guillaume.wenzek@polytechnique.orgGuillaume Wenzek <guillaume.wenzek@polytechnique.org> 2025-01-30 13:02:06+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-01-30 13:02:06+01:00
log3348478fc3882fa3627147e54eeafa83ab7f4b09
tree59e60ef7a5383ce8736152c8703879596544d417
parente4c049e4104ed16097d7481979e474479e45328b
signaturebadge-check Signed by PGP key B5690EEEBB952194

Make -freference-trace work without colors

Currently -freference-trace only works when running from a terminal. This is annoying if you're running in another environment or if you redirect the output. But -freference-trace also works fine without the color, so change how the build runner is interpreting this option.

3 files changed, 14 insertions(+), 19 deletions(-)

lib/compiler/build_runner.zig+11-13
......@@ -733,7 +733,7 @@ fn runStepNames(
733733 if (run.prominent_compile_errors and total_compile_errors > 0) {
734734 for (step_stack.keys()) |s| {
735735 if (s.result_error_bundle.errorMessageCount() > 0) {
736 s.result_error_bundle.renderToStdErr(renderOptions(ttyconf));
736 s.result_error_bundle.renderToStdErr(.{ .ttyconf = ttyconf, .include_reference_trace = (b.reference_trace orelse 0) > 0 });
737737 }
738738 }
739739
......@@ -1112,7 +1112,11 @@ fn workerMakeOneStep(
11121112 defer std.debug.unlockStdErr();
11131113
11141114 const gpa = b.allocator;
1115 printErrorMessages(gpa, s, run.ttyconf, run.stderr, run.prominent_compile_errors) catch {};
1115 const options: std.zig.ErrorBundle.RenderOptions = .{
1116 .ttyconf = run.ttyconf,
1117 .include_reference_trace = (b.reference_trace orelse 0) > 0,
1118 };
1119 printErrorMessages(gpa, s, options, run.stderr, run.prominent_compile_errors) catch {};
11161120 }
11171121
11181122 handle_result: {
......@@ -1168,7 +1172,7 @@ fn workerMakeOneStep(
11681172pub fn printErrorMessages(
11691173 gpa: Allocator,
11701174 failing_step: *Step,
1171 ttyconf: std.io.tty.Config,
1175 options: std.zig.ErrorBundle.RenderOptions,
11721176 stderr: File,
11731177 prominent_compile_errors: bool,
11741178) !void {
......@@ -1183,6 +1187,7 @@ pub fn printErrorMessages(
11831187 }
11841188
11851189 // Now, `step_stack` has the subtree that we want to print, in reverse order.
1190 const ttyconf = options.ttyconf;
11861191 try ttyconf.setColor(stderr, .dim);
11871192 var indent: usize = 0;
11881193 while (step_stack.popOrNull()) |s| : (indent += 1) {
......@@ -1208,8 +1213,9 @@ pub fn printErrorMessages(
12081213 }
12091214 }
12101215
1211 if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0)
1212 try failing_step.result_error_bundle.renderToWriter(renderOptions(ttyconf), stderr.writer());
1216 if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0) {
1217 try failing_step.result_error_bundle.renderToWriter(options, stderr.writer());
1218 }
12131219
12141220 for (failing_step.result_error_msgs.items) |msg| {
12151221 try ttyconf.setColor(stderr, .red);
......@@ -1410,14 +1416,6 @@ fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {
14101416 };
14111417}
14121418
1413fn renderOptions(ttyconf: std.io.tty.Config) std.zig.ErrorBundle.RenderOptions {
1414 return .{
1415 .ttyconf = ttyconf,
1416 .include_source_line = ttyconf != .no_color,
1417 .include_reference_trace = ttyconf != .no_color,
1418 };
1419}
1420
14211419fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {
14221420 std.debug.print(f ++ "\n access the help menu with 'zig build -h'\n", args);
14231421 process.exit(1);
lib/std/Build/Fuzz.zig+2-2
......@@ -127,7 +127,7 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, ttyconf: std.io.tty.Config, par
127127 if (show_error_msgs or show_compile_errors or show_stderr) {
128128 std.debug.lockStdErr();
129129 defer std.debug.unlockStdErr();
130 build_runner.printErrorMessages(gpa, &compile.step, ttyconf, stderr, false) catch {};
130 build_runner.printErrorMessages(gpa, &compile.step, .{ .ttyconf = ttyconf }, stderr, false) catch {};
131131 }
132132
133133 const rebuilt_bin_path = result catch |err| switch (err) {
......@@ -155,7 +155,7 @@ fn fuzzWorkerRun(
155155 const stderr = std.io.getStdErr();
156156 std.debug.lockStdErr();
157157 defer std.debug.unlockStdErr();
158 build_runner.printErrorMessages(gpa, &run.step, ttyconf, stderr, false) catch {};
158 build_runner.printErrorMessages(gpa, &run.step, .{ .ttyconf = ttyconf }, stderr, false) catch {};
159159 return;
160160 },
161161 else => {
lib/std/zig.zig+1-4
......@@ -54,11 +54,8 @@ pub const Color = enum {
5454 }
5555
5656 pub fn renderOptions(color: Color) std.zig.ErrorBundle.RenderOptions {
57 const ttyconf = get_tty_conf(color);
5857 return .{
59 .ttyconf = ttyconf,
60 .include_source_line = ttyconf != .no_color,
61 .include_reference_trace = ttyconf != .no_color,
58 .ttyconf = get_tty_conf(color),
6259 };
6360 }
6461};