OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library io; | 6 library io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 return path.normalize(path.join(utilDir, 'pub', target)); | 279 return path.normalize(path.join(utilDir, 'pub', target)); |
280 } | 280 } |
281 | 281 |
282 // TODO(nweiz): add a ByteSink wrapper to make writing strings to stdout/stderr | 282 // TODO(nweiz): add a ByteSink wrapper to make writing strings to stdout/stderr |
283 // nicer. | 283 // nicer. |
284 | 284 |
285 /// A sink that writes to standard output. Errors piped to this stream will be | 285 /// A sink that writes to standard output. Errors piped to this stream will be |
286 /// surfaced to the top-level error handler. | 286 /// surfaced to the top-level error handler. |
287 final EventSink<List<int>> stdoutSink = stdout; | 287 // TODO: Unrequired wrapper, stdout is now an EventSink<List<int>>. |
| 288 final EventSink<List<int>> stdoutSink = _wrapStdio(stdout, "stdout"); |
288 | 289 |
289 /// A sink that writes to standard error. Errors piped to this stream will be | 290 /// A sink that writes to standard error. Errors piped to this stream will be |
290 /// surfaced to the top-level error handler. | 291 /// surfaced to the top-level error handler. |
291 final EventSink<List<int>> stderrSink = stderr; | 292 // TODO: Unrequired wrapper, stdout is now an EventSink<List<int>>. |
| 293 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); |
292 | 294 |
293 /// Wrap the standard output or error [stream] in a [EventSink]. Any errors are | 295 /// Wrap the standard output or error [stream] in a [EventSink]. Any errors are |
294 /// logged, and then the program is terminated. [name] is used for debugging. | 296 /// logged, and then the program is terminated. [name] is used for debugging. |
295 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { | 297 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { |
296 var pair = consumerToSink(sink); | 298 var pair = consumerToSink(sink); |
297 pair.last.catchError((e) { | 299 pair.last.catchError((e) { |
298 // This log may or may not work, depending on how the stream failed. Not | 300 // This log may or may not work, depending on how the stream failed. Not |
299 // much we can do about that. | 301 // much we can do about that. |
300 log.error("Error writing to $name: $e"); | 302 log.error("Error writing to $name: $e"); |
301 exit(exit_codes.IO); | 303 exit(exit_codes.IO); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
730 | 732 |
731 bool get success => exitCode == 0; | 733 bool get success => exitCode == 0; |
732 } | 734 } |
733 | 735 |
734 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
735 Uri _getUri(uri) { | 737 Uri _getUri(uri) { |
736 if (uri is Uri) return uri; | 738 if (uri is Uri) return uri; |
737 return Uri.parse(uri); | 739 return Uri.parse(uri); |
738 } | 740 } |
OLD | NEW |