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'; |
ahe
2013/11/26 11:18:25
use show?
Johnni Winther
2013/11/27 07:58:04
Done.
| |
8 import 'dart:io' | 8 import 'dart:io' |
9 show exit, File, FileMode, 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'; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 } | 411 } |
412 output.closeSync(); | 412 output.closeSync(); |
413 if (isPrimaryOutput) { | 413 if (isPrimaryOutput) { |
414 totalCharactersWritten += charactersWritten; | 414 totalCharactersWritten += charactersWritten; |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 return new EventSinkWrapper(writeStringSync, onDone); | 418 return new EventSinkWrapper(writeStringSync, onDone); |
419 } | 419 } |
420 | 420 |
421 return api.compile(uri, libraryRoot, packageRoot, | 421 return compileFunc(uri, libraryRoot, packageRoot, |
422 inputProvider, diagnosticHandler, | 422 inputProvider, diagnosticHandler, |
423 options, outputProvider, environment) | 423 options, outputProvider, environment) |
424 .then(compilationDone); | 424 .then(compilationDone); |
425 } | 425 } |
426 | 426 |
427 class EventSinkWrapper extends EventSink<String> { | 427 class EventSinkWrapper extends EventSink<String> { |
428 var onAdd, onClose; | 428 var onAdd, onClose; |
429 | 429 |
430 EventSinkWrapper(this.onAdd, this.onClose); | 430 EventSinkWrapper(this.onAdd, this.onClose); |
431 | 431 |
432 void add(String data) => onAdd(data); | 432 void add(String data) => onAdd(data); |
433 | 433 |
(...skipping 17 matching lines...) Expand all Loading... | |
451 file.closeSync(); | 451 file.closeSync(); |
452 } | 452 } |
453 | 453 |
454 void fail(String message) { | 454 void fail(String message) { |
455 if (diagnosticHandler != null) { | 455 if (diagnosticHandler != null) { |
456 diagnosticHandler.diagnosticHandler( | 456 diagnosticHandler.diagnosticHandler( |
457 null, -1, -1, message, api.Diagnostic.ERROR); | 457 null, -1, -1, message, api.Diagnostic.ERROR); |
458 } else { | 458 } else { |
459 print(message); | 459 print(message); |
460 } | 460 } |
461 exit(1); | 461 exitFunc(1); |
462 } | 462 } |
463 | 463 |
464 Future compilerMain(List<String> arguments) { | 464 Future compilerMain(List<String> arguments) { |
465 var root = uriPathToNative("/$LIBRARY_ROOT"); | 465 var root = uriPathToNative("/$LIBRARY_ROOT"); |
466 arguments = <String>['--library-root=${Platform.script.toFilePath()}$root'] | 466 arguments = <String>['--library-root=${Platform.script.toFilePath()}$root'] |
467 ..addAll(arguments); | 467 ..addAll(arguments); |
468 return compile(arguments); | 468 return compile(arguments); |
469 } | 469 } |
470 | 470 |
471 void help() { | 471 void help() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 : BUILD_ID; | 585 : BUILD_ID; |
586 print('Dart-to-JavaScript compiler (dart2js) version: $version'); | 586 print('Dart-to-JavaScript compiler (dart2js) version: $version'); |
587 } | 587 } |
588 if (wantHelp) { | 588 if (wantHelp) { |
589 if (verbose) { | 589 if (verbose) { |
590 verboseHelp(); | 590 verboseHelp(); |
591 } else { | 591 } else { |
592 help(); | 592 help(); |
593 } | 593 } |
594 } | 594 } |
595 exit(0); | 595 exitFunc(0); |
596 } | 596 } |
597 | 597 |
598 void helpAndFail(String message) { | 598 void helpAndFail(String message) { |
599 help(); | 599 help(); |
600 print(''); | 600 print(''); |
601 fail(message); | 601 fail(message); |
602 } | 602 } |
603 | 603 |
604 void main(List<String> arguments) { | 604 void main(List<String> arguments) { |
605 runZoned(() => compilerMain(arguments), onError: (exception, trace) { | 605 internalMain(arguments); |
606 } | |
607 | |
608 var exitFunc = exit; | |
609 var compileFunc = api.compile; | |
610 | |
611 Future internalMain(List<String> arguments) { | |
612 onError(exception, trace) { | |
606 try { | 613 try { |
607 print('Internal error: $exception'); | 614 print('Internal error: $exception'); |
608 } catch (ignored) { | 615 } catch (ignored) { |
609 print('Internal error: error while printing exception'); | 616 print('Internal error: error while printing exception'); |
610 } | 617 } |
611 | 618 |
612 try { | 619 try { |
613 if (trace != null) { | 620 if (trace != null) { |
614 print(trace); | 621 print(trace); |
615 } | 622 } |
616 } finally { | 623 } finally { |
617 exit(253); // 253 is recognized as a crash by our test scripts. | 624 exitFunc(253); // 253 is recognized as a crash by our test scripts. |
618 } | 625 } |
619 }); | 626 } |
627 | |
628 try { | |
629 return compilerMain(arguments).catchError(onError); | |
630 } catch (exception, trace) { | |
631 onError(exception, trace); | |
632 return new Future.value(); | |
633 } | |
620 } | 634 } |
OLD | NEW |