Chromium Code Reviews| 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 show exit, File, FileMode, Options, Platform, RandomAccessFile; | 9 show exit, File, FileMode, Platform, RandomAccessFile; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| 11 | 11 |
| 12 import '../compiler.dart' as api; | 12 import '../compiler.dart' as api; |
| 13 import 'source_file.dart'; | 13 import 'source_file.dart'; |
| 14 import 'source_file_provider.dart'; | 14 import 'source_file_provider.dart'; |
| 15 import 'filenames.dart'; | 15 import 'filenames.dart'; |
| 16 import 'util/uri_extras.dart'; | 16 import 'util/uri_extras.dart'; |
| 17 import 'util/util.dart'; | 17 import 'util/util.dart'; |
| 18 import '../../libraries.dart'; | 18 import '../../libraries.dart'; |
| 19 | 19 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 void fail(String message) { | 445 void fail(String message) { |
| 446 if (diagnosticHandler != null) { | 446 if (diagnosticHandler != null) { |
| 447 diagnosticHandler.diagnosticHandler( | 447 diagnosticHandler.diagnosticHandler( |
| 448 null, -1, -1, message, api.Diagnostic.ERROR); | 448 null, -1, -1, message, api.Diagnostic.ERROR); |
| 449 } else { | 449 } else { |
| 450 print(message); | 450 print(message); |
| 451 } | 451 } |
| 452 exit(1); | 452 exit(1); |
| 453 } | 453 } |
| 454 | 454 |
| 455 Future compilerMain(Options options) { | 455 Future compilerMain(List<String> args) { |
|
ahe
2013/10/29 16:10:09
Please don't abbreviate: args -> arguments.
| |
| 456 var root = uriPathToNative("/$LIBRARY_ROOT"); | 456 var root = uriPathToNative("/$LIBRARY_ROOT"); |
| 457 List<String> argv = ['--library-root=${options.script}$root']; | 457 args = <String>['--library-root=${Platform.script}$root']..addAll(args); |
| 458 argv.addAll(options.arguments); | 458 return compile(args); |
| 459 return compile(argv); | |
| 460 } | 459 } |
| 461 | 460 |
| 462 void help() { | 461 void help() { |
| 463 // This message should be no longer than 20 lines. The default | 462 // This message should be no longer than 20 lines. The default |
| 464 // terminal size normally 80x24. Two lines are used for the prompts | 463 // terminal size normally 80x24. Two lines are used for the prompts |
| 465 // before and after running the compiler. Another two lines may be | 464 // before and after running the compiler. Another two lines may be |
| 466 // used to print an error message. | 465 // used to print an error message. |
| 467 print(''' | 466 print(''' |
| 468 Usage: dart2js [options] dartfile | 467 Usage: dart2js [options] dartfile |
| 469 | 468 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 } | 581 } |
| 583 exit(0); | 582 exit(0); |
| 584 } | 583 } |
| 585 | 584 |
| 586 void helpAndFail(String message) { | 585 void helpAndFail(String message) { |
| 587 help(); | 586 help(); |
| 588 print(''); | 587 print(''); |
| 589 fail(message); | 588 fail(message); |
| 590 } | 589 } |
| 591 | 590 |
| 592 void mainWithErrorHandler(Options options) { | 591 void main(List<String> args) { |
|
ahe
2013/10/29 16:10:09
args -> arguments.
| |
| 593 runZoned(() => compilerMain(options), onError: (exception) { | 592 runZoned(() => compilerMain(args), onError: (exception) { |
| 594 try { | 593 try { |
| 595 print('Internal error: $exception'); | 594 print('Internal error: $exception'); |
| 596 } catch (ignored) { | 595 } catch (ignored) { |
| 597 print('Internal error: error while printing exception'); | 596 print('Internal error: error while printing exception'); |
| 598 } | 597 } |
| 599 | 598 |
| 600 try { | 599 try { |
| 601 var trace = getAttachedStackTrace(exception); | 600 var trace = getAttachedStackTrace(exception); |
| 602 if (trace != null) { | 601 if (trace != null) { |
| 603 print(trace); | 602 print(trace); |
| 604 } | 603 } |
| 605 } finally { | 604 } finally { |
| 606 exit(253); // 253 is recognized as a crash by our test scripts. | 605 exit(253); // 253 is recognized as a crash by our test scripts. |
| 607 } | 606 } |
| 608 }); | 607 }); |
| 609 } | 608 } |
| 610 | |
| 611 void main() { | |
| 612 mainWithErrorHandler(new Options()); | |
| 613 } | |
| OLD | NEW |