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'; |
11 import 'dart:json'; | 11 import 'dart:json'; |
12 import 'dart:uri'; | 12 import 'dart:uri'; |
13 | 13 |
14 import '../../pkg/pathos/lib/path.dart' as path; | 14 import 'package:pathos/path.dart' as path; |
15 import '../../pkg/http/lib/http.dart' show ByteStream; | 15 import 'package:http/http.dart' show ByteStream; |
16 import 'error_group.dart'; | 16 import 'error_group.dart'; |
17 import 'exit_codes.dart' as exit_codes; | 17 import 'exit_codes.dart' as exit_codes; |
18 import 'log.dart' as log; | 18 import 'log.dart' as log; |
19 import 'utils.dart'; | 19 import 'utils.dart'; |
20 | 20 |
21 export '../../pkg/http/lib/http.dart' show ByteStream; | 21 export 'package:http/http.dart' show ByteStream; |
22 | 22 |
23 /// Returns whether or not [entry] is nested somewhere within [dir]. This just | 23 /// Returns whether or not [entry] is nested somewhere within [dir]. This just |
24 /// performs a path comparison; it doesn't look at the actual filesystem. | 24 /// performs a path comparison; it doesn't look at the actual filesystem. |
25 bool isBeneath(String entry, String dir) { | 25 bool isBeneath(String entry, String dir) { |
26 var relative = path.relative(entry, from: dir); | 26 var relative = path.relative(entry, from: dir); |
27 return !path.isAbsolute(relative) && path.split(relative)[0] != '..'; | 27 return !path.isAbsolute(relative) && path.split(relative)[0] != '..'; |
28 } | 28 } |
29 | 29 |
30 /// Determines if a file or directory exists at [path]. | 30 /// Determines if a file or directory exists at [path]. |
31 bool entryExists(String path) => dirExists(path) || fileExists(path); | 31 bool entryExists(String path) => dirExists(path) || fileExists(path); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 var utilDir = path.dirname(scriptPath); | 303 var utilDir = path.dirname(scriptPath); |
304 while (path.basename(utilDir) != 'utils' && | 304 while (path.basename(utilDir) != 'utils' && |
305 path.basename(utilDir) != 'util') { | 305 path.basename(utilDir) != 'util') { |
306 if (path.basename(utilDir) == '') throw 'Could not find path to pub.'; | 306 if (path.basename(utilDir) == '') throw 'Could not find path to pub.'; |
307 utilDir = path.dirname(utilDir); | 307 utilDir = path.dirname(utilDir); |
308 } | 308 } |
309 | 309 |
310 return path.normalize(path.join(utilDir, 'pub', target)); | 310 return path.normalize(path.join(utilDir, 'pub', target)); |
311 } | 311 } |
312 | 312 |
313 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart | |
314 /// source repository. | |
315 bool get runningFromSdk => path.dirname(relativeToPub('..')) == 'util'; | |
Bob Nystrom
2013/03/26 01:55:44
Does pub itself need these or are they just for te
nweiz
2013/03/26 02:09:53
Done.
| |
316 | |
317 // TODO(nweiz): use the built-in mechanism for accessing this once it exists | |
318 // (issue 9119). | |
319 /// The path to the `packages` directory from which pub loads its dependencies. | |
320 String get packageRoot { | |
321 if (runningFromSdk) { | |
322 return path.absolute(relativeToPub(path.join('..', '..', 'packages'))); | |
323 } else { | |
324 return path.absolute(path.join( | |
325 path.dirname(new Options().executable), '..', '..', 'packages')); | |
326 } | |
327 } | |
328 | |
313 // TODO(nweiz): add a ByteSink wrapper to make writing strings to stdout/stderr | 329 // TODO(nweiz): add a ByteSink wrapper to make writing strings to stdout/stderr |
314 // nicer. | 330 // nicer. |
315 | 331 |
316 /// A sink that writes to standard output. Errors piped to this stream will be | 332 /// A sink that writes to standard output. Errors piped to this stream will be |
317 /// surfaced to the top-level error handler. | 333 /// surfaced to the top-level error handler. |
318 final EventSink<List<int>> stdoutSink = _wrapStdio(stdout, "stdout"); | 334 final EventSink<List<int>> stdoutSink = _wrapStdio(stdout, "stdout"); |
319 | 335 |
320 /// A sink that writes to standard error. Errors piped to this stream will be | 336 /// A sink that writes to standard error. Errors piped to this stream will be |
321 /// surfaced to the top-level error handler. | 337 /// surfaced to the top-level error handler. |
322 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); | 338 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 781 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
766 | 782 |
767 bool get success => exitCode == 0; | 783 bool get success => exitCode == 0; |
768 } | 784 } |
769 | 785 |
770 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 786 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
771 Uri _getUri(uri) { | 787 Uri _getUri(uri) { |
772 if (uri is Uri) return uri; | 788 if (uri is Uri) return uri; |
773 return Uri.parse(uri); | 789 return Uri.parse(uri); |
774 } | 790 } |
OLD | NEW |