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 = _wrapStdio(stdout, "stdout"); | 287 final EventSink<List<int>> stdoutSink = stdout; |
288 | 288 |
289 /// A sink that writes to standard error. Errors piped to this stream will be | 289 /// A sink that writes to standard error. Errors piped to this stream will be |
290 /// surfaced to the top-level error handler. | 290 /// surfaced to the top-level error handler. |
291 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); | 291 final EventSink<List<int>> stderrSink = stderr; |
292 | 292 |
293 /// Wrap the standard output or error [stream] in a [EventSink]. Any errors are | 293 /// 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. | 294 /// logged, and then the program is terminated. [name] is used for debugging. |
295 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { | 295 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { |
nweiz
2013/04/15 19:37:23
This is no longer used; you can remove it.
nweiz
2013/04/15 19:59:52
I hadn't seen the second CL when I wrote this. I'l
| |
296 var pair = consumerToSink(sink); | 296 var pair = consumerToSink(sink); |
297 pair.last.catchError((e) { | 297 pair.last.catchError((e) { |
298 // This log may or may not work, depending on how the stream failed. Not | 298 // This log may or may not work, depending on how the stream failed. Not |
299 // much we can do about that. | 299 // much we can do about that. |
300 log.error("Error writing to $name: $e"); | 300 log.error("Error writing to $name: $e"); |
301 exit(exit_codes.IO); | 301 exit(exit_codes.IO); |
302 }); | 302 }); |
303 return pair.first; | 303 return pair.first; |
304 } | 304 } |
305 | 305 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 729 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
730 | 730 |
731 bool get success => exitCode == 0; | 731 bool get success => exitCode == 0; |
732 } | 732 } |
733 | 733 |
734 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 734 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
735 Uri _getUri(uri) { | 735 Uri _getUri(uri) { |
736 if (uri is Uri) return uri; | 736 if (uri is Uri) return uri; |
737 return Uri.parse(uri); | 737 return Uri.parse(uri); |
738 } | 738 } |
OLD | NEW |