authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-11 13:42:47-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
logc4cefd68358470d464bf66bc41985cadd874db73
tree4baa0f228bb20d2ffd9fe94753e215b3fb09bfcf
parent91fa252cf20554495e719cacf83f488bef740a67

std.Build.Step.Run: restore Color.inherit logic


1 files changed, 33 insertions(+), 25 deletions(-)

lib/std/Build/Step/Run.zig+33-25
......@@ -1257,30 +1257,6 @@ fn runCommand(
12571257 };
12581258 defer env_map.deinit();
12591259
1260 color: switch (run.color) {
1261 .manual => {},
1262 .enable => {
1263 try env_map.put("CLICOLOR_FORCE", "1");
1264 env_map.remove("NO_COLOR");
1265 },
1266 .disable => {
1267 try env_map.put("NO_COLOR", "1");
1268 env_map.remove("CLICOLOR_FORCE");
1269 },
1270 .inherit => {},
1271 .auto => {
1272 const capture_stderr = run.captured_stderr != null or switch (run.stdio) {
1273 .check => |checks| checksContainStderr(checks.items),
1274 .infer_from_args, .inherit, .zig_test => false,
1275 };
1276 if (capture_stderr) {
1277 continue :color .disable;
1278 } else {
1279 continue :color .inherit;
1280 }
1281 },
1282 }
1283
12841260 const opt_generic_result = spawnChildAndCollect(run, argv, &env_map, has_side_effects, options, fuzz_context) catch |err| term: {
12851261 // InvalidExe: cpu arch mismatch
12861262 // FileNotFound: can happen with a wrong dynamic linker path
......@@ -1648,7 +1624,10 @@ fn spawnChildAndCollect(
16481624 if (!run.disable_zig_progress and !inherit) {
16491625 child.progress_node = options.progress_node;
16501626 }
1651 if (inherit) _ = std.debug.lockStderrWriter(&.{});
1627 if (inherit) {
1628 const stderr = std.debug.lockStderrWriter(&.{});
1629 try setColorEnvironmentVariables(run, env_map, stderr.mode);
1630 }
16521631 defer if (inherit) std.debug.unlockStderrWriter();
16531632 var timer = try std.time.Timer.start();
16541633 const res = try evalGeneric(run, &child);
......@@ -1657,6 +1636,35 @@ fn spawnChildAndCollect(
16571636 }
16581637}
16591638
1639fn setColorEnvironmentVariables(run: *Run, env_map: *EnvMap, fwm: Io.File.Writer.Mode) !void {
1640 color: switch (run.color) {
1641 .manual => {},
1642 .enable => {
1643 try env_map.put("CLICOLOR_FORCE", "1");
1644 env_map.remove("NO_COLOR");
1645 },
1646 .disable => {
1647 try env_map.put("NO_COLOR", "1");
1648 env_map.remove("CLICOLOR_FORCE");
1649 },
1650 .inherit => switch (fwm) {
1651 .terminal_escaped => continue :color .enable,
1652 else => continue :color .disable,
1653 },
1654 .auto => {
1655 const capture_stderr = run.captured_stderr != null or switch (run.stdio) {
1656 .check => |checks| checksContainStderr(checks.items),
1657 .infer_from_args, .inherit, .zig_test => false,
1658 };
1659 if (capture_stderr) {
1660 continue :color .disable;
1661 } else {
1662 continue :color .inherit;
1663 }
1664 },
1665 }
1666}
1667
16601668const StdioPollEnum = enum { stdout, stderr };
16611669
16621670fn evalZigTest(