authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-07-28 02:30:53+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-07-27 21:30:53-04:00
logc234d4790ef51ac05e317e42a0a4836632a5d7a0
tree45c142250302eb37f8feb7d0ed40d0f6a801c712
parentbb2accba9bf1ec2bf32e7d461785b3084524dbf1
signature Signed by PGP key 4AEE18F83AFDEB23

Add option to hide build command on compilation error to build_runner (#8513)

Co-authored-by: Veikka Tuominen <git@vexu.eu>

4 files changed, 60 insertions(+), 32 deletions(-)

lib/std/build.zig+10-2
......@@ -45,6 +45,8 @@ pub const Builder = struct {
4545 verbose_llvm_ir: bool,
4646 verbose_cimport: bool,
4747 verbose_llvm_cpu_features: bool,
48 /// The purpose of executing the command is for a human to read compile errors from the terminal
49 prominent_compile_errors: bool,
4850 color: enum { auto, on, off } = .auto,
4951 invalid_user_input: bool,
5052 zig_exe: []const u8,
......@@ -157,6 +159,7 @@ pub const Builder = struct {
157159 .verbose_llvm_ir = false,
158160 .verbose_cimport = false,
159161 .verbose_llvm_cpu_features = false,
162 .prominent_compile_errors = false,
160163 .invalid_user_input = false,
161164 .allocator = allocator,
162165 .user_input_options = UserInputOptionsMap.init(allocator),
......@@ -1162,8 +1165,13 @@ pub const Builder = struct {
11621165 },
11631166 error.ExitCodeFailure => {
11641167 if (src_step) |s| warn("{s}...", .{s.name});
1165 warn("The following command exited with error code {d}:\n", .{code});
1166 printCmd(null, argv);
1168 if (self.prominent_compile_errors) {
1169 warn("The step exited with error code {d}\n", .{code});
1170 } else {
1171 warn("The following command exited with error code {d}:\n", .{code});
1172 printCmd(null, argv);
1173 }
1174
11671175 std.os.exit(@truncate(u8, code));
11681176 },
11691177 error.ProcessTerminated => {
lib/std/build/RunStep.zig+13-5
......@@ -221,11 +221,19 @@ fn make(step: *Step) !void {
221221 switch (term) {
222222 .Exited => |code| {
223223 if (code != self.expected_exit_code) {
224 warn("The following command exited with error code {} (expected {}):\n", .{
225 code,
226 self.expected_exit_code,
227 });
228 printCmd(cwd, argv);
224 if (self.builder.prominent_compile_errors) {
225 warn("Run step exited with error code {} (expected {})\n", .{
226 code,
227 self.expected_exit_code,
228 });
229 } else {
230 warn("The following command exited with error code {} (expected {}):\n", .{
231 code,
232 self.expected_exit_code,
233 });
234 printCmd(cwd, argv);
235 }
236
229237 return error.UncleanExit;
230238 }
231239 },
lib/std/special/build_runner.zig+26-23
......@@ -157,6 +157,8 @@ pub fn main() !void {
157157 builder.verbose_cc = true;
158158 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
159159 builder.verbose_llvm_cpu_features = true;
160 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
161 builder.prominent_compile_errors = true;
160162 } else if (mem.eql(u8, arg, "--")) {
161163 builder.args = argsRest(args, arg_idx);
162164 break;
......@@ -214,24 +216,25 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
214216 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
215217 else
216218 top_level_step.step.name;
217 try out_stream.print(" {s:<27} {s}\n", .{ name, top_level_step.description });
219 try out_stream.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
218220 }
219221
220222 try out_stream.writeAll(
221223 \\
222224 \\General Options:
223 \\ -p, --prefix [path] Override default install prefix
224 \\ --prefix-lib-dir [path] Override default library directory path
225 \\ --prefix-exe-dir [path] Override default executable directory path
226 \\ --prefix-include-dir [path] Override default include directory path
225 \\ -p, --prefix [path] Override default install prefix
226 \\ --prefix-lib-dir [path] Override default library directory path
227 \\ --prefix-exe-dir [path] Override default executable directory path
228 \\ --prefix-include-dir [path] Override default include directory path
227229 \\
228 \\ --sysroot [path] Set the system root directory (usually /)
229 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
230 \\ --libc [file] Provide a file which specifies libc paths
230 \\ --sysroot [path] Set the system root directory (usually /)
231 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
232 \\ --libc [file] Provide a file which specifies libc paths
231233 \\
232 \\ -h, --help Print this help and exit
233 \\ --verbose Print commands before executing them
234 \\ --color [auto|off|on] Enable or disable colored error messages
234 \\ -h, --help Print this help and exit
235 \\ --verbose Print commands before executing them
236 \\ --color [auto|off|on] Enable or disable colored error messages
237 \\ --prominent-compile-errors Output compile errors formatted for a human to read
235238 \\
236239 \\Project-Specific Options:
237240 \\
......@@ -246,24 +249,24 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
246249 @tagName(option.type_id),
247250 });
248251 defer allocator.free(name);
249 try out_stream.print("{s:<29} {s}\n", .{ name, option.description });
252 try out_stream.print("{s:<30} {s}\n", .{ name, option.description });
250253 }
251254 }
252255
253256 try out_stream.writeAll(
254257 \\
255258 \\Advanced Options:
256 \\ --build-file [file] Override path to build.zig
257 \\ --cache-dir [path] Override path to zig cache directory
258 \\ --zig-lib-dir [arg] Override path to Zig lib directory
259 \\ --verbose-tokenize Enable compiler debug output for tokenization
260 \\ --verbose-ast Enable compiler debug output for parsing into an AST
261 \\ --verbose-link Enable compiler debug output for linking
262 \\ --verbose-ir Enable compiler debug output for Zig IR
263 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
264 \\ --verbose-cimport Enable compiler debug output for C imports
265 \\ --verbose-cc Enable compiler debug output for C compilation
266 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
259 \\ --build-file [file] Override path to build.zig
260 \\ --cache-dir [path] Override path to zig cache directory
261 \\ --zig-lib-dir [arg] Override path to Zig lib directory
262 \\ --verbose-tokenize Enable compiler debug output for tokenization
263 \\ --verbose-ast Enable compiler debug output for parsing into an AST
264 \\ --verbose-link Enable compiler debug output for linking
265 \\ --verbose-ir Enable compiler debug output for Zig IR
266 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
267 \\ --verbose-cimport Enable compiler debug output for C imports
268 \\ --verbose-cc Enable compiler debug output for C compilation
269 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
267270 \\
268271 );
269272}
src/main.zig+11-2
......@@ -2753,6 +2753,8 @@ pub const usage_build =
27532753;
27542754
27552755pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {
2756 var prominent_compile_errors: bool = false;
2757
27562758 // We want to release all the locks before executing the child process, so we make a nice
27572759 // big block here to ensure the cleanup gets run when we extract out our argv.
27582760 const child_argv = argv: {
......@@ -2804,6 +2806,8 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
28042806 i += 1;
28052807 override_global_cache_dir = args[i];
28062808 continue;
2809 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
2810 prominent_compile_errors = true;
28072811 }
28082812 }
28092813 try child_argv.append(arg);
......@@ -2973,8 +2977,13 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
29732977 switch (term) {
29742978 .Exited => |code| {
29752979 if (code == 0) return cleanExit();
2976 const cmd = try argvCmd(arena, child_argv);
2977 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
2980
2981 if (prominent_compile_errors) {
2982 fatal("the build command failed with exit code {d}", .{code});
2983 } else {
2984 const cmd = try argvCmd(arena, child_argv);
2985 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
2986 }
29782987 },
29792988 else => {
29802989 const cmd = try argvCmd(arena, child_argv);