Improve how dartfix finds the analysis server pkg root
Change-Id: Iead97b14a2eede8628ea286fedcccbafb4f3c2b7
Reviewed-on: https://dart-review.googlesource.com/c/80943
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
diff --git a/pkg/analyzer_cli/lib/src/fix/server.dart b/pkg/analyzer_cli/lib/src/fix/server.dart
index 1e8e1b4..525610e 100644
--- a/pkg/analyzer_cli/lib/src/fix/server.dart
+++ b/pkg/analyzer_cli/lib/src/fix/server.dart
@@ -97,7 +97,9 @@
/**
* Find the root directory of the analysis_server package by proceeding
- * upward to the 'test' dir, and then going up one more directory.
+ * upward until finding the Dart SDK repository root then returning
+ * the analysis_server package root within the repository.
+ * Return `null` if it cannot be found.
*/
static String findRoot([String pathname]) {
pathname ??= Platform.script.toFilePath(windows: Platform.isWindows);
@@ -106,12 +108,10 @@
if (parent.length >= pathname.length) {
return null;
}
- String name = basename(pathname);
- if (['benchmark', 'test'].contains(name)) {
- return parent;
- }
- if (name == 'pkg') {
- return join(pathname, 'analysis_server');
+ String root = normalize(join(parent, 'pkg', 'analysis_server'));
+ String server = join(root, 'bin', 'server.dart');
+ if (new File(server).existsSync()) {
+ return root;
}
pathname = parent;
}