authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-26 19:27:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
log190f6038bfca5e6239635cfeebd87d67d2501ea3
tree99da329d57b7af92edc13fa3ce11c3bb7bc4caa8
parent5e2035da145f2c758be26ee9817473b97274c34d

zig build: reintroduce --prominent-compile-errors

This reintroduced flag makes zig build behave the same as the previous commit. Without this flag, the default behavior is now changed to display compilation errors inline with the rest of error messages and the build tree context. This behavior is essential for making sense of error logs from projects that have two or more steps emitting compilation errors which is why it is now the default.

2 files changed, 18 insertions(+), 3 deletions(-)

lib/build_runner.zig+17-3
...@@ -99,6 +99,7 @@ pub fn main() !void {...@@ -99,6 +99,7 @@ pub fn main() !void {
99 var skip_oom_steps: bool = false;99 var skip_oom_steps: bool = false;
100 var color: Color = .auto;100 var color: Color = .auto;
101 var seed: u32 = 0;101 var seed: u32 = 0;
102 var prominent_compile_errors: bool = false;
102103
103 const stderr_stream = io.getStdErr().writer();104 const stderr_stream = io.getStdErr().writer();
104 const stdout_stream = io.getStdOut().writer();105 const stdout_stream = io.getStdOut().writer();
...@@ -242,6 +243,8 @@ pub fn main() !void {...@@ -242,6 +243,8 @@ pub fn main() !void {
242 builder.verbose_cc = true;243 builder.verbose_cc = true;
243 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {244 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
244 builder.verbose_llvm_cpu_features = true;245 builder.verbose_llvm_cpu_features = true;
246 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
247 prominent_compile_errors = true;
245 } else if (mem.eql(u8, arg, "-fwine")) {248 } else if (mem.eql(u8, arg, "-fwine")) {
246 builder.enable_wine = true;249 builder.enable_wine = true;
247 } else if (mem.eql(u8, arg, "-fno-wine")) {250 } else if (mem.eql(u8, arg, "-fno-wine")) {
...@@ -325,6 +328,7 @@ pub fn main() !void {...@@ -325,6 +328,7 @@ pub fn main() !void {
325 .max_rss_mutex = .{},328 .max_rss_mutex = .{},
326 .skip_oom_steps = skip_oom_steps,329 .skip_oom_steps = skip_oom_steps,
327 .memory_blocked_steps = std.ArrayList(*Step).init(arena),330 .memory_blocked_steps = std.ArrayList(*Step).init(arena),
331 .prominent_compile_errors = prominent_compile_errors,
328332
329 .claimed_rss = 0,333 .claimed_rss = 0,
330 .summary = summary,334 .summary = summary,
...@@ -357,6 +361,7 @@ const Run = struct {...@@ -357,6 +361,7 @@ const Run = struct {
357 max_rss_mutex: std.Thread.Mutex,361 max_rss_mutex: std.Thread.Mutex,
358 skip_oom_steps: bool,362 skip_oom_steps: bool,
359 memory_blocked_steps: std.ArrayList(*Step),363 memory_blocked_steps: std.ArrayList(*Step),
364 prominent_compile_errors: bool,
360365
361 claimed_rss: usize,366 claimed_rss: usize,
362 summary: ?Summary,367 summary: ?Summary,
...@@ -561,7 +566,7 @@ fn runStepNames(...@@ -561,7 +566,7 @@ fn runStepNames(
561 // Finally, render compile errors at the bottom of the terminal.566 // Finally, render compile errors at the bottom of the terminal.
562 // We use a separate compile_error_steps array list because step_stack is destructively567 // We use a separate compile_error_steps array list because step_stack is destructively
563 // mutated in printTreeStep above.568 // mutated in printTreeStep above.
564 if (total_compile_errors > 0) {569 if (run.prominent_compile_errors and total_compile_errors > 0) {
565 for (compile_error_steps.items) |s| {570 for (compile_error_steps.items) |s| {
566 if (s.result_error_bundle.errorMessageCount() > 0) {571 if (s.result_error_bundle.errorMessageCount() > 0) {
567 s.result_error_bundle.renderToStdErr(renderOptions(ttyconf));572 s.result_error_bundle.renderToStdErr(renderOptions(ttyconf));
...@@ -910,7 +915,11 @@ fn workerMakeOneStep(...@@ -910,7 +915,11 @@ fn workerMakeOneStep(
910 const make_result = s.make(&sub_prog_node);915 const make_result = s.make(&sub_prog_node);
911916
912 // No matter the result, we want to display error/warning messages.917 // No matter the result, we want to display error/warning messages.
913 if (s.result_error_msgs.items.len > 0) {918 const show_compile_errors = !run.prominent_compile_errors and
919 s.result_error_bundle.errorMessageCount() > 0;
920 const show_error_msgs = s.result_error_msgs.items.len > 0;
921
922 if (show_error_msgs or show_compile_errors) {
914 sub_prog_node.context.lock_stderr();923 sub_prog_node.context.lock_stderr();
915 defer sub_prog_node.context.unlock_stderr();924 defer sub_prog_node.context.unlock_stderr();
916925
...@@ -1003,7 +1012,11 @@ fn printErrorMessages(b: *std.Build, failing_step: *Step, run: *const Run) !void...@@ -1003,7 +1012,11 @@ fn printErrorMessages(b: *std.Build, failing_step: *Step, run: *const Run) !void
1003 }1012 }
1004 try ttyconf.setColor(stderr, .reset);1013 try ttyconf.setColor(stderr, .reset);
10051014
1006 // Finally, the actual error messages.1015 // Penultimately, the compilation errors.
1016 if (!run.prominent_compile_errors and failing_step.result_error_bundle.errorMessageCount() > 0)
1017 try failing_step.result_error_bundle.renderToWriter(renderOptions(ttyconf), stderr.writer());
1018
1019 // Finally, generic error messages.
1007 for (failing_step.result_error_msgs.items) |msg| {1020 for (failing_step.result_error_msgs.items) |msg| {
1008 try ttyconf.setColor(stderr, .red);1021 try ttyconf.setColor(stderr, .red);
1009 try stderr.writeAll("error: ");1022 try stderr.writeAll("error: ");
...@@ -1078,6 +1091,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi...@@ -1078,6 +1091,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
1078 \\ -l, --list-steps Print available steps1091 \\ -l, --list-steps Print available steps
1079 \\ --verbose Print commands before executing them1092 \\ --verbose Print commands before executing them
1080 \\ --color [auto|off|on] Enable or disable colored error messages1093 \\ --color [auto|off|on] Enable or disable colored error messages
1094 \\ --prominent-compile-errors Buffer compile errors and display at end
1081 \\ --summary [mode] Control the printing of the build summary1095 \\ --summary [mode] Control the printing of the build summary
1082 \\ all Print the build summary in its entirety1096 \\ all Print the build summary in its entirety
1083 \\ failures (Default) Only print failed steps1097 \\ failures (Default) Only print failed steps
src/main.zig+1
...@@ -5096,6 +5096,7 @@ pub const usage_build =...@@ -5096,6 +5096,7 @@ pub const usage_build =
5096 \\ --global-cache-dir [path] Override path to global Zig cache directory5096 \\ --global-cache-dir [path] Override path to global Zig cache directory
5097 \\ --zig-lib-dir [arg] Override path to Zig lib directory5097 \\ --zig-lib-dir [arg] Override path to Zig lib directory
5098 \\ --build-runner [file] Override path to build runner5098 \\ --build-runner [file] Override path to build runner
5099 \\ --prominent-compile-errors Buffer compile errors and display at end
5099 \\ --seed [integer] For shuffling dependency traversal order (default: random)5100 \\ --seed [integer] For shuffling dependency traversal order (default: random)
5100 \\ --fetch Exit after fetching dependency tree5101 \\ --fetch Exit after fetching dependency tree
5101 \\ -h, --help Print this help and exit5102 \\ -h, --help Print this help and exit