std.Build.Step.Run: global lock when child inherits stderr

The docs for setting stdio to "inherit" say:

It also means that this step will obtain a global lock to prevent other
steps from running in the meantime.

The implementation of this lock was missing but is now provided by this
commit.

closes #20119
This commit is contained in:
Andrew Kelley
2024-05-31 12:39:08 -07:00
parent c564a16a01
commit 4918c2ce2d

View File

@@ -1241,20 +1241,26 @@ fn spawnChildAndCollect(
child.stdin_behavior = .Pipe;
}
if (run.stdio != .zig_test and !run.disable_zig_progress) {
const inherit = child.stdout_behavior == .Inherit or child.stderr_behavior == .Inherit;
if (run.stdio != .zig_test and !run.disable_zig_progress and !inherit) {
child.progress_node = prog_node;
}
try child.spawn();
var timer = try std.time.Timer.start();
const term, const result, const elapsed_ns = t: {
if (inherit) std.debug.lockStdErr();
defer if (inherit) std.debug.unlockStdErr();
const result = if (run.stdio == .zig_test)
evalZigTest(run, &child, prog_node)
else
evalGeneric(run, &child);
try child.spawn();
var timer = try std.time.Timer.start();
const term = try child.wait();
const elapsed_ns = timer.read();
const result = if (run.stdio == .zig_test)
evalZigTest(run, &child, prog_node)
else
evalGeneric(run, &child);
break :t .{ try child.wait(), result, timer.read() };
};
return .{
.stdio = try result,