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(...@@ -3404,23 +3404,25 @@ fn buildOutputType(
3404 },3404 },
3405 }3405 }
34063406
3407 const root_prog_node = std.Progress.start(.{3407 {
3408 .disable_printing = (color == .off),3408 const root_prog_node = std.Progress.start(.{
3409 });3409 .disable_printing = (color == .off),
3410 defer root_prog_node.end();3410 });
3411 defer root_prog_node.end();
34113412
3412 if (arg_mode == .translate_c) {3413 if (arg_mode == .translate_c) {
3413 return cmdTranslateC(comp, arena, null, root_prog_node);3414 return cmdTranslateC(comp, arena, null, root_prog_node);
3414 }3415 }
34153416
3416 updateModule(comp, color, root_prog_node) catch |err| switch (err) {3417 updateModule(comp, color, root_prog_node) catch |err| switch (err) {
3417 error.SemanticAnalyzeFail => {3418 error.SemanticAnalyzeFail => {
3418 assert(listen == .none);3419 assert(listen == .none);
3419 saveState(comp, debug_incremental);3420 saveState(comp, debug_incremental);
3420 process.exit(1);3421 process.exit(1);
3421 },3422 },
3422 else => |e| return e,3423 else => |e| return e,
3423 };3424 };
3425 }
3424 if (build_options.only_c) return cleanExit();3426 if (build_options.only_c) return cleanExit();
3425 try comp.makeBinFileExecutable();3427 try comp.makeBinFileExecutable();
3426 saveState(comp, debug_incremental);3428 saveState(comp, debug_incremental);
...@@ -4228,7 +4230,9 @@ fn runOrTest(...@@ -4228,7 +4230,9 @@ fn runOrTest(
4228 // the error message and invocation below.4230 // the error message and invocation below.
4229 if (process.can_execv and arg_mode == .run) {4231 if (process.can_execv and arg_mode == .run) {
4230 // execv releases the locks; no need to destroy the Compilation here.4232 // execv releases the locks; no need to destroy the Compilation here.
4233 std.debug.lockStdErr();
4231 const err = process.execve(gpa, argv.items, &env_map);4234 const err = process.execve(gpa, argv.items, &env_map);
4235 std.debug.unlockStdErr();
4232 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);4236 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
4233 const cmd = try std.mem.join(arena, " ", argv.items);4237 const cmd = try std.mem.join(arena, " ", argv.items);
4234 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });4238 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
...@@ -4244,7 +4248,12 @@ fn runOrTest(...@@ -4244,7 +4248,12 @@ fn runOrTest(
4244 comp.destroy();4248 comp.destroy();
4245 comp_destroyed.* = true;4249 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| {
4248 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);4257 try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
4249 const cmd = try std.mem.join(arena, " ", argv.items);4258 const cmd = try std.mem.join(arena, " ", argv.items);
4250 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });4259 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });