Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: packages/cli_util/lib/cli_util.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/cli_util/lib/cli_logging.dart ('k') | packages/cli_util/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/cli_util/lib/cli_util.dart
diff --git a/packages/cli_util/lib/cli_util.dart b/packages/cli_util/lib/cli_util.dart
index aff2c6799978a1445c485fdc512e0ae9fdfe69e4..d58be7a72fdc9033d124834ee9579c5b7cc24394 100644
--- a/packages/cli_util/lib/cli_util.dart
+++ b/packages/cli_util/lib/cli_util.dart
@@ -2,15 +2,24 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+/// Utilities to return the Dart SDK location.
library cli_util;
import 'dart:io';
-import 'package:path/path.dart' as p;
-import 'package:which/which.dart';
+import 'package:path/path.dart' as path;
-/// Return the path to the current Dart SDK. This will return `null` if we are
-/// unable to locate the Dart SDK.
+import 'src/utils.dart';
+
+/// Return the path to the current Dart SDK.
+///
+/// This first checks for an explicit SDK listed on the command-line
+/// (`--dart-sdk`). It then looks in any `DART_SDK` environment variable. Next,
+/// it looks relative to the Dart VM executable. Last, it uses the
+/// [Platform.resolvedExecutable] API.
+///
+/// Callers should generally prefer using the [getSdkPath] function.
+@Deprecated('Clients should generally prefer getSdkPath()')
Directory getSdkDir([List<String> cliArgs]) {
// Look for --dart-sdk on the command line.
if (cliArgs != null) {
@@ -33,36 +42,19 @@ Directory getSdkDir([List<String> cliArgs]) {
}
// Look relative to the dart executable.
- Directory sdkDirectory = new File(Platform.executable).parent.parent;
- if (_isSdkDir(sdkDirectory)) return sdkDirectory;
-
- // Try and locate the VM using 'which'.
- String executable = whichSync('dart', orElse: () => null);
-
- if (executable != null) {
- // In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links.
- Link link = new Link(executable);
- if (link.existsSync()) {
- executable = link.resolveSymbolicLinksSync();
- }
-
- Link parentLink = new Link(p.dirname(executable));
- if (parentLink.existsSync()) {
- executable = p.join(
- parentLink.resolveSymbolicLinksSync(), p.basename(executable));
- }
-
- File dartVm = new File(executable);
- Directory dir = dartVm.parent.parent;
- if (_isSdkDir(dir)) return dir;
- }
-
- return null;
+ File platformExecutable = new File(Platform.executable);
+ Directory sdkDirectory = platformExecutable.parent.parent;
+ if (isSdkDir(sdkDirectory)) return sdkDirectory;
+
+ // Handle the case where Platform.executable is a sibling of the SDK directory
+ // (this happens during internal testing).
+ sdkDirectory =
+ new Directory(path.join(platformExecutable.parent.path, 'dart-sdk'));
+ if (isSdkDir(sdkDirectory)) return sdkDirectory;
+
+ // Use `Platform.resolvedExecutable`.
+ return new Directory(getSdkPath());
}
-bool _isSdkDir(Directory dir) => _joinFile(dir, ['version']).existsSync();
-
-File _joinFile(Directory dir, List<String> files) {
- String pathFragment = files.join(Platform.pathSeparator);
- return new File("${dir.path}${Platform.pathSeparator}${pathFragment}");
-}
+/// Return the path to the current Dart SDK.
+String getSdkPath() => path.dirname(path.dirname(Platform.resolvedExecutable));
« no previous file with comments | « packages/cli_util/lib/cli_logging.dart ('k') | packages/cli_util/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698