| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart | 491 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart |
| 492 /// source repository. | 492 /// source repository. |
| 493 final bool runningFromSdk = | 493 final bool runningFromSdk = |
| 494 !runningFromTest && Platform.script.path.endsWith('.snapshot'); | 494 !runningFromTest && Platform.script.path.endsWith('.snapshot'); |
| 495 | 495 |
| 496 /// Whether pub is running from source in the Dart repo. | 496 /// Whether pub is running from source in the Dart repo. |
| 497 /// | 497 /// |
| 498 /// This can happen when building Observatory, for example. | 498 /// This can happen when building Observatory, for example. |
| 499 final bool runningFromDartRepo = | 499 final bool runningFromDartRepo = |
| 500 Platform.script.path.endsWith('/third_party/pkg/pub/bin/pub.dart'); | 500 Platform.script.path.endsWith('/third_party/pkg_tested/pub/bin/pub.dart'); |
| 501 | 501 |
| 502 /// Resolves [target] relative to the path to pub's `asset` directory. | 502 /// Resolves [target] relative to the path to pub's `asset` directory. |
| 503 String assetPath(String target) => runningFromSdk | 503 String assetPath(String target) => runningFromSdk |
| 504 ? sdkAssetPath(target) | 504 ? sdkAssetPath(target) |
| 505 : path.join(pubRoot, 'lib', 'src', 'asset', target); | 505 : path.join(pubRoot, 'lib', 'src', 'asset', target); |
| 506 | 506 |
| 507 /// Resolves [target] relative to the Dart SDK's `asset` directory. | 507 /// Resolves [target] relative to the Dart SDK's `asset` directory. |
| 508 /// | 508 /// |
| 509 /// Throws a [StateError] if called from within the Dart repo. | 509 /// Throws a [StateError] if called from within the Dart repo. |
| 510 String sdkAssetPath(String target) { | 510 String sdkAssetPath(String target) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 539 | 539 |
| 540 /// The path to the root of the Dart repo. | 540 /// The path to the root of the Dart repo. |
| 541 /// | 541 /// |
| 542 /// This throws a [StateError] if it's called when not running pub from source | 542 /// This throws a [StateError] if it's called when not running pub from source |
| 543 /// in the Dart repo. | 543 /// in the Dart repo. |
| 544 final String dartRepoRoot = (() { | 544 final String dartRepoRoot = (() { |
| 545 if (!runningFromDartRepo) { | 545 if (!runningFromDartRepo) { |
| 546 throw new StateError("Not running from source in the Dart repo."); | 546 throw new StateError("Not running from source in the Dart repo."); |
| 547 } | 547 } |
| 548 | 548 |
| 549 // In the Dart repo, the script is in "third_party/pkg/pub/bin". | 549 // In the Dart repo, the script is in "third_party/pkg_tested/pub/bin". |
| 550 return path.dirname(path.dirname(path.dirname(path.dirname(path.dirname( | 550 return path.dirname(path.dirname(path.dirname(path.dirname(path.dirname( |
| 551 path.fromUri(Platform.script)))))); | 551 path.fromUri(Platform.script)))))); |
| 552 })(); | 552 })(); |
| 553 | 553 |
| 554 /// A line-by-line stream of standard input. | 554 /// A line-by-line stream of standard input. |
| 555 final Stream<String> stdinLines = streamToLines( | 555 final Stream<String> stdinLines = streamToLines( |
| 556 new ByteStream(stdin).toStringStream()); | 556 new ByteStream(stdin).toStringStream()); |
| 557 | 557 |
| 558 /// Displays a message and reads a yes/no confirmation from the user. | 558 /// Displays a message and reads a yes/no confirmation from the user. |
| 559 /// | 559 /// |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1052 |
| 1053 // TODO(rnystrom): Remove this and change to returning one string. | 1053 // TODO(rnystrom): Remove this and change to returning one string. |
| 1054 static List<String> _toLines(String output) { | 1054 static List<String> _toLines(String output) { |
| 1055 var lines = splitLines(output); | 1055 var lines = splitLines(output); |
| 1056 if (!lines.isEmpty && lines.last == "") lines.removeLast(); | 1056 if (!lines.isEmpty && lines.last == "") lines.removeLast(); |
| 1057 return lines; | 1057 return lines; |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 bool get success => exitCode == exit_codes.SUCCESS; | 1060 bool get success => exitCode == exit_codes.SUCCESS; |
| 1061 } | 1061 } |
| OLD | NEW |