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

Side by Side Diff: sdk/lib/_internal/pub_generated/bin/pub.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 import 'dart:async';
2 import 'dart:io';
3 import 'package:args/args.dart';
4 import 'package:http/http.dart' as http;
5 import 'package:path/path.dart' as path;
6 import 'package:stack_trace/stack_trace.dart';
7 import '../lib/src/command.dart';
8 import '../lib/src/exceptions.dart';
9 import '../lib/src/exit_codes.dart' as exit_codes;
10 import '../lib/src/http.dart';
11 import '../lib/src/io.dart';
12 import '../lib/src/log.dart' as log;
13 import '../lib/src/sdk.dart' as sdk;
14 import '../lib/src/solver/version_solver.dart';
15 import '../lib/src/utils.dart';
16 void main(List<String> arguments) {
17 ArgResults options;
18 try {
19 options = PubCommand.pubArgParser.parse(arguments);
20 } on FormatException catch (e) {
21 log.error(e.message);
22 log.error('Run "pub help" to see available options.');
23 flushThenExit(exit_codes.USAGE);
24 return;
25 }
26 log.withPrejudice = options['with-prejudice'];
27 if (options['version']) {
28 log.message('Pub ${sdk.version}');
29 return;
30 }
31 if (options['help']) {
32 PubCommand.printGlobalUsage();
33 return;
34 }
35 if (options['trace']) {
36 log.recordTranscript();
37 }
38 switch (options['verbosity']) {
39 case 'normal':
40 log.verbosity = log.Verbosity.NORMAL;
41 break;
42 case 'io':
43 log.verbosity = log.Verbosity.IO;
44 break;
45 case 'solver':
46 log.verbosity = log.Verbosity.SOLVER;
47 break;
48 case 'all':
49 log.verbosity = log.Verbosity.ALL;
50 break;
51 default:
52 if (options['verbose']) {
53 log.verbosity = log.Verbosity.ALL;
54 }
55 break;
56 }
57 log.fine('Pub ${sdk.version}');
58 var cacheDir;
59 if (Platform.environment.containsKey('PUB_CACHE')) {
60 cacheDir = Platform.environment['PUB_CACHE'];
61 } else if (Platform.operatingSystem == 'windows') {
62 var appData = Platform.environment['APPDATA'];
63 cacheDir = path.join(appData, 'Pub', 'Cache');
64 } else {
65 cacheDir = '${Platform.environment['HOME']}/.pub-cache';
66 }
67 validatePlatform().then((_) => runPub(cacheDir, options, arguments));
68 }
69 void runPub(String cacheDir, ArgResults options, List<String> arguments) {
70 var captureStackChains =
71 options['trace'] ||
72 options['verbose'] ||
73 options['verbosity'] == 'all';
74 captureErrors(
75 () => invokeCommand(cacheDir, options),
76 captureStackChains: captureStackChains).catchError((error, Chain chain) {
77 log.exception(error, chain);
78 if (options['trace']) {
79 log.dumpTranscript();
80 } else if (!isUserFacingException(error)) {
81 log.error("""
82 This is an unexpected error. Please run
83
84 pub --trace ${arguments.map((arg) => "'$arg'").join(' ')}
85
86 and include the results in a bug report on http://dartbug.com/new.
87 """);
88 }
89 return flushThenExit(chooseExitCode(error));
90 }).then((_) {
91 return flushThenExit(exit_codes.SUCCESS);
92 });
93 }
94 int chooseExitCode(exception) {
95 while (exception is WrappedException) exception = exception.innerError;
96 if (exception is HttpException ||
97 exception is http.ClientException ||
98 exception is SocketException ||
99 exception is PubHttpException ||
100 exception is DependencyNotFoundException) {
101 return exit_codes.UNAVAILABLE;
102 } else if (exception is FormatException || exception is DataException) {
103 return exit_codes.DATA;
104 } else if (exception is UsageException) {
105 return exit_codes.USAGE;
106 } else {
107 return 1;
108 }
109 }
110 Future invokeCommand(String cacheDir, ArgResults mainOptions) {
111 final completer0 = new Completer();
112 scheduleMicrotask(() {
113 try {
114 var commands = PubCommand.mainCommands;
115 var command;
116 var commandString = "pub";
117 var options = mainOptions;
118 break0(x2) {
119 join0() {
120 join1(x0) {
121 completer0.complete(null);
122 }
123 finally0(cont0, v0) {
124 command.cache.deleteTempDir();
125 cont0(v0);
126 }
127 catch0(e0) {
128 finally0(join1, null);
129 }
130 try {
131 finally0((v1) {
132 completer0.complete(v1);
133 }, command.run(cacheDir, mainOptions, options));
134 } catch (e1) {
135 catch0(e1);
136 }
137 }
138 if (!command.takesArguments && options.rest.isNotEmpty) {
139 command.usageError(
140 'Command "${options.name}" does not take any arguments.');
141 join0();
142 } else {
143 join0();
144 }
145 }
146 continue0(x3) {
147 if (commands.isNotEmpty) {
148 Future.wait([]).then((x1) {
149 join2() {
150 options = options.command;
151 command = commands[options.name];
152 commands = command.subcommands;
153 commandString += " ${options.name}";
154 join3() {
155 continue0(null);
156 }
157 if (options['help']) {
158 command.printUsage();
159 completer0.complete(new Future.value());
160 } else {
161 join3();
162 }
163 }
164 if (options.command == null) {
165 join4() {
166 join2();
167 }
168 if (options.rest.isEmpty) {
169 join5() {
170 command.usageError(
171 'Missing subcommand for "${commandString}".');
172 join4();
173 }
174 if (command == null) {
175 PubCommand.printGlobalUsage();
176 completer0.complete(new Future.value());
177 } else {
178 join5();
179 }
180 } else {
181 join6() {
182 command.usageError(
183 'Could not find a subcommand named '
184 '"${options.rest[0]}" for "${commandString}".');
185 join4();
186 }
187 if (command == null) {
188 PubCommand.usageErrorWithCommands(
189 commands,
190 'Could not find a command named "${options.rest[0]}".');
191 join6();
192 } else {
193 join6();
194 }
195 }
196 } else {
197 join2();
198 }
199 });
200 } else {
201 break0(null);
202 }
203 }
204 continue0(null);
205 } catch (e2) {
206 completer0.completeError(e2);
207 }
208 });
209 return completer0.future;
210 }
211 Future validatePlatform() {
212 final completer0 = new Completer();
213 scheduleMicrotask(() {
214 try {
215 join0() {
216 runProcess('ver', []).then((x0) {
217 try {
218 var result = x0;
219 join1() {
220 completer0.complete(null);
221 }
222 if (result.stdout.join('\n').contains('XP')) {
223 log.error('Sorry, but pub is not supported on Windows XP.');
224 flushThenExit(exit_codes.USAGE).then((x1) {
225 try {
226 x1;
227 join1();
228 } catch (e1) {
229 completer0.completeError(e1);
230 }
231 }, onError: (e2) {
232 completer0.completeError(e2);
233 });
234 } else {
235 join1();
236 }
237 } catch (e0) {
238 completer0.completeError(e0);
239 }
240 }, onError: (e3) {
241 completer0.completeError(e3);
242 });
243 }
244 if (Platform.operatingSystem != 'windows') {
245 completer0.complete(null);
246 } else {
247 join0();
248 }
249 } catch (e4) {
250 completer0.completeError(e4);
251 }
252 });
253 return completer0.future;
254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698