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(...@@ -733,7 +733,7 @@ fn runStepNames(
733 if (run.prominent_compile_errors and total_compile_errors > 0) {733 if (run.prominent_compile_errors and total_compile_errors > 0) {
734 for (step_stack.keys()) |s| {734 for (step_stack.keys()) |s| {
735 if (s.result_error_bundle.errorMessageCount() > 0) {735 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 });
737 }737 }
738 }738 }
739739
...@@ -1112,7 +1112,11 @@ fn workerMakeOneStep(...@@ -1112,7 +1112,11 @@ fn workerMakeOneStep(
1112 defer std.debug.unlockStdErr();1112 defer std.debug.unlockStdErr();
11131113
1114 const gpa = b.allocator;1114 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 {};
1116 }1120 }
11171121
1118 handle_result: {1122 handle_result: {
...@@ -1168,7 +1172,7 @@ fn workerMakeOneStep(...@@ -1168,7 +1172,7 @@ fn workerMakeOneStep(
1168pub fn printErrorMessages(1172pub fn printErrorMessages(
1169 gpa: Allocator,1173 gpa: Allocator,
1170 failing_step: *Step,1174 failing_step: *Step,
1171 ttyconf: std.io.tty.Config,1175 options: std.zig.ErrorBundle.RenderOptions,
1172 stderr: File,1176 stderr: File,
1173 prominent_compile_errors: bool,1177 prominent_compile_errors: bool,
1174) !void {1178) !void {
...@@ -1183,6 +1187,7 @@ pub fn printErrorMessages(...@@ -1183,6 +1187,7 @@ pub fn printErrorMessages(
1183 }1187 }
11841188
1185 // Now, `step_stack` has the subtree that we want to print, in reverse order.1189 // Now, `step_stack` has the subtree that we want to print, in reverse order.
1190 const ttyconf = options.ttyconf;
1186 try ttyconf.setColor(stderr, .dim);1191 try ttyconf.setColor(stderr, .dim);
1187 var indent: usize = 0;1192 var indent: usize = 0;
1188 while (step_stack.popOrNull()) |s| : (indent += 1) {1193 while (step_stack.popOrNull()) |s| : (indent += 1) {
...@@ -1208,8 +1213,9 @@ pub fn printErrorMessages(...@@ -1208,8 +1213,9 @@ pub fn printErrorMessages(
1208 }1213 }
1209 }1214 }
12101215
1211 if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0)1216 if (!prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0) {
1212 try failing_step.result_error_bundle.renderToWriter(renderOptions(ttyconf), stderr.writer());1217 try failing_step.result_error_bundle.renderToWriter(options, stderr.writer());
1218 }
12131219
1214 for (failing_step.result_error_msgs.items) |msg| {1220 for (failing_step.result_error_msgs.items) |msg| {
1215 try ttyconf.setColor(stderr, .red);1221 try ttyconf.setColor(stderr, .red);
...@@ -1410,14 +1416,6 @@ fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {...@@ -1410,14 +1416,6 @@ fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {
1410 };1416 };
1411}1417}
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
1421fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {1419fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {
1422 std.debug.print(f ++ "\n access the help menu with 'zig build -h'\n", args);1420 std.debug.print(f ++ "\n access the help menu with 'zig build -h'\n", args);
1423 process.exit(1);1421 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...@@ -127,7 +127,7 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, ttyconf: std.io.tty.Config, par
127 if (show_error_msgs or show_compile_errors or show_stderr) {127 if (show_error_msgs or show_compile_errors or show_stderr) {
128 std.debug.lockStdErr();128 std.debug.lockStdErr();
129 defer std.debug.unlockStdErr();129 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 {};
131 }131 }
132132
133 const rebuilt_bin_path = result catch |err| switch (err) {133 const rebuilt_bin_path = result catch |err| switch (err) {
...@@ -155,7 +155,7 @@ fn fuzzWorkerRun(...@@ -155,7 +155,7 @@ fn fuzzWorkerRun(
155 const stderr = std.io.getStdErr();155 const stderr = std.io.getStdErr();
156 std.debug.lockStdErr();156 std.debug.lockStdErr();
157 defer std.debug.unlockStdErr();157 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 {};
159 return;159 return;
160 },160 },
161 else => {161 else => {
lib/std/zig.zig+1-4
...@@ -54,11 +54,8 @@ pub const Color = enum {...@@ -54,11 +54,8 @@ pub const Color = enum {
54 }54 }
5555
56 pub fn renderOptions(color: Color) std.zig.ErrorBundle.RenderOptions {56 pub fn renderOptions(color: Color) std.zig.ErrorBundle.RenderOptions {
57 const ttyconf = get_tty_conf(color);
58 return .{57 return .{
59 .ttyconf = ttyconf,58 .ttyconf = get_tty_conf(color),
60 .include_source_line = ttyconf != .no_color,
61 .include_reference_trace = ttyconf != .no_color,
62 };59 };
63 }60 }
64};61};