update standalone and incremental tests to new API

This commit is contained in:
Andrew Kelley
2025-07-07 19:33:20 -07:00
parent c873c2eed9
commit d8e26275f2
72 changed files with 347 additions and 892 deletions

View File

@@ -43,8 +43,7 @@ pub fn main() !void {
while (args_it.next()) |arg| {
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
const stdout = io.getStdOut().writer();
try stdout.writeAll(usage);
try fs.File.stdout().writeAll(usage);
process.exit(0);
} else if (mem.eql(u8, arg, "--code-dir")) {
if (args_it.next()) |param| {

View File

@@ -44,7 +44,7 @@ pub fn main() !void {
while (args_it.next()) |arg| {
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try std.io.getStdOut().writeAll(usage);
try std.fs.File.stdout().writeAll(usage);
process.exit(0);
} else if (mem.eql(u8, arg, "-i")) {
opt_input = args_it.next() orelse fatal("expected parameter after -i", .{});

View File

@@ -48,8 +48,9 @@ pub fn main() !void {
fatal("failed to load coverage file {}: {s}", .{ cov_path, @errorName(err) });
};
var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
const stdout = bw.writer();
var stdout_buffer: [4000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
const stdout = &stdout_writer.interface;
const header: *SeenPcsHeader = @ptrCast(cov_bytes);
try stdout.print("{any}\n", .{header.*});
@@ -83,5 +84,5 @@ pub fn main() !void {
});
}
try bw.flush();
try stdout.flush();
}

View File

@@ -5,6 +5,8 @@ const mem = std.mem;
const process = std.process;
const assert = std.debug.assert;
const tmpDir = std.testing.tmpDir;
const fatal = std.process.fatal;
const info = std.log.info;
const Allocator = mem.Allocator;
const OsTag = std.Target.Os.Tag;
@@ -245,19 +247,6 @@ const ArgsIterator = struct {
}
};
fn info(comptime format: []const u8, args: anytype) void {
const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
std.io.getStdOut().writeAll(msg) catch {};
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
ret: {
const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
std.io.getStdErr().writeAll(msg) catch {};
}
std.process.exit(1);
}
const Version = struct {
major: u16,
minor: u8,

View File

@@ -1,5 +1,7 @@
const std = @import("std");
const assert = std.debug.assert;
const info = std.log.info;
const fatal = std.process.fatal;
const Allocator = std.mem.Allocator;
@@ -13,19 +15,6 @@ const usage =
\\-h, --help Print this help and exit
;
fn info(comptime format: []const u8, args: anytype) void {
const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
std.io.getStdOut().writeAll(msg) catch {};
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
ret: {
const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
std.io.getStdErr().writeAll(msg) catch {};
}
std.process.exit(1);
}
pub fn main() anyerror!void {
var arena_allocator = std.heap.ArenaAllocator.init(gpa);
defer arena_allocator.deinit();
@@ -58,16 +47,19 @@ pub fn main() anyerror!void {
std.mem.sort([]const u8, paths.items, {}, SortFn.lessThan);
const stdout = std.io.getStdOut().writer();
try stdout.writeAll("#define _XOPEN_SOURCE\n");
var buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
const w = &stdout_writer.interface;
try w.writeAll("#define _XOPEN_SOURCE\n");
for (paths.items) |path| {
try stdout.print("#include <{s}>\n", .{path});
try w.print("#include <{s}>\n", .{path});
}
try stdout.writeAll(
try w.writeAll(
\\int main(int argc, char **argv) {
\\ return 0;
\\}
);
try w.flush();
}
fn findHeaders(

View File

@@ -17,8 +17,9 @@ pub fn main() !void {
//const args = try std.process.argsAlloc(arena);
var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
const w = bw.writer();
var stdout_buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
const w = &stdout_writer.interface;
try w.writeAll(
\\//! This file is generated by tools/gen_outline_atomics.zig.
@@ -57,7 +58,7 @@ pub fn main() !void {
try w.writeAll(footer.items);
try w.writeAll("}\n");
try bw.flush();
try w.flush();
}
fn writeFunction(

View File

@@ -91,9 +91,10 @@ pub fn main() !void {
try readExtRegistry(&exts, a, std.fs.cwd(), args[2]);
var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
try render(bw.writer(), a, core_spec, exts.items);
try bw.flush();
var buffer: [4000]u8 = undefined;
var w = std.fs.File.stdout().writerStreaming(&buffer);
try render(&w, a, core_spec, exts.items);
try w.flush();
}
fn readExtRegistry(exts: *std.ArrayList(Extension), a: Allocator, dir: std.fs.Dir, sub_path: []const u8) !void {
@@ -166,7 +167,7 @@ fn tagPriorityScore(tag: []const u8) usize {
}
}
fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {
fn render(writer: *std.io.Writer, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {
try writer.writeAll(
\\//! This file is auto-generated by tools/gen_spirv_spec.zig.
\\
@@ -188,15 +189,10 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
\\ none,
\\ _,
\\
\\ pub fn format(
\\ self: IdResult,
\\ comptime _: []const u8,
\\ _: std.fmt.FormatOptions,
\\ writer: anytype,
\\ ) @TypeOf(writer).Error!void {
\\ pub fn format(self: IdResult, writer: *std.io.Writer) std.io.Writer.Error!void {
\\ switch (self) {
\\ .none => try writer.writeAll("(none)"),
\\ else => try writer.print("%{}", .{@intFromEnum(self)}),
\\ else => try writer.print("%{d}", .{@intFromEnum(self)}),
\\ }
\\ }
\\};
@@ -899,7 +895,8 @@ fn parseHexInt(text: []const u8) !u31 {
}
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
std.io.getStdErr().writer().print(
const stderr = std.debug.lockStderrWriter(&.{});
stderr.print(
\\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>
\\
\\Generates Zig bindings for SPIR-V specifications found in the SPIRV-Headers

View File

@@ -333,7 +333,9 @@ pub fn main() !void {
}
}
const stdout = std.io.getStdOut().writer();
var stdout_buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
const stdout = &stdout_writer.interface;
try stdout.writeAll(
\\#ifdef PTR64
\\#define WEAK64 .weak
@@ -533,6 +535,8 @@ pub fn main() !void {
.all => {},
.single, .multi, .family, .time32 => try stdout.writeAll("#endif\n"),
}
try stdout.flush();
}
fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) !void {

View File

@@ -6,7 +6,9 @@ pub fn main() !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
var allocator = gpa.allocator();
var output = std.io.getStdOut().writer();
var stdout_buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
const output = &stdout_writer.interface;
try output.writeAll(
\\// This file was generated by _generate_JSONTestSuite.zig
\\// These test cases are sourced from: https://github.com/nst/JSONTestSuite
@@ -44,6 +46,8 @@ pub fn main() !void {
try writeString(output, contents);
try output.writeAll(");\n}\n");
}
try output.flush();
}
const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500;

View File

@@ -42,20 +42,23 @@ pub fn main() !void {
const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] });
const target = try std.zig.system.resolveTargetQuery(query);
const stdout = std.io.getStdOut().writer();
var buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
const w = &stdout_writer.interface;
inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {
const c_type: std.Target.CType = @enumFromInt(field.value);
try stdout.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
cName(c_type),
target.cTypeByteSize(c_type),
});
try stdout.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
try w.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
cName(c_type),
target.cTypeAlignment(c_type),
});
try stdout.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
try w.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
cName(c_type),
target.cTypePreferredAlignment(c_type),
});
}
try w.flush();
}

View File

@@ -666,13 +666,16 @@ pub fn main() !void {
const allocator = arena.allocator();
const args = try std.process.argsAlloc(allocator);
if (args.len < 3 or mem.eql(u8, args[1], "--help"))
usageAndExit(std.io.getStdErr(), args[0], 1);
if (args.len < 3 or mem.eql(u8, args[1], "--help")) {
usage(std.debug.lockStderrWriter(&.{}), args[0]) catch std.process.exit(2);
std.process.exit(1);
}
const zig_exe = args[1];
const linux_path = args[2];
var buf_out = std.io.bufferedWriter(std.io.getStdOut().writer());
const writer = buf_out.writer();
var stdout_buffer: [2000]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
const writer = &stdout_writer.interface;
var linux_dir = try std.fs.cwd().openDir(linux_path, .{});
defer linux_dir.close();
@@ -714,17 +717,16 @@ pub fn main() !void {
}
}
try buf_out.flush();
try writer.flush();
}
fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
file.writer().print(
fn usage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
try w.print(
\\Usage: {s} /path/to/zig /path/to/linux
\\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux
\\
\\Generates the list of Linux syscalls for each supported cpu arch, using the Linux development tree.
\\Prints to stdout Zig code which you can use to replace the file lib/std/os/linux/syscalls.zig.
\\
, .{arg0}) catch std.process.exit(1);
std.process.exit(code);
, .{arg0});
}

View File

@@ -634,25 +634,25 @@ pub fn main() anyerror!void {
const allocator = arena.allocator();
const args = try std.process.argsAlloc(allocator);
if (args.len <= 1) {
usageAndExit(std.io.getStdErr(), args[0], 1);
}
var stdout_buffer: [4000]u8 = undefined;
var stdout_writer = fs.stdout().writerStreaming(&stdout_buffer);
const stdout = &stdout_writer.interface;
if (args.len <= 1) printUsageAndExit(args[0]);
if (std.mem.eql(u8, args[1], "--help")) {
usageAndExit(std.io.getStdOut(), args[0], 0);
}
if (args.len < 3) {
usageAndExit(std.io.getStdErr(), args[0], 1);
printUsage(stdout, args[0]) catch std.process.exit(2);
stdout.flush() catch std.process.exit(2);
std.process.exit(0);
}
if (args.len < 3) printUsageAndExit(args[0]);
const llvm_tblgen_exe = args[1];
if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) {
usageAndExit(std.io.getStdErr(), args[0], 1);
}
if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) printUsageAndExit(args[0]);
const llvm_src_root = args[2];
if (std.mem.startsWith(u8, llvm_src_root, "-")) {
usageAndExit(std.io.getStdErr(), args[0], 1);
}
if (std.mem.startsWith(u8, llvm_src_root, "-")) printUsageAndExit(args[0]);
var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(allocator);
@@ -719,8 +719,6 @@ pub fn main() anyerror!void {
// "W" and "Wl,". So we sort this list in order of descending priority.
std.mem.sort(*json.ObjectMap, all_objects.items, {}, objectLessThan);
var buffered_stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
const stdout = buffered_stdout.writer();
try stdout.writeAll(
\\// This file is generated by tools/update_clang_options.zig.
\\// zig fmt: off
@@ -815,7 +813,7 @@ pub fn main() anyerror!void {
\\
);
try buffered_stdout.flush();
try stdout.flush();
}
// TODO we should be able to import clang_options.zig but currently this is problematic because it will
@@ -966,13 +964,17 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
return std.mem.lessThan(u8, a_key, b_key);
}
fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
file.writer().print(
fn printUsageAndExit(arg0: []const u8) noreturn {
printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
std.process.exit(1);
}
fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
try w.print(
\\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
\\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
\\
\\Prints to stdout Zig code which you can use to replace the file src/clang_options_data.zig.
\\
, .{arg0}) catch std.process.exit(1);
std.process.exit(code);
, .{arg0});
}

View File

@@ -2082,8 +2082,8 @@ fn processOneTarget(job: Job) void {
}
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
const stderr = std.io.getStdErr();
stderr.writer().print(
const stderr = std.debug.lockStderrWriter(&.{});
stderr.print(
\\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]
\\
\\Updates lib/std/target/<target>.zig from llvm/lib/Target/<Target>/<Target>.td .

View File

@@ -11,14 +11,10 @@ pub fn main() anyerror!void {
const arena = arena_state.allocator();
const args = try std.process.argsAlloc(arena);
if (args.len <= 1) {
usageAndExit(std.io.getStdErr(), args[0], 1);
}
if (args.len <= 1) printUsageAndExit(args[0]);
const zig_src_root = args[1];
if (mem.startsWith(u8, zig_src_root, "-")) {
usageAndExit(std.io.getStdErr(), args[0], 1);
}
if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);
var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
defer zig_src_dir.close();
@@ -193,10 +189,14 @@ pub fn main() anyerror!void {
}
}
fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
file.writer().print(
fn printUsageAndExit(arg0: []const u8) noreturn {
printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
std.process.exit(1);
}
fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
return w.print(
\\Usage: {s} /path/git/zig
\\
, .{arg0}) catch std.process.exit(1);
std.process.exit(code);
, .{arg0});
}