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> arguments) { |
456 var root = uriPathToNative("/$LIBRARY_ROOT"); | 456 var root = uriPathToNative("/$LIBRARY_ROOT"); |
457 List<String> argv = ['--library-root=${options.script}$root']; | 457 arguments = |
458 argv.addAll(options.arguments); | 458 <String>['--library-root=${Platform.script}$root']..addAll(arguments); |
459 return compile(argv); | 459 return compile(arguments); |
460 } | 460 } |
461 | 461 |
462 void help() { | 462 void help() { |
463 // This message should be no longer than 20 lines. The default | 463 // This message should be no longer than 20 lines. The default |
464 // terminal size normally 80x24. Two lines are used for the prompts | 464 // terminal size normally 80x24. Two lines are used for the prompts |
465 // before and after running the compiler. Another two lines may be | 465 // before and after running the compiler. Another two lines may be |
466 // used to print an error message. | 466 // used to print an error message. |
467 print(''' | 467 print(''' |
468 Usage: dart2js [options] dartfile | 468 Usage: dart2js [options] dartfile |
469 | 469 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 582 } |
583 exit(0); | 583 exit(0); |
584 } | 584 } |
585 | 585 |
586 void helpAndFail(String message) { | 586 void helpAndFail(String message) { |
587 help(); | 587 help(); |
588 print(''); | 588 print(''); |
589 fail(message); | 589 fail(message); |
590 } | 590 } |
591 | 591 |
592 void mainWithErrorHandler(Options options) { | 592 void main(List<String> arguments) { |
593 runZoned(() => compilerMain(options), onError: (exception) { | 593 runZoned(() => compilerMain(arguments), onError: (exception) { |
594 try { | 594 try { |
595 print('Internal error: $exception'); | 595 print('Internal error: $exception'); |
596 } catch (ignored) { | 596 } catch (ignored) { |
597 print('Internal error: error while printing exception'); | 597 print('Internal error: error while printing exception'); |
598 } | 598 } |
599 | 599 |
600 try { | 600 try { |
601 var trace = getAttachedStackTrace(exception); | 601 var trace = getAttachedStackTrace(exception); |
602 if (trace != null) { | 602 if (trace != null) { |
603 print(trace); | 603 print(trace); |
604 } | 604 } |
605 } finally { | 605 } finally { |
606 exit(253); // 253 is recognized as a crash by our test scripts. | 606 exit(253); // 253 is recognized as a crash by our test scripts. |
607 } | 607 } |
608 }); | 608 }); |
609 } | 609 } |
610 | |
611 void main() { | |
612 mainWithErrorHandler(new Options()); | |
613 } | |
OLD | NEW |