Support an executable in a symlinked directory.

R=pquitslund@google.com

Review URL: https://chromiumcodereview.appspot.com//1132913003
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7271432..85af3d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 0.0.1+2
+
+- Support an executable in a symlinked directory.
+
 ## 0.0.1+1
 
 - Fix for when the dart executable can't be found by `which`.
diff --git a/lib/cli_util.dart b/lib/cli_util.dart
index 683bef7..aff2c67 100644
--- a/lib/cli_util.dart
+++ b/lib/cli_util.dart
@@ -6,6 +6,7 @@
 
 import 'dart:io';
 
+import 'package:path/path.dart' as p;
 import 'package:which/which.dart';
 
 /// Return the path to the current Dart SDK. This will return `null` if we are
@@ -45,6 +46,12 @@
       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;
diff --git a/pubspec.yaml b/pubspec.yaml
index 80f21e1..c27866d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,11 +1,12 @@
 name: cli_util
-version: 0.0.1+1
+version: 0.0.1+2
 author: Dart Team <misc@dartlang.org>
 description: A library to help in building Dart command-line apps.
 homepage: https://github.com/dart-lang/cli_util
 environment:
   sdk: '>=1.0.0 <2.0.0'
 dependencies:
+  path: '>=1.0.0 <2.0.0'
   which: '>=0.1.2 <0.2.0'
 dev_dependencies:
   unittest: '>=0.11.0 <0.12.0'