| ... | ... | @@ -374,10 +374,37 @@ pub fn evalZigProcess( |
| 374 | 374 | prog_node: std.Progress.Node, |
| 375 | 375 | watch: bool, |
| 376 | 376 | ) !?[]const u8 { |
| 377 | | if (s.getZigProcess()) |zp| { |
| 377 | if (s.getZigProcess()) |zp| update: { |
| 378 | 378 | assert(watch); |
| 379 | 379 | if (std.Progress.have_ipc) if (zp.progress_ipc_fd) |fd| prog_node.setIpcFd(fd); |
| 380 | | return zigProcessUpdate(s, zp, watch); |
| 380 | const result = zigProcessUpdate(s, zp, watch) catch |err| switch (err) { |
| 381 | error.BrokenPipe => { |
| 382 | // Process restart required. |
| 383 | const term = zp.child.wait() catch |e| { |
| 384 | return s.fail("unable to wait for {s}: {s}", .{ argv[0], @errorName(e) }); |
| 385 | }; |
| 386 | _ = term; |
| 387 | s.clearZigProcess(); |
| 388 | break :update; |
| 389 | }, |
| 390 | else => |e| return e, |
| 391 | }; |
| 392 | |
| 393 | if (s.result_error_bundle.errorMessageCount() > 0) |
| 394 | return s.fail("{d} compilation errors", .{s.result_error_bundle.errorMessageCount()}); |
| 395 | |
| 396 | if (s.result_error_msgs.items.len > 0 and result == null) { |
| 397 | // Crash detected. |
| 398 | const term = zp.child.wait() catch |e| { |
| 399 | return s.fail("unable to wait for {s}: {s}", .{ argv[0], @errorName(e) }); |
| 400 | }; |
| 401 | s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0; |
| 402 | s.clearZigProcess(); |
| 403 | try handleChildProcessTerm(s, term, null, argv); |
| 404 | return error.MakeFailed; |
| 405 | } |
| 406 | |
| 407 | return result; |
| 381 | 408 | } |
| 382 | 409 | assert(argv.len != 0); |
| 383 | 410 | const b = s.owner; |
| ... | ... | @@ -399,7 +426,7 @@ pub fn evalZigProcess( |
| 399 | 426 | argv[0], @errorName(err), |
| 400 | 427 | }); |
| 401 | 428 | |
| 402 | | const zp = try arena.create(ZigProcess); |
| 429 | const zp = try gpa.create(ZigProcess); |
| 403 | 430 | zp.* = .{ |
| 404 | 431 | .child = child, |
| 405 | 432 | .poller = std.io.poll(gpa, ZigProcess.StreamEnum, .{ |
| ... | ... | @@ -590,6 +617,20 @@ fn setZigProcess(s: *Step, zp: *ZigProcess) void { |
| 590 | 617 | } |
| 591 | 618 | } |
| 592 | 619 | |
| 620 | fn clearZigProcess(s: *Step) void { |
| 621 | const gpa = s.owner.allocator; |
| 622 | switch (s.id) { |
| 623 | .compile => { |
| 624 | const compile = s.cast(Compile).?; |
| 625 | if (compile.zig_process) |zp| { |
| 626 | gpa.destroy(zp); |
| 627 | compile.zig_process = null; |
| 628 | } |
| 629 | }, |
| 630 | else => unreachable, |
| 631 | } |
| 632 | } |
| 633 | |
| 593 | 634 | fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void { |
| 594 | 635 | const header: std.zig.Client.Message.Header = .{ |
| 595 | 636 | .tag = tag, |