| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library code_transformers.src.dart_sdk; |
| 6 |
| 7 import 'dart:convert' as convert; |
| 8 import 'dart:io' show Directory, File, Platform, Process; |
| 9 import 'package:path/path.dart' as path; |
| 10 |
| 11 |
| 12 /// Attempts to provide the current Dart SDK directory. |
| 13 /// |
| 14 /// Note that this may not be correct when executing outside of `pub`. |
| 15 String get dartSdkDirectory { |
| 16 if (path.split(Platform.executable).length == 1) { |
| 17 // TODO(blois): make this cross-platform. |
| 18 // HACK: A single part, hope it's on the path. |
| 19 var result = Process.runSync('which', ['dart'], |
| 20 stdoutEncoding: convert.UTF8); |
| 21 return path.dirname(path.dirname(result.stdout)); |
| 22 } |
| 23 var sdkDir = path.dirname(path.absolute(Platform.executable)); |
| 24 // If there's a sub-dir named dart-sdk then we're most likely executing from |
| 25 // a dart enlistment build directory. |
| 26 if (new Directory(path.join(sdkDir, 'dart-sdk')).existsSync()) { |
| 27 return path.join(sdkDir, 'dart-sdk'); |
| 28 } |
| 29 // If we can find libraries.dart then it's the root of the SDK. |
| 30 if (new File(path.join(sdkDir, 'lib', '_internal', 'libraries.dart')) |
| 31 .existsSync()) { |
| 32 return sdkDir; |
| 33 } |
| 34 |
| 35 var parts = path.split(sdkDir); |
| 36 // If the dart executable is within the sdk dir then get the root. |
| 37 if (parts.contains('dart-sdk')) { |
| 38 return path.joinAll(parts.take(parts.indexOf('dart-sdk') + 1)); |
| 39 } |
| 40 |
| 41 return sdkDir; |
| 42 } |
| OLD | NEW |