authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-31 12:39:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-31 18:59:53-04:00
log4918c2ce2d739ba5e1b207a2ef32afcc04bfc435
treeefc061985ba14f1cef915b35f911dc49c62d7b4e
parentc564a16a01811c18113fe304dbc3e8255af9f172

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 files changed, 15 insertions(+), 9 deletions(-)

lib/std/Build/Step/Run.zig+15-9
...@@ -1241,20 +1241,26 @@ fn spawnChildAndCollect(...@@ -1241,20 +1241,26 @@ fn spawnChildAndCollect(
1241 child.stdin_behavior = .Pipe;1241 child.stdin_behavior = .Pipe;
1242 }1242 }
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) {
1245 child.progress_node = prog_node;1247 child.progress_node = prog_node;
1246 }1248 }
12471249
1248 try child.spawn();1250 const term, const result, const elapsed_ns = t: {
1249 var timer = try std.time.Timer.start();1251 if (inherit) std.debug.lockStdErr();
1252 defer if (inherit) std.debug.unlockStdErr();
12501253
1251 const result = if (run.stdio == .zig_test)1254 try child.spawn();
1252 evalZigTest(run, &child, prog_node)1255 var timer = try std.time.Timer.start();
1253 else
1254 evalGeneric(run, &child);
12551256
1256 const term = try child.wait();1257 const result = if (run.stdio == .zig_test)
1257 const elapsed_ns = timer.read();1258 evalZigTest(run, &child, prog_node)
1259 else
1260 evalGeneric(run, &child);
1261
1262 break :t .{ try child.wait(), result, timer.read() };
1263 };
12581264
1259 return .{1265 return .{
1260 .stdio = try result,1266 .stdio = try result,