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

Side by Side Diff: utils/pub/pub.dart

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix after merge. Created 7 years, 10 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
« no previous file with comments | « utils/pub/package.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// The main entrypoint for the pub command line application. 5 /// The main entrypoint for the pub command line application.
6 library pub; 6 library pub;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import '../../pkg/args/lib/args.dart'; 9 import '../../pkg/args/lib/args.dart';
10 import '../../pkg/path/lib/path.dart' as path; 10 import '../../pkg/path/lib/path.dart' as path;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 log.error(message); 229 log.error(message);
230 if (globalOptions['trace'] && trace != null) { 230 if (globalOptions['trace'] && trace != null) {
231 log.error(trace); 231 log.error(trace);
232 log.dumpTranscript(); 232 log.dumpTranscript();
233 } 233 }
234 234
235 exit(_chooseExitCode(error)); 235 exit(_chooseExitCode(error));
236 } 236 }
237 237
238 var future = new Future.immediate(null); 238 defer(() {
239 if (requiresEntrypoint) { 239 if (requiresEntrypoint) {
240 // TODO(rnystrom): Will eventually need better logic to walk up 240 // TODO(rnystrom): Will eventually need better logic to walk up
241 // subdirectories until we hit one that looks package-like. For now, just 241 // subdirectories until we hit one that looks package-like. For now,
242 // assume the cwd is it. 242 // just assume the cwd is it.
243 future = Entrypoint.load(path.current, cache); 243 entrypoint = new Entrypoint(path.current, cache);
244 } 244 }
245 245
246 future = future.then((entrypoint) { 246 var commandFuture = onRun();
247 this.entrypoint = entrypoint; 247 if (commandFuture == null) return true;
248 try {
249 var commandFuture = onRun();
250 if (commandFuture == null) return true;
251 248
252 return commandFuture; 249 return commandFuture;
253 } catch (error, trace) { 250 }).whenComplete(() => cache_.deleteTempDir()).catchError((asyncError) {
254 handleError(error, trace); 251 var e = asyncError.error;
252 if (e is PubspecNotFoundException && e.name == null) {
253 e = 'Could not find a file named "pubspec.yaml" in the directory '
254 '${path.current}.';
255 } else if (e is PubspecHasNoNameException && e.name == null) {
256 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: '
257 '${basename(path.current)}").';
255 } 258 }
256 });
257 259
258 future 260 handleError(e, asyncError.stackTrace);
259 .then((_) => cache_.deleteTempDir()) 261 }).then((_) {
260 .catchError((asyncError) {
261 var e = asyncError.error;
262 if (e is PubspecNotFoundException && e.name == null) {
263 e = 'Could not find a file named "pubspec.yaml" in the directory '
264 '${path.current}.';
265 } else if (e is PubspecHasNoNameException && e.name == null) {
266 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: '
267 '${basename(path.current)}").';
268 }
269
270 handleError(e, asyncError.stackTrace);
271 })
272 // Explicitly exit on success to ensure that any dangling dart:io handles 262 // Explicitly exit on success to ensure that any dangling dart:io handles
273 // don't cause the process to never terminate. 263 // don't cause the process to never terminate.
274 .then((_) => exit(0)); 264 exit(0);
265 });
275 } 266 }
276 267
277 /// Override this to perform the specific command. Return a future that 268 /// Override this to perform the specific command. Return a future that
278 /// completes when the command is done or fails if the command fails. If the 269 /// completes when the command is done or fails if the command fails. If the
279 /// command is synchronous, it may return `null`. 270 /// command is synchronous, it may return `null`.
280 Future onRun(); 271 Future onRun();
281 272
282 /// Displays usage information for this command. 273 /// Displays usage information for this command.
283 void printUsage([String description]) { 274 void printUsage([String description]) {
284 if (description == null) description = this.description; 275 if (description == null) description = this.description;
(...skipping 16 matching lines...) Expand all
301 if (exception is HttpException || exception is HttpParserException || 292 if (exception is HttpException || exception is HttpParserException ||
302 exception is SocketIOException || exception is PubHttpException) { 293 exception is SocketIOException || exception is PubHttpException) {
303 return exit_codes.UNAVAILABLE; 294 return exit_codes.UNAVAILABLE;
304 } else if (exception is FormatException) { 295 } else if (exception is FormatException) {
305 return exit_codes.DATA; 296 return exit_codes.DATA;
306 } else { 297 } else {
307 return 1; 298 return 1;
308 } 299 }
309 } 300 }
310 } 301 }
OLDNEW
« no previous file with comments | « utils/pub/package.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698