Always normalize paths before they are passed to the analyzer (#2409)
diff --git a/lib/src/command/deps.dart b/lib/src/command/deps.dart
index 2651400..ac22043 100644
--- a/lib/src/command/deps.dart
+++ b/lib/src/command/deps.dart
@@ -280,7 +280,6 @@
/// Returns `true` if [path] looks like a Dart entrypoint.
bool _isDartExecutable(String path) {
try {
- path = p.normalize(path);
var unit = analysisContextManager.parse(path);
return isEntrypoint(unit);
} on AnalyzerErrorGroup {
diff --git a/lib/src/dart.dart b/lib/src/dart.dart
index 87a9950..c6e1418 100644
--- a/lib/src/dart.dart
+++ b/lib/src/dart.dart
@@ -78,7 +78,7 @@
/// the given [path]. It is expected that the client knows analysis roots
/// in advance. Pub does know, it is the packages it works with.
void createContextsForDirectory(String path) {
- _throwIfNotAbsolutePath(path);
+ path = p.normalize(p.absolute(path));
// We add all contexts below the given directory.
// So, children contexts must also have been added.
@@ -121,6 +121,7 @@
///
/// Throws [AnalyzerErrorGroup] is the file has parsing errors.
CompilationUnit parse(String path) {
+ path = p.normalize(p.absolute(path));
var parseResult = _getExistingSession(path).getParsedUnit(path);
if (parseResult.errors.isNotEmpty) {
throw AnalyzerErrorGroup(parseResult.errors);
@@ -147,8 +148,6 @@
}
AnalysisSession _getExistingSession(String path) {
- _throwIfNotAbsolutePath(path);
-
for (var context in _contexts.values) {
if (context.contextRoot.isAnalyzed(path)) {
return context.currentSession;
@@ -157,14 +156,6 @@
throw StateError('Unable to find the context to $path');
}
-
- /// The driver supports only absolute paths, this method is used to validate
- /// any input paths to prevent errors later.
- void _throwIfNotAbsolutePath(String path) {
- if (!p.isAbsolute(path)) {
- throw ArgumentError('Only absolute paths are supported: $path');
- }
- }
}
/// An error class that contains multiple [AnalysisError]s.
diff --git a/lib/src/validator/language_version.dart b/lib/src/validator/language_version.dart
index 4015807..f0fbdd3 100644
--- a/lib/src/validator/language_version.dart
+++ b/lib/src/validator/language_version.dart
@@ -42,8 +42,6 @@
for (final path in ['lib', 'bin']
.map((path) => entrypoint.root.listFiles(beneath: path))
.expand((files) => files)
- .map(p.normalize)
- .map(p.absolute)
.where((String file) => p.extension(file) == '.dart')) {
CompilationUnit unit;
try {
diff --git a/lib/src/validator/strict_dependencies.dart b/lib/src/validator/strict_dependencies.dart
index 6456d90..62da9f2 100644
--- a/lib/src/validator/strict_dependencies.dart
+++ b/lib/src/validator/strict_dependencies.dart
@@ -36,9 +36,7 @@
List<UriBasedDirective> directives;
var contents = readTextFile(file);
try {
- var normalizedPath = p.normalize(p.absolute(file));
- directives =
- analysisContextManager.parseImportsAndExports(normalizedPath);
+ directives = analysisContextManager.parseImportsAndExports(file);
} on AnalyzerErrorGroup catch (e, s) {
// Ignore files that do not parse.
log.fine(getErrorMessage(e));