authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-17 21:30:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
log398ea7e492b7016dcb6cebfe6656876002f5bf73
treebe258027f8b42c3c4f16468524f1bc53c5a49af1
parent4aa8fa898de3847f3a0469edf4484f60c3ecf051

Maker: handle fallible child proc capture gracefully


1 files changed, 9 insertions(+), 5 deletions(-)

lib/compiler/Maker/Step.zig+9-5
......@@ -59,6 +59,7 @@ result_duration_ns: ?u64 = null,
5959result_peak_rss: usize = 0,
6060/// If the step is failed and this field is populated, this is the command which failed.
6161/// This field may be populated even if the step succeeded.
62/// Memory owned by `Maker.gpa`.
6263result_failed_command: ?[]const u8 = null,
6364test_results: TestResults = .{},
6465
......@@ -313,14 +314,13 @@ pub fn reset(step: *Step, maker: *Maker) void {
313314 assert(step.state == .precheck_done);
314315 const gpa = maker.gpa;
315316
316 if (step.result_failed_command) |cmd| gpa.free(cmd);
317 clearFailedCommand(step, gpa);
317318
318319 step.result_error_msgs.clearRetainingCapacity();
319320 step.result_stderr = "";
320321 step.result_cached = false;
321322 step.result_duration_ns = null;
322323 step.result_peak_rss = 0;
323 step.result_failed_command = null;
324324 step.test_results = .{};
325325 // We do not clearWatchInputs here because each step manages that choice
326326 // independently.
......@@ -347,8 +347,7 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
347347 const arena = graph.arena; // TODO stop leaking into process arena
348348 const io = graph.io;
349349
350 // If an error occurs, it's happened in this command:
351 assert(s.result_failed_command == null);
350 clearFailedCommand(s, gpa);
352351 s.result_failed_command = try std.zig.allocPrintCmd(gpa, options.argv, .{});
353352
354353 try handleChildProcUnsupported(s, maker);
......@@ -372,6 +371,11 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
372371 return result;
373372}
374373
374fn clearFailedCommand(s: *Step, gpa: Allocator) void {
375 if (s.result_failed_command) |cmd| gpa.free(cmd);
376 s.result_failed_command = null;
377}
378
375379pub const FailError = error{ OutOfMemory, MakeFailed };
376380
377381pub fn fail(step: *Step, maker: *const Maker, comptime fmt: []const u8, args: anytype) FailError {
......@@ -421,7 +425,7 @@ pub fn evalZigProcess(
421425 const io = graph.io;
422426
423427 // If an error occurs, it's happened in this command:
424 assert(s.result_failed_command == null);
428 clearFailedCommand(s, gpa);
425429 s.result_failed_command = try std.zig.allocPrintCmd(gpa, argv, .{});
426430
427431 if (s.getZigProcess()) |zp| update: {