Skip to content

Commit

Permalink
incr-check: deal with Windows stupidity
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mlugg committed Jan 25, 2025
1 parent f47b8de commit 7ef345f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tools/incr-check.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down

0 comments on commit 7ef345f

Please sign in to comment.