Skip to content

Commit 4918c2c

Browse files
committed
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
1 parent c564a16 commit 4918c2c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/std/Build/Step/Run.zig

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,20 +1241,26 @@ fn spawnChildAndCollect(
12411241
child.stdin_behavior = .Pipe;
12421242
}
12431243

1244-
if (run.stdio != .zig_test and !run.disable_zig_progress) {
1244+
const inherit = child.stdout_behavior == .Inherit or child.stderr_behavior == .Inherit;
1245+
1246+
if (run.stdio != .zig_test and !run.disable_zig_progress and !inherit) {
12451247
child.progress_node = prog_node;
12461248
}
12471249

1248-
try child.spawn();
1249-
var timer = try std.time.Timer.start();
1250+
const term, const result, const elapsed_ns = t: {
1251+
if (inherit) std.debug.lockStdErr();
1252+
defer if (inherit) std.debug.unlockStdErr();
12501253

1251-
const result = if (run.stdio == .zig_test)
1252-
evalZigTest(run, &child, prog_node)
1253-
else
1254-
evalGeneric(run, &child);
1254+
try child.spawn();
1255+
var timer = try std.time.Timer.start();
12551256

1256-
const term = try child.wait();
1257-
const elapsed_ns = timer.read();
1257+
const result = if (run.stdio == .zig_test)
1258+
evalZigTest(run, &child, prog_node)
1259+
else
1260+
evalGeneric(run, &child);
1261+
1262+
break :t .{ try child.wait(), result, timer.read() };
1263+
};
12581264

12591265
return .{
12601266
.stdio = try result,

0 commit comments

Comments
 (0)