mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
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.
This commit is contained in:
parent
74c23a237e
commit
74931fe25c
37 changed files with 169 additions and 193 deletions
|
|
@ -89,10 +89,9 @@ pub fn main() !void {
|
|||
const output = allocating.written()[0 .. allocating.written().len - 1 :0];
|
||||
|
||||
var tree = try std.zig.Ast.parse(allocator, output, .zig);
|
||||
var color: std.zig.Color = .on;
|
||||
|
||||
if (tree.errors.len != 0) {
|
||||
try std.zig.printAstErrorsToStderr(allocator, tree, "", color);
|
||||
try std.zig.printAstErrorsToStderr(allocator, tree, "", .auto);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +103,7 @@ pub fn main() !void {
|
|||
try wip_errors.addZirErrorMessages(zir, tree, output, "");
|
||||
var error_bundle = try wip_errors.toOwnedBundle("");
|
||||
defer error_bundle.deinit(allocator);
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
error_bundle.renderToStdErr(.{}, .auto);
|
||||
}
|
||||
|
||||
const formatted_output = try tree.renderAlloc(allocator);
|
||||
|
|
@ -931,7 +930,7 @@ fn parseHexInt(text: []const u8) !u31 {
|
|||
}
|
||||
|
||||
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
|
||||
const stderr = std.debug.lockStderrWriter(&.{});
|
||||
const stderr, _ = std.debug.lockStderrWriter(&.{});
|
||||
stderr.print(
|
||||
\\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>
|
||||
\\
|
||||
|
|
|
|||
|
|
@ -177,7 +177,9 @@ pub fn main() !void {
|
|||
|
||||
const args = try std.process.argsAlloc(gpa);
|
||||
if (args.len < 2 or mem.eql(u8, args[1], "--help")) {
|
||||
usage(std.debug.lockStderrWriter(&.{}), args[0]) catch std.process.exit(2);
|
||||
const w, _ = std.debug.lockStderrWriter(&.{});
|
||||
defer std.debug.unlockStderrWriter();
|
||||
usage(w, args[0]) catch std.process.exit(2);
|
||||
std.process.exit(1);
|
||||
}
|
||||
const linux_path = args[1];
|
||||
|
|
|
|||
|
|
@ -340,8 +340,7 @@ const Eval = struct {
|
|||
.unknown => return,
|
||||
.compile_errors => |ce| ce,
|
||||
.stdout, .exit_code => {
|
||||
const color: std.zig.Color = .auto;
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
error_bundle.renderToStdErr(.{}, .auto);
|
||||
eval.fatal("update '{s}': unexpected compile errors", .{update.name});
|
||||
},
|
||||
};
|
||||
|
|
@ -350,8 +349,7 @@ const Eval = struct {
|
|||
|
||||
for (error_bundle.getMessages()) |err_idx| {
|
||||
if (expected_idx == expected.errors.len) {
|
||||
const color: std.zig.Color = .auto;
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
error_bundle.renderToStdErr(.{}, .auto);
|
||||
eval.fatal("update '{s}': more errors than expected", .{update.name});
|
||||
}
|
||||
try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], false, err_idx);
|
||||
|
|
@ -359,8 +357,7 @@ const Eval = struct {
|
|||
|
||||
for (error_bundle.getNotes(err_idx)) |note_idx| {
|
||||
if (expected_idx == expected.errors.len) {
|
||||
const color: std.zig.Color = .auto;
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
error_bundle.renderToStdErr(.{}, .auto);
|
||||
eval.fatal("update '{s}': more error notes than expected", .{update.name});
|
||||
}
|
||||
try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], true, note_idx);
|
||||
|
|
@ -369,8 +366,7 @@ const Eval = struct {
|
|||
}
|
||||
|
||||
if (!std.mem.eql(u8, error_bundle.getCompileLogOutput(), expected.compile_log_output)) {
|
||||
const color: std.zig.Color = .auto;
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
error_bundle.renderToStdErr(.{}, .auto);
|
||||
eval.fatal("update '{s}': unexpected compile log output", .{update.name});
|
||||
}
|
||||
}
|
||||
|
|
@ -404,8 +400,7 @@ const Eval = struct {
|
|||
expected.column != src.column + 1 or
|
||||
!std.mem.eql(u8, expected.msg, msg))
|
||||
{
|
||||
const color: std.zig.Color = .auto;
|
||||
eb.renderToStdErr(color.renderOptions());
|
||||
eb.renderToStdErr(.{}, .auto);
|
||||
eval.fatal("update '{s}': compile error did not match expected error", .{update.name});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -961,7 +961,9 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
|
|||
}
|
||||
|
||||
fn printUsageAndExit(arg0: []const u8) noreturn {
|
||||
printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
|
||||
const w, _ = std.debug.lockStderrWriter(&.{});
|
||||
defer std.debug.unlockStderrWriter();
|
||||
printUsage(w, arg0) catch std.process.exit(2);
|
||||
std.process.exit(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2167,7 +2167,7 @@ fn processOneTarget(job: Job) void {
|
|||
}
|
||||
|
||||
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
|
||||
const stderr = std.debug.lockStderrWriter(&.{});
|
||||
const stderr, _ = std.debug.lockStderrWriter(&.{});
|
||||
stderr.print(
|
||||
\\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]
|
||||
\\
|
||||
|
|
|
|||
|
|
@ -190,7 +190,9 @@ pub fn main() anyerror!void {
|
|||
}
|
||||
|
||||
fn printUsageAndExit(arg0: []const u8) noreturn {
|
||||
printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
|
||||
const w, _ = std.debug.lockStderrWriter(&.{});
|
||||
defer std.debug.unlockStderrWriter();
|
||||
printUsage(w, arg0) catch std.process.exit(2);
|
||||
std.process.exit(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue