OLD | NEW |
---|---|
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 test.util.io; | 5 library test.util.io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
11 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
12 import 'package:pub_semver/pub_semver.dart'; | 12 import 'package:pub_semver/pub_semver.dart'; |
13 | 13 |
14 import '../backend/operating_system.dart'; | 14 import '../backend/operating_system.dart'; |
15 import '../runner/application_exception.dart'; | 15 import '../runner/application_exception.dart'; |
16 | 16 |
17 /// The ASCII code for a newline character. | 17 /// The ASCII code for a newline character. |
18 const _newline = 0xA; | 18 const _newline = 0xA; |
19 | 19 |
20 /// The ASCII code for a carriage return character. | 20 /// The ASCII code for a carriage return character. |
21 const _carriageReturn = 0xD; | 21 const _carriageReturn = 0xD; |
22 | 22 |
23 String _sdkDir; | |
nweiz
2015/05/15 20:04:50
For lazy top-level variables, I like to take advan
kevmoo
2015/05/21 17:46:22
Done.
| |
24 | |
23 /// The root directory of the Dart SDK. | 25 /// The root directory of the Dart SDK. |
24 final String sdkDir = | 26 String get sdkDir { |
nweiz
2015/05/15 20:04:50
Add a TODO to get rid of this variable when Platfo
kevmoo
2015/05/21 17:46:22
Not sure if that's going to happen, given the curr
nweiz
2015/05/21 19:06:01
A TODO to simplify it when Platform.executable is
| |
25 p.dirname(p.dirname(Platform.executable)); | 27 if (_sdkDir == null) { |
28 // This may fail on Mac if `dart` is run directly from the PATH environment | |
nweiz
2015/05/15 20:04:50
What does "run directly from the PATH environment"
kevmoo
2015/05/21 17:46:22
Acknowledged.
| |
29 // See https://code.google.com/p/dart/issues/detail?id=21791 | |
nweiz
2015/05/15 20:04:50
What does this issue have to do with it?
kevmoo
2015/05/21 17:46:22
Acknowledged.
| |
30 var path = new File(Platform.executable).resolveSymbolicLinksSync(); | |
nweiz
2015/05/15 20:04:50
What if the bin directory is symlinked rather than
kevmoo
2015/05/21 17:46:22
This still works. resolveSymbolicLinks does the wo
| |
31 _sdkDir = p.dirname(p.dirname(path)); | |
32 } | |
33 return _sdkDir; | |
34 } | |
26 | 35 |
27 /// The version of the Dart SDK currently in use. | 36 /// The version of the Dart SDK currently in use. |
28 final Version _sdkVersion = new Version.parse( | 37 final Version _sdkVersion = new Version.parse( |
29 new File(p.join(sdkDir, 'version')) | 38 new File(p.join(sdkDir, 'version')) |
30 .readAsStringSync().trim()); | 39 .readAsStringSync().trim()); |
31 | 40 |
32 /// Returns the current operating system. | 41 /// Returns the current operating system. |
33 final OperatingSystem currentOS = (() { | 42 final OperatingSystem currentOS = (() { |
34 var name = Platform.operatingSystem; | 43 var name = Platform.operatingSystem; |
35 var os = OperatingSystem.findByIoName(name); | 44 var os = OperatingSystem.findByIoName(name); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 /// returned. | 171 /// returned. |
163 String libraryPath(Symbol libraryName, {String packageRoot}) { | 172 String libraryPath(Symbol libraryName, {String packageRoot}) { |
164 var lib = currentMirrorSystem().findLibrary(libraryName); | 173 var lib = currentMirrorSystem().findLibrary(libraryName); |
165 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); | 174 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); |
166 | 175 |
167 // TODO(nweiz): is there a way to avoid assuming this is being run next to a | 176 // TODO(nweiz): is there a way to avoid assuming this is being run next to a |
168 // packages directory?. | 177 // packages directory?. |
169 if (packageRoot == null) packageRoot = p.absolute('packages'); | 178 if (packageRoot == null) packageRoot = p.absolute('packages'); |
170 return p.join(packageRoot, p.fromUri(lib.uri.path)); | 179 return p.join(packageRoot, p.fromUri(lib.uri.path)); |
171 } | 180 } |
OLD | NEW |