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
signaturebadge-question-mark 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 {...@@ -45,6 +45,8 @@ pub const Builder = struct {
45 verbose_llvm_ir: bool,45 verbose_llvm_ir: bool,
46 verbose_cimport: bool,46 verbose_cimport: bool,
47 verbose_llvm_cpu_features: bool,47 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,
48 color: enum { auto, on, off } = .auto,50 color: enum { auto, on, off } = .auto,
49 invalid_user_input: bool,51 invalid_user_input: bool,
50 zig_exe: []const u8,52 zig_exe: []const u8,
...@@ -157,6 +159,7 @@ pub const Builder = struct {...@@ -157,6 +159,7 @@ pub const Builder = struct {
157 .verbose_llvm_ir = false,159 .verbose_llvm_ir = false,
158 .verbose_cimport = false,160 .verbose_cimport = false,
159 .verbose_llvm_cpu_features = false,161 .verbose_llvm_cpu_features = false,
162 .prominent_compile_errors = false,
160 .invalid_user_input = false,163 .invalid_user_input = false,
161 .allocator = allocator,164 .allocator = allocator,
162 .user_input_options = UserInputOptionsMap.init(allocator),165 .user_input_options = UserInputOptionsMap.init(allocator),
...@@ -1162,8 +1165,13 @@ pub const Builder = struct {...@@ -1162,8 +1165,13 @@ pub const Builder = struct {
1162 },1165 },
1163 error.ExitCodeFailure => {1166 error.ExitCodeFailure => {
1164 if (src_step) |s| warn("{s}...", .{s.name});1167 if (src_step) |s| warn("{s}...", .{s.name});
1165 warn("The following command exited with error code {d}:\n", .{code});1168 if (self.prominent_compile_errors) {
1166 printCmd(null, argv);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
1167 std.os.exit(@truncate(u8, code));1175 std.os.exit(@truncate(u8, code));
1168 },1176 },
1169 error.ProcessTerminated => {1177 error.ProcessTerminated => {
lib/std/build/RunStep.zig+13-5
...@@ -221,11 +221,19 @@ fn make(step: *Step) !void {...@@ -221,11 +221,19 @@ fn make(step: *Step) !void {
221 switch (term) {221 switch (term) {
222 .Exited => |code| {222 .Exited => |code| {
223 if (code != self.expected_exit_code) {223 if (code != self.expected_exit_code) {
224 warn("The following command exited with error code {} (expected {}):\n", .{224 if (self.builder.prominent_compile_errors) {
225 code,225 warn("Run step exited with error code {} (expected {})\n", .{
226 self.expected_exit_code,226 code,
227 });227 self.expected_exit_code,
228 printCmd(cwd, argv);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
229 return error.UncleanExit;237 return error.UncleanExit;
230 }238 }
231 },239 },
lib/std/special/build_runner.zig+26-23
...@@ -157,6 +157,8 @@ pub fn main() !void {...@@ -157,6 +157,8 @@ pub fn main() !void {
157 builder.verbose_cc = true;157 builder.verbose_cc = true;
158 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {158 } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
159 builder.verbose_llvm_cpu_features = true;159 builder.verbose_llvm_cpu_features = true;
160 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
161 builder.prominent_compile_errors = true;
160 } else if (mem.eql(u8, arg, "--")) {162 } else if (mem.eql(u8, arg, "--")) {
161 builder.args = argsRest(args, arg_idx);163 builder.args = argsRest(args, arg_idx);
162 break;164 break;
...@@ -214,24 +216,25 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -214,24 +216,25 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
214 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})216 try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
215 else217 else
216 top_level_step.step.name;218 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 });
218 }220 }
219221
220 try out_stream.writeAll(222 try out_stream.writeAll(
221 \\223 \\
222 \\General Options:224 \\General Options:
223 \\ -p, --prefix [path] Override default install prefix225 \\ -p, --prefix [path] Override default install prefix
224 \\ --prefix-lib-dir [path] Override default library directory path226 \\ --prefix-lib-dir [path] Override default library directory path
225 \\ --prefix-exe-dir [path] Override default executable directory path227 \\ --prefix-exe-dir [path] Override default executable directory path
226 \\ --prefix-include-dir [path] Override default include directory path228 \\ --prefix-include-dir [path] Override default include directory path
227 \\229 \\
228 \\ --sysroot [path] Set the system root directory (usually /)230 \\ --sysroot [path] Set the system root directory (usually /)
229 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers231 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
230 \\ --libc [file] Provide a file which specifies libc paths232 \\ --libc [file] Provide a file which specifies libc paths
231 \\233 \\
232 \\ -h, --help Print this help and exit234 \\ -h, --help Print this help and exit
233 \\ --verbose Print commands before executing them235 \\ --verbose Print commands before executing them
234 \\ --color [auto|off|on] Enable or disable colored error messages236 \\ --color [auto|off|on] Enable or disable colored error messages
237 \\ --prominent-compile-errors Output compile errors formatted for a human to read
235 \\238 \\
236 \\Project-Specific Options:239 \\Project-Specific Options:
237 \\240 \\
...@@ -246,24 +249,24 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -246,24 +249,24 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
246 @tagName(option.type_id),249 @tagName(option.type_id),
247 });250 });
248 defer allocator.free(name);251 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 });
250 }253 }
251 }254 }
252255
253 try out_stream.writeAll(256 try out_stream.writeAll(
254 \\257 \\
255 \\Advanced Options:258 \\Advanced Options:
256 \\ --build-file [file] Override path to build.zig259 \\ --build-file [file] Override path to build.zig
257 \\ --cache-dir [path] Override path to zig cache directory260 \\ --cache-dir [path] Override path to zig cache directory
258 \\ --zig-lib-dir [arg] Override path to Zig lib directory261 \\ --zig-lib-dir [arg] Override path to Zig lib directory
259 \\ --verbose-tokenize Enable compiler debug output for tokenization262 \\ --verbose-tokenize Enable compiler debug output for tokenization
260 \\ --verbose-ast Enable compiler debug output for parsing into an AST263 \\ --verbose-ast Enable compiler debug output for parsing into an AST
261 \\ --verbose-link Enable compiler debug output for linking264 \\ --verbose-link Enable compiler debug output for linking
262 \\ --verbose-ir Enable compiler debug output for Zig IR265 \\ --verbose-ir Enable compiler debug output for Zig IR
263 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR266 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
264 \\ --verbose-cimport Enable compiler debug output for C imports267 \\ --verbose-cimport Enable compiler debug output for C imports
265 \\ --verbose-cc Enable compiler debug output for C compilation268 \\ --verbose-cc Enable compiler debug output for C compilation
266 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features269 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
267 \\270 \\
268 );271 );
269}272}
src/main.zig+11-2
...@@ -2753,6 +2753,8 @@ pub const usage_build =...@@ -2753,6 +2753,8 @@ pub const usage_build =
2753;2753;
27542754
2755pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {2755pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {
2756 var prominent_compile_errors: bool = false;
2757
2756 // We want to release all the locks before executing the child process, so we make a nice2758 // We want to release all the locks before executing the child process, so we make a nice
2757 // big block here to ensure the cleanup gets run when we extract out our argv.2759 // big block here to ensure the cleanup gets run when we extract out our argv.
2758 const child_argv = argv: {2760 const child_argv = argv: {
...@@ -2804,6 +2806,8 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2804,6 +2806,8 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2804 i += 1;2806 i += 1;
2805 override_global_cache_dir = args[i];2807 override_global_cache_dir = args[i];
2806 continue;2808 continue;
2809 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
2810 prominent_compile_errors = true;
2807 }2811 }
2808 }2812 }
2809 try child_argv.append(arg);2813 try child_argv.append(arg);
...@@ -2973,8 +2977,13 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2973,8 +2977,13 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2973 switch (term) {2977 switch (term) {
2974 .Exited => |code| {2978 .Exited => |code| {
2975 if (code == 0) return cleanExit();2979 if (code == 0) return cleanExit();
2976 const cmd = try argvCmd(arena, child_argv);2980
2977 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });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 }
2978 },2987 },
2979 else => {2988 else => {
2980 const cmd = try argvCmd(arena, child_argv);2989 const cmd = try argvCmd(arena, child_argv);