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

@@ -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});
}