authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 09:52:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 15:27:28-04:00
log0c2cd83814e9c4db6c51ff7c2ea2e4678a35f5e4
tree9fed070c5fa28684291e60deebf437dc5a77879d
parent2cf8e73781b81f38c50a40b42cad49242ef7c98b

zig run: finish progress node before executing child

also lock stderr for good measure. it's generally a good idea to lock stderr when you are spawning and waiting for a child that inherits stderr.

1 files changed, 25 insertions(+), 16 deletions(-)

src/main.zig+25-16
......@@ -3404,23 +3404,25 @@ fn buildOutputType(
34043404 },
34053405 }
34063406
3407 const root_prog_node = std.Progress.start(.{
3408 .disable_printing = (color == .off),
3409 });
3410 defer root_prog_node.end();
3407 {
3408 const root_prog_node = std.Progress.start(.{
3409 .disable_printing = (color == .off),
3410 });
3411 defer root_prog_node.end();
34113412
3412 if (arg_mode == .translate_c) {
3413 return cmdTranslateC(comp, arena, null, root_prog_node);
3414 }
3413 if (arg_mode == .translate_c) {
3414 return cmdTranslateC(comp, arena, null, root_prog_node);
3415 }
34153416
3416 updateModule(comp, color, root_prog_node) catch |err| switch (err) {
3417 error.SemanticAnalyzeFail => {
3418 assert(listen == .none);
3419 saveState(comp, debug_incremental);
3420 process.exit(1);
3421 },
3422 else => |e| return e,
3423 };
3417 updateModule(comp, color, root_prog_node) catch |err| switch (err) {
3418 error.SemanticAnalyzeFail => {
3419 assert(listen == .none);
3420 saveState(comp, debug_incremental);
3421 process.exit(1);
3422 },
3423 else => |e| return e,
3424 };
3425 }
34243426 if (build_options.only_c) return cleanExit();
34253427 try comp.makeBinFileExecutable();
34263428 saveState(comp, debug_incremental);
......@@ -4228,7 +4230,9 @@ fn runOrTest(
42284230 // the error message and invocation below.
42294231 if (process.can_execv and arg_mode == .run) {
42304232 // execv releases the locks; no need to destroy the Compilation here.
4233 std.debug.lockStdErr();
42314234 const err = process.execve(gpa, argv.items, &env_map);
4235 std.debug.unlockStdErr();
42324236 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
42334237 const cmd = try std.mem.join(arena, " ", argv.items);
42344238 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
......@@ -4244,7 +4248,12 @@ fn runOrTest(
42444248 comp.destroy();
42454249 comp_destroyed.* = true;
42464250
4247 const term = child.spawnAndWait() catch |err| {
4251 const term_result = t: {
4252 std.debug.lockStdErr();
4253 defer std.debug.unlockStdErr();
4254 break :t child.spawnAndWait();
4255 };
4256 const term = term_result catch |err| {
42484257 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
42494258 const cmd = try std.mem.join(arena, " ", argv.items);
42504259 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });