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 pub.io; | 6 library pub.io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:convert'; | 10 import 'dart:convert'; |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 r"/third_party/pkg/pub/(" | 508 r"/third_party/pkg/pub/(" |
509 r"bin/pub\.dart" | 509 r"bin/pub\.dart" |
510 r"|" | 510 r"|" |
511 r"\.pub/pub\.test\.snapshot" | 511 r"\.pub/pub\.test\.snapshot" |
512 r"|" | 512 r"|" |
513 r"test/.*_test\.dart" | 513 r"test/.*_test\.dart" |
514 r")$"); | 514 r")$"); |
515 | 515 |
516 /// Whether pub is running from source in the Dart repo. | 516 /// Whether pub is running from source in the Dart repo. |
517 /// | 517 /// |
518 /// This can happen when building Observatory, for example. | 518 /// This can happen when running tests against the repo, as well as when |
519 final bool runningFromDartRepo = | 519 /// building Observatory. |
520 Platform.script.path.contains(_dartRepoRegExp); | 520 final bool runningFromDartRepo = (() { |
521 if (runningAsTestRunner) { | |
522 // When running from the test runner, we can't find our location via | |
523 // Platform.script since the runner munges that. However, it guarantees that | |
524 // the working directory is | |
Bob Nystrom
2015/06/30 18:33:11
"is ..."
nweiz
2015/06/30 19:47:29
Done.
| |
525 return path.current.contains( | |
526 new RegExp(r"[/\\]third_party[/\\]pkg[/\\]pub$")); | |
527 } else { | |
528 return Platform.script.path.contains(_dartRepoRegExp); | |
529 } | |
530 })(); | |
521 | 531 |
522 /// Resolves [target] relative to the path to pub's `asset` directory. | 532 /// Resolves [target] relative to the path to pub's `asset` directory. |
523 String assetPath(String target) => runningFromSdk | 533 String assetPath(String target) => runningFromSdk |
524 ? sdkAssetPath(target) | 534 ? sdkAssetPath(target) |
525 : path.join(pubRoot, 'lib', 'src', 'asset', target); | 535 : path.join(pubRoot, 'lib', 'src', 'asset', target); |
526 | 536 |
527 /// Resolves [target] relative to the Dart SDK's `asset` directory. | 537 /// Resolves [target] relative to the Dart SDK's `asset` directory. |
528 /// | 538 /// |
529 /// Throws a [StateError] if called from within the Dart repo. | 539 /// Throws a [StateError] if called from within the Dart repo. |
530 String sdkAssetPath(String target) { | 540 String sdkAssetPath(String target) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 | 572 |
563 /// The path to the root of the Dart repo. | 573 /// The path to the root of the Dart repo. |
564 /// | 574 /// |
565 /// This throws a [StateError] if it's called when not running pub from source | 575 /// This throws a [StateError] if it's called when not running pub from source |
566 /// in the Dart repo. | 576 /// in the Dart repo. |
567 final String dartRepoRoot = (() { | 577 final String dartRepoRoot = (() { |
568 if (!runningFromDartRepo) { | 578 if (!runningFromDartRepo) { |
569 throw new StateError("Not running from source in the Dart repo."); | 579 throw new StateError("Not running from source in the Dart repo."); |
570 } | 580 } |
571 | 581 |
582 if (runningAsTestRunner) { | |
583 // When running in test code started by the test runner, the working | |
584 // directory will always be <repo>/third_party/pkg/pub. | |
585 return path.dirname(path.dirname(path.dirname(path.current))); | |
Bob Nystrom
2015/06/30 18:33:11
Is there a reason to prefer chained dirnames over
nweiz
2015/06/30 19:47:29
Because path.join tries to avoid any unnecessary m
| |
586 } | |
587 | |
572 // Get the URL of the repo root in a way that works when either both running | 588 // Get the URL of the repo root in a way that works when either both running |
573 // as a test or as a pub executable. | 589 // as a test or as a pub executable. |
574 var url = Platform.script.replace( | 590 var url = Platform.script.replace( |
575 path: Platform.script.path.replaceAll(_dartRepoRegExp, '')); | 591 path: Platform.script.path.replaceAll(_dartRepoRegExp, '')); |
576 return path.fromUri(url); | 592 return path.fromUri(url); |
577 })(); | 593 })(); |
578 | 594 |
579 /// A line-by-line stream of standard input. | 595 /// A line-by-line stream of standard input. |
580 final Stream<String> stdinLines = streamToLines( | 596 final Stream<String> stdinLines = streamToLines( |
581 new ByteStream(stdin).toStringStream()); | 597 new ByteStream(stdin).toStringStream()); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 | 1093 |
1078 // TODO(rnystrom): Remove this and change to returning one string. | 1094 // TODO(rnystrom): Remove this and change to returning one string. |
1079 static List<String> _toLines(String output) { | 1095 static List<String> _toLines(String output) { |
1080 var lines = splitLines(output); | 1096 var lines = splitLines(output); |
1081 if (!lines.isEmpty && lines.last == "") lines.removeLast(); | 1097 if (!lines.isEmpty && lines.last == "") lines.removeLast(); |
1082 return lines; | 1098 return lines; |
1083 } | 1099 } |
1084 | 1100 |
1085 bool get success => exitCode == exit_codes.SUCCESS; | 1101 bool get success => exitCode == exit_codes.SUCCESS; |
1086 } | 1102 } |
OLD | NEW |