diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-10-28 12:42:05 +0000 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-10-30 09:31:28 +0000 |
| commit | 74931fe25cdd94e1cd08b5ece9dcce19959bc079 (patch) | |
| tree | 75449b1d594d55a872aeb03f2dd3be16ac396274 /lib/std/Build.zig | |
| parent | 74c23a237ef5245b63eb06b832a511aabeb715c0 (diff) | |
| download | zig-74931fe25cdd94e1cd08b5ece9dcce19959bc079.tar.gz zig-74931fe25cdd94e1cd08b5ece9dcce19959bc079.zip | |
std.debug.lockStderrWriter: also return ttyconf
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving
syscalls), and doing it every time we need to print isn't really
necessary; under normal usage, we can compute the value once and cache
it for the whole program's execution. Since anyone outputting to stderr
may reasonably want this information (in fact they are very likely to),
it makes sense to cache it and return it from `lockStderrWriter`. Call
sites who do not need it will experience no significant overhead, and
can just ignore the TTY config with a `const w, _` destructure.
Diffstat (limited to 'lib/std/Build.zig')
| -rw-r--r-- | lib/std/Build.zig | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/std/Build.zig b/lib/std/Build.zig index e9d2e81fba..3b78fc6f71 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2257,8 +2257,8 @@ pub const GeneratedFile = struct { pub fn getPath2(gen: GeneratedFile, src_builder: *Build, asking_step: ?*Step) []const u8 { return gen.path orelse { - const w = debug.lockStderrWriter(&.{}); - dumpBadGetPathHelp(gen.step, w, .detect(.stderr()), src_builder, asking_step) catch {}; + const w, const ttyconf = debug.lockStderrWriter(&.{}); + dumpBadGetPathHelp(gen.step, w, ttyconf, src_builder, asking_step) catch {}; debug.unlockStderrWriter(); @panic("misconfigured build script"); }; @@ -2466,8 +2466,8 @@ pub const LazyPath = union(enum) { var file_path: Cache.Path = .{ .root_dir = Cache.Directory.cwd(), .sub_path = gen.file.path orelse { - const w = debug.lockStderrWriter(&.{}); - dumpBadGetPathHelp(gen.file.step, w, .detect(.stderr()), src_builder, asking_step) catch {}; + const w, const ttyconf = debug.lockStderrWriter(&.{}); + dumpBadGetPathHelp(gen.file.step, w, ttyconf, src_builder, asking_step) catch {}; debug.unlockStderrWriter(); @panic("misconfigured build script"); }, @@ -2558,13 +2558,11 @@ fn dumpBadDirnameHelp( comptime msg: []const u8, args: anytype, ) anyerror!void { - const w = debug.lockStderrWriter(&.{}); + const w, const tty_config = debug.lockStderrWriter(&.{}); defer debug.unlockStderrWriter(); try w.print(msg, args); - const tty_config = std.Io.tty.detectConfig(.stderr()); - if (fail_step) |s| { tty_config.setColor(w, .red) catch {}; try w.writeAll(" The step was created by this stack trace:\n"); |
