I have a Run step which always prints something to stderr. However, I want to see stderr only if the step fails.
If I don’t configure the behavior specially, stderr is inherited, which is not what I want.
If I do step.addCheck(.{ .expect_term = .{ .Exited = 0 } });
, the stderr is collected, which is good because it at least doesn’t lock build’s global stdio mutex, but it is still printing unconditionally at the end of the build.
If I also step.addCheck(.{ .expect_stderr_match = "" });
, then stderr
isn’t printed even if the step is considered failed.
Looking at the relevant build_runner.zig code, it seems like this use-case isn’t actually supported at all:
// No matter the result, we want to display error/warning messages.
const show_compile_errors = !run.prominent_compile_errors and
s.result_error_bundle.errorMessageCount() > 0;
const show_error_msgs = s.result_error_msgs.items.len > 0;
const show_stderr = s.result_stderr.len > 0;
if (show_error_msgs or show_compile_errors or show_stderr) {
var bw = std.debug.lockStdErr2();
defer std.debug.unlockStdErr();
const gpa = b.allocator;
const options: std.zig.ErrorBundle.RenderOptions = .{
.ttyconf = run.ttyconf,
.include_reference_trace = (b.reference_trace orelse 0) > 0,
};
printErrorMessages(gpa, s, options, &bw, run.prominent_compile_errors) catch {};
}
But is there perhaps some out-of-the-box way to do what I want here?