OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 library io; | 8 library io; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 // Using Path.join here instead of File().fullPathSync() because the former | 365 // Using Path.join here instead of File().fullPathSync() because the former |
366 // does not require an actual file to exist at that path. | 366 // does not require an actual file to exist at that path. |
367 return new Path.fromNative(currentWorkingDir).join(new Path(path)) | 367 return new Path.fromNative(currentWorkingDir).join(new Path(path)) |
368 .toNativePath(); | 368 .toNativePath(); |
369 } | 369 } |
370 | 370 |
371 /// Resolves [path] relative to the location of pub.dart. | 371 /// Resolves [path] relative to the location of pub.dart. |
372 String relativeToPub(String path) { | 372 String relativeToPub(String path) { |
373 var scriptPath = new File(new Options().script).fullPathSync(); | 373 var scriptPath = new File(new Options().script).fullPathSync(); |
374 | 374 |
375 // Walk up until we hit the "utils" directory. This lets us figure out where | 375 // Walk up until we hit the "util(s)" directory. This lets us figure out where |
376 // we are if this function is called from pub.dart, or one of the tests, | 376 // we are if this function is called from pub.dart, or one of the tests, |
377 // which also live under "utils". | 377 // which also live under "utils", or from the SDK where pub is in "util". |
378 var utilsDir = new Path.fromNative(scriptPath).directoryPath; | 378 var utilDir = new Path.fromNative(scriptPath).directoryPath; |
379 while (utilsDir.filename != 'utils') { | 379 while ((utilDir.filename != 'utils') && (utilDir.filename != 'util')) { |
nweiz
2012/11/29 22:12:08
Unnecessary parentheses. Have faith in operator pr
Bob Nystrom
2012/12/04 21:38:24
Done. It is not my faith I question, but those of
| |
380 utilsDir = utilsDir.directoryPath; | 380 if (utilDir.filename == '') throw 'Could not find path to pub.'; |
381 utilDir = utilDir.directoryPath; | |
381 } | 382 } |
382 | 383 |
383 return utilsDir.append('pub').append(path).canonicalize().toNativePath(); | 384 return utilDir.append('pub').append(path).canonicalize().toNativePath(); |
384 } | 385 } |
385 | 386 |
386 /// A StringInputStream reading from stdin. | 387 /// A StringInputStream reading from stdin. |
387 final _stringStdin = new StringInputStream(stdin); | 388 final _stringStdin = new StringInputStream(stdin); |
388 | 389 |
389 /// Returns a single line read from a [StringInputStream]. By default, reads | 390 /// Returns a single line read from a [StringInputStream]. By default, reads |
390 /// from stdin. | 391 /// from stdin. |
391 /// | 392 /// |
392 /// A [StringInputStream] passed to this should have no callbacks registered. | 393 /// A [StringInputStream] passed to this should have no callbacks registered. |
393 Future<String> readLine([StringInputStream stream]) { | 394 Future<String> readLine([StringInputStream stream]) { |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 return new Directory(entry); | 924 return new Directory(entry); |
924 } | 925 } |
925 | 926 |
926 /** | 927 /** |
927 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 928 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
928 */ | 929 */ |
929 Uri _getUri(uri) { | 930 Uri _getUri(uri) { |
930 if (uri is Uri) return uri; | 931 if (uri is Uri) return uri; |
931 return new Uri.fromString(uri); | 932 return new Uri.fromString(uri); |
932 } | 933 } |
OLD | NEW |