Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 code_transformers.src.dart_sdk; | 5 library code_transformers.src.dart_sdk; |
| 6 | 6 |
| 7 import 'dart:convert' as convert; | 7 import 'dart:convert' as convert; |
| 8 import 'dart:io' show File, Link, Platform, Process; | 8 import 'dart:io' show Directory, File, Link, Platform, Process; |
|
jakemac
2015/02/05 23:22:22
Looks like only Directory is needed any more here.
pquitslund
2015/02/05 23:36:48
Check! Cleaned up imports. I left the Directory
| |
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/java_io.dart'; | 11 import 'package:analyzer/src/generated/java_io.dart'; |
| 12 import 'package:analyzer/src/generated/sdk.dart'; | 12 import 'package:analyzer/src/generated/sdk.dart'; |
| 13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:cli_util/cli_util.dart' as cli_util; | |
| 15 | 16 |
| 16 | 17 |
| 17 /// Attempts to provide the current Dart SDK directory. | 18 /// Attempts to provide the current Dart SDK directory. |
| 18 /// | 19 /// |
| 19 /// This will return null if the SDK cannot be found | 20 /// This will return null if the SDK cannot be found |
| 20 /// | 21 /// |
| 21 /// Note that this may not be correct when executing outside of `pub`. | 22 /// Note that this may not be correct when executing outside of `pub`. |
| 22 String get dartSdkDirectory { | 23 String get dartSdkDirectory { |
| 23 | 24 Directory sdkDir = cli_util.getSdkDir(); |
| 24 bool isSdkDir(String dirname) => | 25 return sdkDir != null ? sdkDir.path : null; |
| 25 new File(path.join(dirname, 'lib', '_internal', 'libraries.dart')) | |
| 26 .existsSync(); | |
| 27 | |
| 28 String executable = Platform.executable; | |
| 29 if (path.split(executable).length == 1) { | |
| 30 // TODO(blois): make this cross-platform. | |
| 31 // HACK: A single part, hope it's on the path. | |
| 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)); | |
| 40 if (isSdkDir(sdkDir)) return sdkDir; | |
| 41 } | |
| 42 | |
| 43 var dartDir = path.dirname(path.absolute(executable)); | |
| 44 // If there's a sub-dir named dart-sdk then we're most likely executing from | |
| 45 // a dart enlistment build directory. | |
| 46 if (isSdkDir(path.join(dartDir, 'dart-sdk'))) { | |
| 47 return path.join(dartDir, 'dart-sdk'); | |
| 48 } | |
| 49 // If we can find libraries.dart then it's the root of the SDK. | |
| 50 if (isSdkDir(dartDir)) return dartDir; | |
| 51 | |
| 52 var parts = path.split(dartDir); | |
| 53 // If the dart executable is within the sdk dir then get the root. | |
| 54 if (parts.contains('dart-sdk')) { | |
| 55 var dartSdkDir = path.joinAll(parts.take(parts.indexOf('dart-sdk') + 1)); | |
| 56 if (isSdkDir(dartSdkDir)) return dartSdkDir; | |
| 57 } | |
| 58 | |
| 59 return null; | |
| 60 } | 26 } |
| 61 | 27 |
| 62 /// Sources that are annotated with a source uri, so it is easy to resolve how | 28 /// Sources that are annotated with a source uri, so it is easy to resolve how |
| 63 /// to support `Resolver.getImportUri`. | 29 /// to support `Resolver.getImportUri`. |
| 64 abstract class UriAnnotatedSource extends Source { | 30 abstract class UriAnnotatedSource extends Source { |
| 65 Uri get uri; | 31 Uri get uri; |
| 66 } | 32 } |
| 67 | 33 |
| 68 /// Dart SDK which wraps all Dart sources as [UriAnnotatedSource] to ensure they | 34 /// Dart SDK which wraps all Dart sources as [UriAnnotatedSource] to ensure they |
| 69 /// are tracked with Uris. | 35 /// are tracked with Uris. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 UriKind get uriKind => UriKind.DART_URI; | 195 UriKind get uriKind => UriKind.DART_URI; |
| 230 | 196 |
| 231 bool get isInSystemLibrary => true; | 197 bool get isInSystemLibrary => true; |
| 232 | 198 |
| 233 Source resolveRelative(Uri relativeUri) => | 199 Source resolveRelative(Uri relativeUri) => |
| 234 throw new UnsupportedError('not expecting relative urls in dart: mocks'); | 200 throw new UnsupportedError('not expecting relative urls in dart: mocks'); |
| 235 | 201 |
| 236 Uri resolveRelativeUri(Uri relativeUri) => | 202 Uri resolveRelativeUri(Uri relativeUri) => |
| 237 throw new UnsupportedError('not expecting relative urls in dart: mocks'); | 203 throw new UnsupportedError('not expecting relative urls in dart: mocks'); |
| 238 } | 204 } |
| OLD | NEW |