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.
This commit is contained in:
Andrew Kelley 2024-06-02 09:52:06 -07:00
parent 2cf8e73781
commit 0c2cd83814

View File

@ -3404,23 +3404,25 @@ fn buildOutputType(
},
}
const root_prog_node = std.Progress.start(.{
.disable_printing = (color == .off),
});
defer root_prog_node.end();
{
const root_prog_node = std.Progress.start(.{
.disable_printing = (color == .off),
});
defer root_prog_node.end();
if (arg_mode == .translate_c) {
return cmdTranslateC(comp, arena, null, root_prog_node);
if (arg_mode == .translate_c) {
return cmdTranslateC(comp, arena, null, root_prog_node);
}
updateModule(comp, color, root_prog_node) catch |err| switch (err) {
error.SemanticAnalyzeFail => {
assert(listen == .none);
saveState(comp, debug_incremental);
process.exit(1);
},
else => |e| return e,
};
}
updateModule(comp, color, root_prog_node) catch |err| switch (err) {
error.SemanticAnalyzeFail => {
assert(listen == .none);
saveState(comp, debug_incremental);
process.exit(1);
},
else => |e| return e,
};
if (build_options.only_c) return cleanExit();
try comp.makeBinFileExecutable();
saveState(comp, debug_incremental);
@ -4228,7 +4230,9 @@ fn runOrTest(
// the error message and invocation below.
if (process.can_execv and arg_mode == .run) {
// execv releases the locks; no need to destroy the Compilation here.
std.debug.lockStdErr();
const err = process.execve(gpa, argv.items, &env_map);
std.debug.unlockStdErr();
try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
@ -4244,7 +4248,12 @@ fn runOrTest(
comp.destroy();
comp_destroyed.* = true;
const term = child.spawnAndWait() catch |err| {
const term_result = t: {
std.debug.lockStdErr();
defer std.debug.unlockStdErr();
break :t child.spawnAndWait();
};
const term = term_result catch |err| {
try warnAboutForeignBinaries(arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });