tint: handle CRLF on Windows when splitting WGSL source

When splitting WGSL source lines, detect and split along CRLF, not just
LF. Before this fix, when emitting error diagnostics on Windows, we'd
emit the CR at the end. Not normally a big deal, but it made our e2e
tests fail when the source WGSL had CRLFs in it: when comparing against
expected files, even though we'd replace CRLF with LF, we'd fail the
comparison because the actual output would contain CRCRLFs.

Change-Id: I360e0d4cd0f29ff76938ff32d7cb84e45feda2b0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86201
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2022-04-08 18:52:56 +00:00 committed by Dawn LUCI CQ
parent 96e245e576
commit 81e497c45f
1 changed files with 6 additions and 1 deletions

View File

@ -27,7 +27,12 @@ std::vector<std::string_view> SplitLines(std::string_view str) {
size_t lineStart = 0;
for (size_t i = 0; i < str.size(); ++i) {
if (str[i] == '\n') {
lines.push_back(str.substr(lineStart, i - lineStart));
// Handle CRLF on Windows
size_t curr = i;
if (i > 0 && str[i - 1] == '\r') {
--curr;
}
lines.push_back(str.substr(lineStart, curr - lineStart));
lineStart = i + 1;
}
}