| 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 library dart2js.cmdline; | 5 library dart2js.cmdline; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } else { | 84 } else { |
| 85 handler.handle(argument); | 85 handler.handle(argument); |
| 86 } | 86 } |
| 87 continue OUTER; | 87 continue OUTER; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 throw 'Internal error: "$argument" did not match'; | 90 throw 'Internal error: "$argument" did not match'; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void compile(List<String> argv) { | 94 Future compile(List<String> argv) { |
| 95 bool isWindows = (Platform.operatingSystem == 'windows'); | 95 bool isWindows = (Platform.operatingSystem == 'windows'); |
| 96 stackTraceFilePrefix = '$currentDirectory'; | 96 stackTraceFilePrefix = '$currentDirectory'; |
| 97 Uri libraryRoot = currentDirectory; | 97 Uri libraryRoot = currentDirectory; |
| 98 Uri out = currentDirectory.resolve('out.js'); | 98 Uri out = currentDirectory.resolve('out.js'); |
| 99 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); | 99 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
| 100 Uri packageRoot = null; | 100 Uri packageRoot = null; |
| 101 List<String> options = new List<String>(); | 101 List<String> options = new List<String>(); |
| 102 bool explicitOut = false; | 102 bool explicitOut = false; |
| 103 bool wantHelp = false; | 103 bool wantHelp = false; |
| 104 bool wantVersion = false; | 104 bool wantVersion = false; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 381 } |
| 382 output.closeSync(); | 382 output.closeSync(); |
| 383 if (isPrimaryOutput) { | 383 if (isPrimaryOutput) { |
| 384 totalCharactersWritten += charactersWritten; | 384 totalCharactersWritten += charactersWritten; |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 return new EventSinkWrapper(writeStringSync, onDone); | 388 return new EventSinkWrapper(writeStringSync, onDone); |
| 389 } | 389 } |
| 390 | 390 |
| 391 api.compile(uri, libraryRoot, packageRoot, | 391 return api.compile(uri, libraryRoot, packageRoot, |
| 392 inputProvider.readStringFromUri, handler, | 392 inputProvider.readStringFromUri, handler, |
| 393 options, outputProvider) | 393 options, outputProvider) |
| 394 .then(compilationDone); | 394 .then(compilationDone); |
| 395 } | 395 } |
| 396 | 396 |
| 397 class EventSinkWrapper extends EventSink<String> { | 397 class EventSinkWrapper extends EventSink<String> { |
| 398 var onAdd, onClose; | 398 var onAdd, onClose; |
| 399 | 399 |
| 400 EventSinkWrapper(this.onAdd, this.onClose); | 400 EventSinkWrapper(this.onAdd, this.onClose); |
| 401 | 401 |
| 402 void add(String data) => onAdd(data); | 402 void add(String data) => onAdd(data); |
| 403 | 403 |
| 404 void addError(error) => throw error; | 404 void addError(error) => throw error; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 419 var file = new File(uriPathToNative(uri.path)).openSync(mode: FileMode.WRITE); | 419 var file = new File(uriPathToNative(uri.path)).openSync(mode: FileMode.WRITE); |
| 420 file.writeStringSync(text); | 420 file.writeStringSync(text); |
| 421 file.closeSync(); | 421 file.closeSync(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void fail(String message) { | 424 void fail(String message) { |
| 425 print(message); | 425 print(message); |
| 426 exit(1); | 426 exit(1); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void compilerMain(Options options) { | 429 Future compilerMain(Options options) { |
| 430 var root = uriPathToNative("/$LIBRARY_ROOT"); | 430 var root = uriPathToNative("/$LIBRARY_ROOT"); |
| 431 List<String> argv = ['--library-root=${options.script}$root']; | 431 List<String> argv = ['--library-root=${options.script}$root']; |
| 432 argv.addAll(options.arguments); | 432 argv.addAll(options.arguments); |
| 433 compile(argv); | 433 return compile(argv); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void help() { | 436 void help() { |
| 437 // This message should be no longer than 20 lines. The default | 437 // This message should be no longer than 20 lines. The default |
| 438 // terminal size normally 80x24. Two lines are used for the prompts | 438 // terminal size normally 80x24. Two lines are used for the prompts |
| 439 // before and after running the compiler. Another two lines may be | 439 // before and after running the compiler. Another two lines may be |
| 440 // used to print an error message. | 440 // used to print an error message. |
| 441 print(''' | 441 print(''' |
| 442 Usage: dart2js [options] dartfile | 442 Usage: dart2js [options] dartfile |
| 443 | 443 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 exit(0); | 570 exit(0); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void helpAndFail(String message) { | 573 void helpAndFail(String message) { |
| 574 help(); | 574 help(); |
| 575 print(''); | 575 print(''); |
| 576 fail(message); | 576 fail(message); |
| 577 } | 577 } |
| 578 | 578 |
| 579 void mainWithErrorHandler(Options options) { | 579 void mainWithErrorHandler(Options options) { |
| 580 try { | 580 compilerMain(options).catchError((exception) { |
| 581 compilerMain(options); | |
| 582 } catch (exception, trace) { | |
| 583 try { | 581 try { |
| 584 print('Internal error: $exception'); | 582 print('Internal error: $exception'); |
| 585 } catch (ignored) { | 583 } catch (ignored) { |
| 586 print('Internal error: error while printing exception'); | 584 print('Internal error: error while printing exception'); |
| 587 } | 585 } |
| 586 |
| 588 try { | 587 try { |
| 589 print(trace); | 588 var trace = getAttachedStackTrace(exception); |
| 589 if (trace != null) { |
| 590 print(trace); |
| 591 } |
| 590 } finally { | 592 } finally { |
| 591 exit(253); // 253 is recognized as a crash by our test scripts. | 593 exit(253); // 253 is recognized as a crash by our test scripts. |
| 592 } | 594 } |
| 593 } | 595 }); |
| 594 } | 596 } |
| 595 | 597 |
| 596 void main() { | 598 void main() { |
| 597 mainWithErrorHandler(new Options()); | 599 mainWithErrorHandler(new Options()); |
| 598 } | 600 } |
| OLD | NEW |