authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-25 08:11:00+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-25 08:57:20+00:00
log7ef345f342534f93a7e61d9ecd096523f048871d
tree6a780b3130783fd9d3f8fe2c6dd6b367e1069841
parentf47b8de2ad706616b648c52f5036102cb804e65d
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 15 insertions(+), 8 deletions(-)

tools/incr-check.zig+15-8
...@@ -660,21 +660,28 @@ const Case = struct {...@@ -660,21 +660,28 @@ const Case = struct {
660 if (root_source_file == null)660 if (root_source_file == null)
661 root_source_file = val;661 root_source_file = val;
662662
663 const start_index = it.index.?;663 // Because Windows is so excellent, we need to convert CRLF to LF, so
664 const src = while (true) : (line_n += 1) {664 // can't just slice into the input here. How delightful!
665 var src: std.ArrayListUnmanaged(u8) = .empty;
666
667 while (true) {
665 const old = it;668 const old = it;
666 const next_line = it.next() orelse fatal("line {d}: unexpected EOF", .{line_n});669 const next_line_raw = it.next() orelse fatal("line {d}: unexpected EOF", .{line_n});
670 const next_line = std.mem.trimRight(u8, next_line_raw, "\r");
667 if (std.mem.startsWith(u8, next_line, "#")) {671 if (std.mem.startsWith(u8, next_line, "#")) {
668 const end_index = old.index.?;
669 const src = bytes[start_index..end_index];
670 it = old;672 it = old;
671 break src;673 break;
672 }674 }
673 };675 line_n += 1;
676
677 try src.ensureUnusedCapacity(arena, next_line.len + 1);
678 src.appendSliceAssumeCapacity(next_line);
679 src.appendAssumeCapacity('\n');
680 }
674681
675 try changes.append(arena, .{682 try changes.append(arena, .{
676 .name = val,683 .name = val,
677 .bytes = src,684 .bytes = src.items,
678 });685 });
679 } else if (std.mem.eql(u8, key, "rm_file")) {686 } else if (std.mem.eql(u8, key, "rm_file")) {
680 if (updates.items.len == 0) fatal("line {d}: rm_file directive before update", .{line_n});687 if (updates.items.len == 0) fatal("line {d}: rm_file directive before update", .{line_n});