| 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' show Future; | 7 import 'dart:async' show Future; |
| 8 import 'dart:convert' show UTF8, LineSplitter; | 8 import 'dart:convert' show UTF8, LineSplitter; |
| 9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; | 9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 continue OUTER; | 97 continue OUTER; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 throw 'Internal error: "$argument" did not match'; | 100 throw 'Internal error: "$argument" did not match'; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 FormattingDiagnosticHandler diagnosticHandler; | 104 FormattingDiagnosticHandler diagnosticHandler; |
| 105 | 105 |
| 106 Future<api.CompilationResult> compile(List<String> argv) { | 106 Future<api.CompilationResult> compile(List<String> argv) { |
| 107 Stopwatch wallclock = new Stopwatch()..start(); |
| 107 stackTraceFilePrefix = '$currentDirectory'; | 108 stackTraceFilePrefix = '$currentDirectory'; |
| 108 Uri libraryRoot = currentDirectory; | 109 Uri libraryRoot = currentDirectory; |
| 109 Uri out = currentDirectory.resolve('out.js'); | 110 Uri out = currentDirectory.resolve('out.js'); |
| 110 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); | 111 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
| 111 List<Uri> resolutionInputs; | 112 List<Uri> resolutionInputs; |
| 112 List<String> bazelPaths; | 113 List<String> bazelPaths; |
| 113 Uri packageConfig = null; | 114 Uri packageConfig = null; |
| 114 Uri packageRoot = null; | 115 Uri packageRoot = null; |
| 115 List<String> options = new List<String>(); | 116 List<String> options = new List<String>(); |
| 116 List<String> explicitOutputArguments = <String>[]; | 117 List<String> explicitOutputArguments = <String>[]; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 onFailure: fail, | 525 onFailure: fail, |
| 525 resolutionOutput: resolveOnly ? resolutionOutput : null); | 526 resolutionOutput: resolveOnly ? resolutionOutput : null); |
| 526 | 527 |
| 527 api.CompilationResult compilationDone(api.CompilationResult result) { | 528 api.CompilationResult compilationDone(api.CompilationResult result) { |
| 528 if (analyzeOnly) return result; | 529 if (analyzeOnly) return result; |
| 529 if (!result.isSuccess) { | 530 if (!result.isSuccess) { |
| 530 fail('Compilation failed.'); | 531 fail('Compilation failed.'); |
| 531 } | 532 } |
| 532 writeString( | 533 writeString( |
| 533 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); | 534 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); |
| 534 diagnosticHandler | 535 int dartCharactersRead = inputProvider.dartCharactersRead; |
| 535 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' | 536 int jsCharactersWritten = outputProvider.totalCharactersWrittenJavaScript; |
| 536 '-> ${outputProvider.totalCharactersWritten} characters ' | 537 int jsCharactersPrimary = outputProvider.totalCharactersWrittenPrimary; |
| 537 'JavaScript in ' | 538 |
| 538 '${relativize(currentDirectory, out, Platform.isWindows)}'); | 539 print('Compiled ' |
| 540 '${_formatCharacterCount(dartCharactersRead)} characters Dart' |
| 541 ' to ' |
| 542 '${_formatCharacterCount(jsCharactersWritten)} characters JavaScript' |
| 543 ' in ' |
| 544 '${_formatDurationAsSeconds(wallclock.elapsed)} seconds'); |
| 545 |
| 546 diagnosticHandler.info( |
| 547 '${_formatCharacterCount(jsCharactersPrimary)} characters JavaScript' |
| 548 ' in ' |
| 549 '${relativize(currentDirectory, out, Platform.isWindows)}'); |
| 539 if (diagnosticHandler.verbose) { | 550 if (diagnosticHandler.verbose) { |
| 540 String input = uriPathToNative(arguments[0]); | 551 String input = uriPathToNative(arguments[0]); |
| 541 print('Dart file ($input) compiled to JavaScript.'); | 552 print('Dart file ($input) compiled to JavaScript.'); |
| 542 print('Wrote the following files:'); | 553 print('Wrote the following files:'); |
| 543 for (String filename in outputProvider.allOutputFiles) { | 554 for (String filename in outputProvider.allOutputFiles) { |
| 544 print(" $filename"); | 555 print(" $filename"); |
| 545 } | 556 } |
| 546 } else if (explicitOutputArguments.isNotEmpty) { | 557 } else if (explicitOutputArguments.isNotEmpty) { |
| 547 String input = uriPathToNative(arguments[0]); | 558 String input = uriPathToNative(arguments[0]); |
| 548 String output = relativize(currentDirectory, out, Platform.isWindows); | 559 String output = relativize(currentDirectory, out, Platform.isWindows); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 560 packagesDiscoveryProvider: findPackages, | 571 packagesDiscoveryProvider: findPackages, |
| 561 resolutionInputs: resolutionInputs, | 572 resolutionInputs: resolutionInputs, |
| 562 resolutionOutput: resolveOnly ? resolutionOutput : null, | 573 resolutionOutput: resolveOnly ? resolutionOutput : null, |
| 563 options: options, | 574 options: options, |
| 564 environment: environment); | 575 environment: environment); |
| 565 return compileFunc( | 576 return compileFunc( |
| 566 compilerOptions, inputProvider, diagnosticHandler, outputProvider) | 577 compilerOptions, inputProvider, diagnosticHandler, outputProvider) |
| 567 .then(compilationDone); | 578 .then(compilationDone); |
| 568 } | 579 } |
| 569 | 580 |
| 581 /// Returns the non-negative integer formatted with a thousands separator. |
| 582 String _formatCharacterCount(int value, [String separator = ',']) { |
| 583 String text = '$value'; |
| 584 // 'Insert' separators right-to-left. Inefficient, but used just a few times. |
| 585 for (int position = text.length - 3; position > 0; position -= 3) { |
| 586 text = text.substring(0, position) + separator + text.substring(position); |
| 587 } |
| 588 return text; |
| 589 } |
| 590 |
| 591 /// Formats [duration] in seconds in fixed-point format, preferring to keep the |
| 592 /// result at to below [width] characters. |
| 593 String _formatDurationAsSeconds(Duration duration, [int width = 4]) { |
| 594 num seconds = duration.inMilliseconds / 1000.0; |
| 595 String text; |
| 596 for (int digits = 3; digits >= 0; digits--) { |
| 597 text = seconds.toStringAsFixed(digits); |
| 598 if (text.length <= width) return text; |
| 599 } |
| 600 return text; |
| 601 } |
| 602 |
| 570 class AbortLeg { | 603 class AbortLeg { |
| 571 final message; | 604 final message; |
| 572 AbortLeg(this.message); | 605 AbortLeg(this.message); |
| 573 toString() => 'Aborted due to --throw-on-error: $message'; | 606 toString() => 'Aborted due to --throw-on-error: $message'; |
| 574 } | 607 } |
| 575 | 608 |
| 576 void writeString(Uri uri, String text) { | 609 void writeString(Uri uri, String text) { |
| 577 if (!enableWriteString) return; | 610 if (!enableWriteString) return; |
| 578 if (uri.scheme != 'file') { | 611 if (uri.scheme != 'file') { |
| 579 fail('Unhandled scheme ${uri.scheme}.'); | 612 fail('Unhandled scheme ${uri.scheme}.'); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 @override | 1071 @override |
| 1039 void add(String event) { | 1072 void add(String event) { |
| 1040 sb.write(event); | 1073 sb.write(event); |
| 1041 } | 1074 } |
| 1042 | 1075 |
| 1043 @override | 1076 @override |
| 1044 void close() { | 1077 void close() { |
| 1045 // Do nothing. | 1078 // Do nothing. |
| 1046 } | 1079 } |
| 1047 } | 1080 } |
| OLD | NEW |