Skip to content

Commit 56acaee

Browse files
DanTupcommit-bot@chromium.org
authored andcommitted
Normalize Windows drive letters to uppercase for analysis
This fixes #32095, ~~however I'm currently unable to get the tests running locally. I'll continue to work on that, but I'm hoping that creating a PR runs all the tests on CI so we should at least get to see if this (legitimately) broke anything in the meantime?~~ Turns out this also fixes #32042! I can't run the latest analyzer code against a version of the SDK that the flutter_tools is happy with, however I rolled my analyzer code back to `2.0-dev.22` and repro'd this error, then applied the same changes from this PR to that version, and the errors went away. Turns out to also fix #28895! @bwilkerson Closes #32133 #32133 GitOrigin-RevId: 94cc374 Change-Id: I32a5ce52c7b28e1d484c1e5e9a9dd6d64c2b1b3b Reviewed-on: https://dart-review.googlesource.com/40720 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 396ba9b commit 56acaee

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

pkg/analyzer/lib/file_system/physical_file_system.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ List<int> _pathsToTimes(List<String> paths) {
3939
}).toList();
4040
}
4141

42+
/**
43+
* Return a (semi-)canonicalized version of [path] for the purpose of analysis.
44+
*
45+
* Using the built-in path's [canonicalize] results in fully lowercase paths on
46+
* Windows displayed to the user so this method uses [normalize] and then just
47+
* uppercases the drive letter on Windows to resolve the most common issues.
48+
*/
49+
String _canonicalize(String path) {
50+
path = normalize(path);
51+
// Ideally we'd call path's [canonicalize] here to ensure that on
52+
// case-insensitive file systems that different casing paths resolved to the
53+
// same thing; however these paths are used both as both as part of the
54+
// identity and also to display to users in error messages so for now we only
55+
// canonicalize the drive letter to resolve the most common issues.
56+
// https://github.com/dart-lang/sdk/issues/32095
57+
if (io.Platform.isWindows && isAbsolute(path)) {
58+
path = path.substring(0, 1).toUpperCase() + path.substring(1);
59+
}
60+
return path;
61+
}
62+
4263
/**
4364
* The name of the directory containing plugin specific subfolders used to
4465
* store data across sessions.
@@ -90,13 +111,13 @@ class PhysicalResourceProvider implements ResourceProvider {
90111

91112
@override
92113
File getFile(String path) {
93-
path = normalize(path);
114+
path = _canonicalize(path);
94115
return new _PhysicalFile(new io.File(path));
95116
}
96117

97118
@override
98119
Folder getFolder(String path) {
99-
path = normalize(path);
120+
path = _canonicalize(path);
100121
return new _PhysicalFolder(new io.Directory(path));
101122
}
102123

@@ -255,7 +276,7 @@ class _PhysicalFolder extends _PhysicalResource implements Folder {
255276

256277
@override
257278
String canonicalizePath(String relPath) {
258-
return normalize(join(path, relPath));
279+
return _canonicalize(join(path, relPath));
259280
}
260281

261282
@override

0 commit comments

Comments
 (0)