From 7ef345f342534f93a7e61d9ecd096523f048871d Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 25 Jan 2025 08:11:00 +0000 Subject: [PATCH] incr-check: deal with Windows stupidity The real problem here is that Git for Windows has horrendous defaults which convert LF to CRLF. However, rather than changing this configuration on the CI runners, it's worth supporting inexplicable CRLF in these files so that anyone else cloning Zig on Windows doesn't get unexpected test failures. --- tools/incr-check.zig | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/incr-check.zig b/tools/incr-check.zig index bbdef19043..8ef3fddc56 100644 --- a/tools/incr-check.zig +++ b/tools/incr-check.zig @@ -660,21 +660,28 @@ const Case = struct { if (root_source_file == null) root_source_file = val; - const start_index = it.index.?; - const src = while (true) : (line_n += 1) { + // Because Windows is so excellent, we need to convert CRLF to LF, so + // can't just slice into the input here. How delightful! + var src: std.ArrayListUnmanaged(u8) = .empty; + + while (true) { const old = it; - const next_line = it.next() orelse fatal("line {d}: unexpected EOF", .{line_n}); + const next_line_raw = it.next() orelse fatal("line {d}: unexpected EOF", .{line_n}); + const next_line = std.mem.trimRight(u8, next_line_raw, "\r"); if (std.mem.startsWith(u8, next_line, "#")) { - const end_index = old.index.?; - const src = bytes[start_index..end_index]; it = old; - break src; + break; } - }; + line_n += 1; + + try src.ensureUnusedCapacity(arena, next_line.len + 1); + src.appendSliceAssumeCapacity(next_line); + src.appendAssumeCapacity('\n'); + } try changes.append(arena, .{ .name = val, - .bytes = src, + .bytes = src.items, }); } else if (std.mem.eql(u8, key, "rm_file")) { if (updates.items.len == 0) fatal("line {d}: rm_file directive before update", .{line_n});