Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit 8dbe912

Browse files
committed
Fix code_transformers to consider dart symlinks (typical in brew installations)
Review URL: https://codereview.chromium.org//795433002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/code_transformers@42275 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 7461ccb commit 8dbe912

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.3+2
2+
3+
* Added logic to discover the location of the dart SDK when the dart binary is a
4+
symlink.
5+
16
## 0.2.3
27

38
* Added support for logging stable error messages from transformers.

lib/src/dart_sdk.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
library code_transformers.src.dart_sdk;
66

77
import 'dart:convert' as convert;
8-
import 'dart:io' show File, Platform, Process;
8+
import 'dart:io' show File, Link, Platform, Process;
99
import 'package:path/path.dart' as path;
1010
import 'package:analyzer/src/generated/engine.dart';
1111
import 'package:analyzer/src/generated/java_io.dart';
@@ -23,18 +23,24 @@ String get dartSdkDirectory {
2323

2424
bool isSdkDir(String dirname) =>
2525
new File(path.join(dirname, 'lib', '_internal', 'libraries.dart'))
26-
.existsSync();
26+
.existsSync();
2727

28-
if (path.split(Platform.executable).length == 1) {
28+
String executable = Platform.executable;
29+
if (path.split(executable).length == 1) {
2930
// TODO(blois): make this cross-platform.
3031
// HACK: A single part, hope it's on the path.
31-
var result = Process.runSync('which', ['dart'],
32-
stdoutEncoding: convert.UTF8);
33-
34-
var sdkDir = path.dirname(path.dirname(result.stdout));
32+
executable = Process.runSync('which', ['dart'],
33+
stdoutEncoding: convert.UTF8).stdout.trim();
34+
// In case Dart is symlinked (e.g. homebrew on Mac) follow symbolic links.
35+
var link = new Link(executable);
36+
if (link.existsSync()) {
37+
executable = link.resolveSymbolicLinksSync();
38+
}
39+
var sdkDir = path.dirname(path.dirname(executable));
3540
if (isSdkDir(sdkDir)) return sdkDir;
3641
}
37-
var dartDir = path.dirname(path.absolute(Platform.executable));
42+
43+
var dartDir = path.dirname(path.absolute(executable));
3844
// If there's a sub-dir named dart-sdk then we're most likely executing from
3945
// a dart enlistment build directory.
4046
if (isSdkDir(path.join(dartDir, 'dart-sdk'))) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: code_transformers
2-
version: 0.2.3+1
2+
version: 0.2.3+2
33
author: "Dart Team <[email protected]>"
44
description: Collection of utilities related to creating barback transformers.
55
homepage: http://www.dartlang.org

0 commit comments

Comments
 (0)