From 4918c2ce2d739ba5e1b207a2ef32afcc04bfc435 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 31 May 2024 12:39:08 -0700 Subject: [PATCH] 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 --- lib/std/Build/Step/Run.zig | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 1ecc3334c4..ac3418dd95 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -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,