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

Side by Side Diff: lib/cli_util.dart

Issue 1132913003: Support an executable in a symlinked directory. (Closed) Base URL: git@github.com:dart-lang/cli_util@master
Patch Set: Remove a debugging print. Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library cli_util; 5 library cli_util;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p;
9 import 'package:which/which.dart'; 10 import 'package:which/which.dart';
10 11
11 /// Return the path to the current Dart SDK. This will return `null` if we are 12 /// Return the path to the current Dart SDK. This will return `null` if we are
12 /// unable to locate the Dart SDK. 13 /// unable to locate the Dart SDK.
13 Directory getSdkDir([List<String> cliArgs]) { 14 Directory getSdkDir([List<String> cliArgs]) {
14 // Look for --dart-sdk on the command line. 15 // Look for --dart-sdk on the command line.
15 if (cliArgs != null) { 16 if (cliArgs != null) {
16 int index = cliArgs.indexOf('--dart-sdk'); 17 int index = cliArgs.indexOf('--dart-sdk');
17 18
18 if (index != -1 && (index + 1 < cliArgs.length)) { 19 if (index != -1 && (index + 1 < cliArgs.length)) {
(...skipping 19 matching lines...) Expand all
38 // Try and locate the VM using 'which'. 39 // Try and locate the VM using 'which'.
39 String executable = whichSync('dart', orElse: () => null); 40 String executable = whichSync('dart', orElse: () => null);
40 41
41 if (executable != null) { 42 if (executable != null) {
42 // In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links. 43 // In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links.
43 Link link = new Link(executable); 44 Link link = new Link(executable);
44 if (link.existsSync()) { 45 if (link.existsSync()) {
45 executable = link.resolveSymbolicLinksSync(); 46 executable = link.resolveSymbolicLinksSync();
46 } 47 }
47 48
49 Link parentLink = new Link(p.dirname(executable));
50 if (parentLink.existsSync()) {
51 executable = p.join(
52 parentLink.resolveSymbolicLinksSync(), p.basename(executable));
53 }
54
48 File dartVm = new File(executable); 55 File dartVm = new File(executable);
49 Directory dir = dartVm.parent.parent; 56 Directory dir = dartVm.parent.parent;
50 if (_isSdkDir(dir)) return dir; 57 if (_isSdkDir(dir)) return dir;
51 } 58 }
52 59
53 return null; 60 return null;
54 } 61 }
55 62
56 bool _isSdkDir(Directory dir) => _joinFile(dir, ['version']).existsSync(); 63 bool _isSdkDir(Directory dir) => _joinFile(dir, ['version']).existsSync();
57 64
58 File _joinFile(Directory dir, List<String> files) { 65 File _joinFile(Directory dir, List<String> files) {
59 String pathFragment = files.join(Platform.pathSeparator); 66 String pathFragment = files.join(Platform.pathSeparator);
60 return new File("${dir.path}${Platform.pathSeparator}${pathFragment}"); 67 return new File("${dir.path}${Platform.pathSeparator}${pathFragment}");
61 } 68 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698