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,...@@ -59,6 +59,7 @@ result_duration_ns: ?u64 = null,
59result_peak_rss: usize = 0,59result_peak_rss: usize = 0,
60/// If the step is failed and this field is populated, this is the command which failed.60/// If the step is failed and this field is populated, this is the command which failed.
61/// This field may be populated even if the step succeeded.61/// This field may be populated even if the step succeeded.
62/// Memory owned by `Maker.gpa`.
62result_failed_command: ?[]const u8 = null,63result_failed_command: ?[]const u8 = null,
63test_results: TestResults = .{},64test_results: TestResults = .{},
6465
...@@ -313,14 +314,13 @@ pub fn reset(step: *Step, maker: *Maker) void {...@@ -313,14 +314,13 @@ pub fn reset(step: *Step, maker: *Maker) void {
313 assert(step.state == .precheck_done);314 assert(step.state == .precheck_done);
314 const gpa = maker.gpa;315 const gpa = maker.gpa;
315316
316 if (step.result_failed_command) |cmd| gpa.free(cmd);317 clearFailedCommand(step, gpa);
317318
318 step.result_error_msgs.clearRetainingCapacity();319 step.result_error_msgs.clearRetainingCapacity();
319 step.result_stderr = "";320 step.result_stderr = "";
320 step.result_cached = false;321 step.result_cached = false;
321 step.result_duration_ns = null;322 step.result_duration_ns = null;
322 step.result_peak_rss = 0;323 step.result_peak_rss = 0;
323 step.result_failed_command = null;
324 step.test_results = .{};324 step.test_results = .{};
325 // We do not clearWatchInputs here because each step manages that choice325 // We do not clearWatchInputs here because each step manages that choice
326 // independently.326 // independently.
...@@ -347,8 +347,7 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess...@@ -347,8 +347,7 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
347 const arena = graph.arena; // TODO stop leaking into process arena347 const arena = graph.arena; // TODO stop leaking into process arena
348 const io = graph.io;348 const io = graph.io;
349349
350 // If an error occurs, it's happened in this command:350 clearFailedCommand(s, gpa);
351 assert(s.result_failed_command == null);
352 s.result_failed_command = try std.zig.allocPrintCmd(gpa, options.argv, .{});351 s.result_failed_command = try std.zig.allocPrintCmd(gpa, options.argv, .{});
353352
354 try handleChildProcUnsupported(s, maker);353 try handleChildProcUnsupported(s, maker);
...@@ -372,6 +371,11 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess...@@ -372,6 +371,11 @@ pub fn captureChildProcess(s: *Step, maker: *Maker, options: CaptureChildProcess
372 return result;371 return result;
373}372}
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
375pub const FailError = error{ OutOfMemory, MakeFailed };379pub const FailError = error{ OutOfMemory, MakeFailed };
376380
377pub fn fail(step: *Step, maker: *const Maker, comptime fmt: []const u8, args: anytype) FailError {381pub fn fail(step: *Step, maker: *const Maker, comptime fmt: []const u8, args: anytype) FailError {
...@@ -421,7 +425,7 @@ pub fn evalZigProcess(...@@ -421,7 +425,7 @@ pub fn evalZigProcess(
421 const io = graph.io;425 const io = graph.io;
422426
423 // If an error occurs, it's happened in this command:427 // If an error occurs, it's happened in this command:
424 assert(s.result_failed_command == null);428 clearFailedCommand(s, gpa);
425 s.result_failed_command = try std.zig.allocPrintCmd(gpa, argv, .{});429 s.result_failed_command = try std.zig.allocPrintCmd(gpa, argv, .{});
426430
427 if (s.getZigProcess()) |zp| update: {431 if (s.getZigProcess()) |zp| update: {