aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-11 13:42:47 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:09 -0800
commitc4cefd68358470d464bf66bc41985cadd874db73 (patch)
tree4baa0f228bb20d2ffd9fe94753e215b3fb09bfcf /lib/std/Build/Step
parent91fa252cf20554495e719cacf83f488bef740a67 (diff)
downloadzig-c4cefd68358470d464bf66bc41985cadd874db73.tar.gz
zig-c4cefd68358470d464bf66bc41985cadd874db73.zip
std.Build.Step.Run: restore Color.inherit logic
Diffstat (limited to 'lib/std/Build/Step')
-rw-r--r--lib/std/Build/Step/Run.zig58
1 files changed, 33 insertions, 25 deletions
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index 8aafc77820..f1e5313905 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1257,30 +1257,6 @@ fn runCommand(
};
defer env_map.deinit();
- color: switch (run.color) {
- .manual => {},
- .enable => {
- try env_map.put("CLICOLOR_FORCE", "1");
- env_map.remove("NO_COLOR");
- },
- .disable => {
- try env_map.put("NO_COLOR", "1");
- env_map.remove("CLICOLOR_FORCE");
- },
- .inherit => {},
- .auto => {
- const capture_stderr = run.captured_stderr != null or switch (run.stdio) {
- .check => |checks| checksContainStderr(checks.items),
- .infer_from_args, .inherit, .zig_test => false,
- };
- if (capture_stderr) {
- continue :color .disable;
- } else {
- continue :color .inherit;
- }
- },
- }
-
const opt_generic_result = spawnChildAndCollect(run, argv, &env_map, has_side_effects, options, fuzz_context) catch |err| term: {
// InvalidExe: cpu arch mismatch
// FileNotFound: can happen with a wrong dynamic linker path
@@ -1648,7 +1624,10 @@ fn spawnChildAndCollect(
if (!run.disable_zig_progress and !inherit) {
child.progress_node = options.progress_node;
}
- if (inherit) _ = std.debug.lockStderrWriter(&.{});
+ if (inherit) {
+ const stderr = std.debug.lockStderrWriter(&.{});
+ try setColorEnvironmentVariables(run, env_map, stderr.mode);
+ }
defer if (inherit) std.debug.unlockStderrWriter();
var timer = try std.time.Timer.start();
const res = try evalGeneric(run, &child);
@@ -1657,6 +1636,35 @@ fn spawnChildAndCollect(
}
}
+fn setColorEnvironmentVariables(run: *Run, env_map: *EnvMap, fwm: Io.File.Writer.Mode) !void {
+ color: switch (run.color) {
+ .manual => {},
+ .enable => {
+ try env_map.put("CLICOLOR_FORCE", "1");
+ env_map.remove("NO_COLOR");
+ },
+ .disable => {
+ try env_map.put("NO_COLOR", "1");
+ env_map.remove("CLICOLOR_FORCE");
+ },
+ .inherit => switch (fwm) {
+ .terminal_escaped => continue :color .enable,
+ else => continue :color .disable,
+ },
+ .auto => {
+ const capture_stderr = run.captured_stderr != null or switch (run.stdio) {
+ .check => |checks| checksContainStderr(checks.items),
+ .infer_from_args, .inherit, .zig_test => false,
+ };
+ if (capture_stderr) {
+ continue :color .disable;
+ } else {
+ continue :color .inherit;
+ }
+ },
+ }
+}
+
const StdioPollEnum = enum { stdout, stderr };
fn evalZigTest(