Skip to content

Commit e7e07f7

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Normalize repo dir
Uri.base, Platform.script and dart:io operations use the drive letter capitalization of the current working directory, but git, alas, does not. This normalizes the computeRepoDir to match that of Uri.base, thus avoiding spurious errors on Windows. Change-Id: If4324874fa9b5c73c679c1b67a9481371ce8808d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421161 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
1 parent a2ae02e commit e7e07f7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/front_end/test/utils/io_utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ String computeRepoDir() {
3535
if (!new Directory(dirPath).existsSync()) {
3636
throw "The path returned by git ($dirPath) does not actually exist.";
3737
}
38+
if (dirPath.length > 1 && dirPath[1] == ':') {
39+
// Absolute Windows path. Normalize drive letter to match Uri.base.
40+
if (Uri.base.path.length < 3 ||
41+
Uri.base.path[0] != '/' ||
42+
Uri.base.path[2] != ':') {
43+
throw "Expected Uri.base=${Uri.base} to be an absolute file path.";
44+
}
45+
bool isLowerCase = Uri.base.path[1] == Uri.base.path[1].toLowerCase();
46+
if (isLowerCase) {
47+
dirPath = dirPath[0].toLowerCase() + dirPath.substring(1);
48+
} else {
49+
dirPath = dirPath[0].toUpperCase() + dirPath.substring(1);
50+
}
51+
}
3852
return dirPath;
3953
}
4054

0 commit comments

Comments
 (0)