Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Unified Diff: sdk/lib/_internal/pub_generated/bin/pub.dart

Issue 657673002: Regenerate pub sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub_generated/bin/pub.dart
diff --git a/sdk/lib/_internal/pub_generated/bin/pub.dart b/sdk/lib/_internal/pub_generated/bin/pub.dart
index ae5c7a08ecaa791dd6af3ab2693b408792c58606..50ee1ce19a693af6f17fcd39e5ebb32ab06bbb1f 100644
--- a/sdk/lib/_internal/pub_generated/bin/pub.dart
+++ b/sdk/lib/_internal/pub_generated/bin/pub.dart
@@ -1,9 +1,15 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
import 'dart:async';
import 'dart:io';
+
import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart';
+
import '../lib/src/command.dart';
import '../lib/src/exceptions.dart';
import '../lib/src/exit_codes.dart' as exit_codes;
@@ -13,8 +19,10 @@ import '../lib/src/log.dart' as log;
import '../lib/src/sdk.dart' as sdk;
import '../lib/src/solver/version_solver.dart';
import '../lib/src/utils.dart';
+
void main(List<String> arguments) {
ArgResults options;
+
try {
options = PubCommand.pubArgParser.parse(arguments);
} on FormatException catch (e) {
@@ -23,18 +31,23 @@ void main(List<String> arguments) {
flushThenExit(exit_codes.USAGE);
return;
}
+
log.withPrejudice = options['with-prejudice'];
+
if (options['version']) {
log.message('Pub ${sdk.version}');
return;
}
+
if (options['help']) {
PubCommand.printGlobalUsage();
return;
}
+
if (options['trace']) {
log.recordTranscript();
}
+
switch (options['verbosity']) {
case 'normal':
log.verbosity = log.Verbosity.NORMAL;
@@ -49,12 +62,15 @@ void main(List<String> arguments) {
log.verbosity = log.Verbosity.ALL;
break;
default:
+ // No specific verbosity given, so check for the shortcut.
if (options['verbose']) {
log.verbosity = log.Verbosity.ALL;
}
break;
}
+
log.fine('Pub ${sdk.version}');
+
var cacheDir;
if (Platform.environment.containsKey('PUB_CACHE')) {
cacheDir = Platform.environment['PUB_CACHE'];
@@ -64,17 +80,25 @@ void main(List<String> arguments) {
} else {
cacheDir = '${Platform.environment['HOME']}/.pub-cache';
}
+
validatePlatform().then((_) => runPub(cacheDir, options, arguments));
}
+
+/// Runs the appropriate pub command whose [arguments] have been parsed to
+/// [options] using the system cache in [cacheDir].
+///
+/// Handles and correctly reports any errors that occur while running.
void runPub(String cacheDir, ArgResults options, List<String> arguments) {
var captureStackChains =
options['trace'] ||
options['verbose'] ||
options['verbosity'] == 'all';
+
captureErrors(
() => invokeCommand(cacheDir, options),
captureStackChains: captureStackChains).catchError((error, Chain chain) {
log.exception(error, chain);
+
if (options['trace']) {
log.dumpTranscript();
} else if (!isUserFacingException(error)) {
@@ -86,13 +110,20 @@ This is an unexpected error. Please run
and include the results in a bug report on http://dartbug.com/new.
""");
}
+
return flushThenExit(chooseExitCode(error));
}).then((_) {
+ // Explicitly exit on success to ensure that any dangling dart:io handles
+ // don't cause the process to never terminate.
return flushThenExit(exit_codes.SUCCESS);
});
}
+
+/// Returns the appropriate exit code for [exception], falling back on 1 if no
+/// appropriate exit code could be found.
int chooseExitCode(exception) {
while (exception is WrappedException) exception = exception.innerError;
+
if (exception is HttpException ||
exception is http.ClientException ||
exception is SocketException ||
@@ -107,6 +138,8 @@ int chooseExitCode(exception) {
return 1;
}
}
+
+/// Walks the command tree and runs the selected pub command.
Future invokeCommand(String cacheDir, ArgResults mainOptions) {
final completer0 = new Completer();
scheduleMicrotask(() {
@@ -115,24 +148,25 @@ Future invokeCommand(String cacheDir, ArgResults mainOptions) {
var command;
var commandString = "pub";
var options = mainOptions;
- break0(x2) {
+ break0() {
join0() {
- join1(x0) {
- completer0.complete(null);
+ join1() {
+ completer0.complete();
}
- finally0(cont0, v0) {
+ finally0(cont0) {
command.cache.deleteTempDir();
- cont0(v0);
+ cont0();
}
- catch0(e0) {
- finally0(join1, null);
+ catch0(e1, s1) {
+ finally0(() => completer0.completeError(e1, s1));
}
try {
- finally0((v1) {
- completer0.complete(v1);
- }, command.run(cacheDir, mainOptions, options));
- } catch (e1) {
- catch0(e1);
+ final v0 = command.run(cacheDir, mainOptions, options);
+ finally0(() {
+ completer0.complete(v0);
+ });
+ } catch (e2, s2) {
+ catch0(e2, s2);
}
}
if (!command.takesArguments && options.rest.isNotEmpty) {
@@ -143,71 +177,77 @@ Future invokeCommand(String cacheDir, ArgResults mainOptions) {
join0();
}
}
- continue0(x3) {
+ var trampoline0;
+ continue0() {
+ trampoline0 = null;
if (commands.isNotEmpty) {
- Future.wait([]).then((x1) {
- join2() {
- options = options.command;
- command = commands[options.name];
- commands = command.subcommands;
- commandString += " ${options.name}";
- join3() {
- continue0(null);
+ join2() {
+ options = options.command;
+ command = commands[options.name];
+ commands = command.subcommands;
+ commandString += " ${options.name}";
+ join3() {
+ trampoline0 = continue0;
+ }
+ if (options['help']) {
+ command.printUsage();
+ completer0.complete(new Future.value());
+ } else {
+ join3();
+ }
+ }
+ if (options.command == null) {
+ join4() {
+ join2();
+ }
+ if (options.rest.isEmpty) {
+ join5() {
+ command.usageError(
+ 'Missing subcommand for "${commandString}".');
+ join4();
}
- if (options['help']) {
- command.printUsage();
+ if (command == null) {
+ PubCommand.printGlobalUsage();
completer0.complete(new Future.value());
} else {
- join3();
+ join5();
}
- }
- if (options.command == null) {
- join4() {
- join2();
+ } else {
+ join6() {
+ command.usageError(
+ 'Could not find a subcommand named '
+ '"${options.rest[0]}" for "${commandString}".');
+ join4();
}
- if (options.rest.isEmpty) {
- join5() {
- command.usageError(
- 'Missing subcommand for "${commandString}".');
- join4();
- }
- if (command == null) {
- PubCommand.printGlobalUsage();
- completer0.complete(new Future.value());
- } else {
- join5();
- }
+ if (command == null) {
+ PubCommand.usageErrorWithCommands(
+ commands,
+ 'Could not find a command named "${options.rest[0]}".');
+ join6();
} else {
- join6() {
- command.usageError(
- 'Could not find a subcommand named '
- '"${options.rest[0]}" for "${commandString}".');
- join4();
- }
- if (command == null) {
- PubCommand.usageErrorWithCommands(
- commands,
- 'Could not find a command named "${options.rest[0]}".');
- join6();
- } else {
- join6();
- }
+ join6();
}
- } else {
- join2();
}
- });
+ } else {
+ join2();
+ }
} else {
- break0(null);
+ break0();
}
}
- continue0(null);
- } catch (e2) {
- completer0.completeError(e2);
+ trampoline0 = continue0;
+ do trampoline0(); while (trampoline0 != null);
+ } catch (e, s) {
+ completer0.completeError(e, s);
}
});
return completer0.future;
}
+
+/// Checks that pub is running on a supported platform.
+///
+/// If it isn't, it prints an error message and exits. Completes when the
+/// validation is done.
Future validatePlatform() {
final completer0 = new Completer();
scheduleMicrotask(() {
@@ -217,7 +257,7 @@ Future validatePlatform() {
try {
var result = x0;
join1() {
- completer0.complete(null);
+ completer0.complete();
}
if (result.stdout.join('\n').contains('XP')) {
log.error('Sorry, but pub is not supported on Windows XP.');
@@ -225,29 +265,25 @@ Future validatePlatform() {
try {
x1;
join1();
- } catch (e1) {
- completer0.completeError(e1);
+ } catch (e0, s0) {
+ completer0.completeError(e0, s0);
}
- }, onError: (e2) {
- completer0.completeError(e2);
- });
+ }, onError: completer0.completeError);
} else {
join1();
}
- } catch (e0) {
- completer0.completeError(e0);
+ } catch (e1, s1) {
+ completer0.completeError(e1, s1);
}
- }, onError: (e3) {
- completer0.completeError(e3);
- });
+ }, onError: completer0.completeError);
}
if (Platform.operatingSystem != 'windows') {
completer0.complete(null);
} else {
join0();
}
- } catch (e4) {
- completer0.completeError(e4);
+ } catch (e, s) {
+ completer0.completeError(e, s);
}
});
return completer0.future;
« no previous file with comments | « sdk/lib/_internal/pub_generated/bin/async_compile.dart ('k') | sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698