Maker: handle fallible child proc capture gracefully

This commit is contained in:
Andrew Kelley
2026-05-17 21:30:08 -07:00
parent 4aa8fa898d
commit 398ea7e492
+9 -5
View File
@@ -59,6 +59,7 @@ result_duration_ns: ?u64 = null,
result_peak_rss: usize = 0,
/// If the step is failed and this field is populated, this is the command which failed.
/// This field may be populated even if the step succeeded.
/// Memory owned by `Maker.gpa`.
result_failed_command: ?[]const u8 = null,
test_results: TestResults = .{},
@@ -313,14 +314,13 @@ pub fn reset(step: *Step, maker: *Maker) void {
assert(step.state == .precheck_done);
const gpa = maker.gpa;
if (step.result_failed_command) |cmd| gpa.free(cmd);
clearFailedCommand(step, gpa);
step.result_error_msgs.clearRetainingCapacity();
step.result_stderr = "";
step.result_cached = false;
step.result_duration_ns = null;
step.result_peak_rss = 0;
step.result_failed_command = null;
step.test_results = .{};
// We do not clearWatchInputs here because each step manages that choice
// independently.
@@ -347,8 +347,7 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
const arena = graph.arena; // TODO stop leaking into process arena
const io = graph.io;
// If an error occurs, it's happened in this command:
assert(s.result_failed_command == null);
clearFailedCommand(s, gpa);
s.result_failed_command = try std.zig.allocPrintCmd(gpa, options.argv, .{});
try handleChildProcUnsupported(s, maker);
@@ -372,6 +371,11 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
return result;
}
fn clearFailedCommand(s: *Step, gpa: Allocator) void {
if (s.result_failed_command) |cmd| gpa.free(cmd);
s.result_failed_command = null;
}
pub const FailError = error{ OutOfMemory, MakeFailed };
pub fn fail(step: *Step, maker: *const Maker, comptime fmt: []const u8, args: anytype) FailError {
@@ -421,7 +425,7 @@ pub fn evalZigProcess(
const io = graph.io;
// If an error occurs, it's happened in this command:
assert(s.result_failed_command == null);
clearFailedCommand(s, gpa);
s.result_failed_command = try std.zig.allocPrintCmd(gpa, argv, .{});
if (s.getZigProcess()) |zp| update: {