Chromium Code Reviews| 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 | 13 |
| 13 import '../backend/operating_system.dart'; | 14 import '../backend/operating_system.dart'; |
| 14 import '../runner/load_exception.dart'; | 15 import '../runner/load_exception.dart'; |
| 15 | 16 |
| 16 /// The root directory of the Dart SDK. | 17 /// The root directory of the Dart SDK. |
| 17 final String sdkDir = | 18 final String sdkDir = |
| 18 p.dirname(p.dirname(Platform.executable)); | 19 p.dirname(p.dirname(Platform.executable)); |
| 19 | 20 |
| 21 /// The version of the Dart SDK currently in use. | |
|
kevmoo
2015/04/03 22:55:53
Annoying nit: if this check fails, an exception wi
| |
| 22 final Version _sdkVersion = new Version.parse( | |
| 23 new File(p.join(p.dirname(p.dirname(Platform.executable)), 'version')) | |
| 24 .readAsStringSync().trim()); | |
| 25 | |
| 20 /// Returns the current operating system. | 26 /// Returns the current operating system. |
| 21 final OperatingSystem currentOS = (() { | 27 final OperatingSystem currentOS = (() { |
| 22 var name = Platform.operatingSystem; | 28 var name = Platform.operatingSystem; |
| 23 var os = OperatingSystem.findByIoName(name); | 29 var os = OperatingSystem.findByIoName(name); |
| 24 if (os != null) return os; | 30 if (os != null) return os; |
| 25 | 31 |
| 26 throw new UnsupportedError('Unsupported operating system "$name".'); | 32 throw new UnsupportedError('Unsupported operating system "$name".'); |
| 27 })(); | 33 })(); |
| 28 | 34 |
| 29 /// The path to the `lib` directory of the `test` package. | 35 /// The path to the `lib` directory of the `test` package. |
| 30 String libDir({String packageRoot}) { | 36 String libDir({String packageRoot}) { |
| 31 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot); | 37 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot); |
| 32 return p.dirname(p.dirname(p.dirname(pathToIo))); | 38 return p.dirname(p.dirname(p.dirname(pathToIo))); |
| 33 } | 39 } |
| 34 | 40 |
| 35 /// Returns whether the current Dart version supports [Isolate.kill]. | 41 /// Returns whether the current Dart version supports [Isolate.kill]. |
| 36 final bool supportsIsolateKill = _supportsIsolateKill; | 42 final bool supportsIsolateKill = _supportsIsolateKill; |
| 37 bool get _supportsIsolateKill { | 43 bool get _supportsIsolateKill { |
| 38 // This isn't 100% accurate, since early 1.9 dev releases didn't support | 44 // This isn't 100% accurate, since early 1.9 dev releases didn't support |
| 39 // Isolate.kill(), but it's very unlikely anyone will be using them. | 45 // Isolate.kill(), but it's very unlikely anyone will be using them. |
| 40 // TODO(nweiz): remove this when we no longer support older Dart versions. | 46 // TODO(nweiz): remove this when we no longer support older Dart versions. |
| 41 var path = p.join(p.dirname(p.dirname(Platform.executable)), 'version'); | 47 return new VersionConstraint.parse('>=1.9.0-dev <2.0.0').allows(_sdkVersion); |
| 42 return !new File(path).readAsStringSync().startsWith('1.8'); | 48 } |
| 49 | |
| 50 /// Returns whether the current Dart version has a fix for issue 23084. | |
| 51 final bool supportsPubServe = _supportsPubServe; | |
| 52 bool get _supportsPubServe { | |
| 53 // This isn't 100% accurate, since issue 23084 wasn't fixed in early 1.10 dev | |
| 54 // releases, but it's unlikely anyone will be using them. | |
| 55 // TODO(nweiz): remove this when we no longer support older Dart versions. | |
| 56 return new VersionConstraint.parse('>=1.9.2 <2.0.0').allows(_sdkVersion); | |
| 43 } | 57 } |
| 44 | 58 |
| 45 // TODO(nweiz): Make this check [stdioType] once that works within "pub run". | 59 // TODO(nweiz): Make this check [stdioType] once that works within "pub run". |
| 46 /// Whether "special" strings such as Unicode characters or color escapes are | 60 /// Whether "special" strings such as Unicode characters or color escapes are |
| 47 /// safe to use. | 61 /// safe to use. |
| 48 /// | 62 /// |
| 49 /// On Windows or when not printing to a terminal, only printable ASCII | 63 /// On Windows or when not printing to a terminal, only printable ASCII |
| 50 /// characters should be used. | 64 /// characters should be used. |
| 51 bool get canUseSpecialChars => | 65 bool get canUseSpecialChars => |
| 52 Platform.operatingSystem != 'windows' && | 66 Platform.operatingSystem != 'windows' && |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 /// returned. | 121 /// returned. |
| 108 String libraryPath(Symbol libraryName, {String packageRoot}) { | 122 String libraryPath(Symbol libraryName, {String packageRoot}) { |
| 109 var lib = currentMirrorSystem().findLibrary(libraryName); | 123 var lib = currentMirrorSystem().findLibrary(libraryName); |
| 110 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); | 124 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); |
| 111 | 125 |
| 112 // TODO(nweiz): is there a way to avoid assuming this is being run next to a | 126 // TODO(nweiz): is there a way to avoid assuming this is being run next to a |
| 113 // packages directory?. | 127 // packages directory?. |
| 114 if (packageRoot == null) packageRoot = p.absolute('packages'); | 128 if (packageRoot == null) packageRoot = p.absolute('packages'); |
| 115 return p.join(packageRoot, p.fromUri(lib.uri.path)); | 129 return p.join(packageRoot, p.fromUri(lib.uri.path)); |
| 116 } | 130 } |
| OLD | NEW |