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; | 5 library dart2js; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection' show Queue, LinkedHashMap; | 8 import 'dart:collection' show Queue, LinkedHashMap; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| 11 import 'dart:utf'; | 11 import 'dart:utf'; |
| 12 | 12 |
| 13 import '../compiler.dart' as api; | 13 import '../compiler.dart' as api; |
| 14 import 'source_file.dart'; | 14 import 'source_file.dart'; |
| 15 import 'source_file_provider.dart'; | 15 import 'source_file_provider.dart'; |
| 16 import 'filenames.dart'; | 16 import 'filenames.dart'; |
| 17 import 'util/uri_extras.dart'; | 17 import 'util/uri_extras.dart'; |
| 18 import '../../libraries.dart'; | 18 import '../../libraries.dart'; |
| 19 | 19 |
| 20 const String LIBRARY_ROOT = '../../../../..'; | 20 const String LIBRARY_ROOT = '../../../../..'; |
| 21 const String OUTPUT_LANGUAGE_DART = 'Dart'; | 21 const String OUTPUT_LANGUAGE_DART = 'Dart'; |
| 22 | 22 |
| 23 /** | |
| 24 * A string to identify the revision or build. | |
| 25 * | |
| 26 * This ID is displayed if the compiler crashes and in verbose mode, and is | |
| 27 * an aid in reproducing bug reports. | |
| 28 * | |
| 29 * The actual string is rewritten by a wrapper script when included in the sdk. | |
| 30 */ | |
| 31 String BUILD_ID = null; | |
| 32 | |
| 33 | |
|
ahe
2013/04/10 14:50:08
Extra line.
| |
| 23 typedef void HandleOption(String option); | 34 typedef void HandleOption(String option); |
| 24 | 35 |
| 25 class OptionHandler { | 36 class OptionHandler { |
| 26 String pattern; | 37 String pattern; |
| 27 HandleOption handle; | 38 HandleOption handle; |
| 28 | 39 |
| 29 OptionHandler(this.pattern, this.handle); | 40 OptionHandler(this.pattern, this.handle); |
| 30 } | 41 } |
| 31 | 42 |
| 32 /** | 43 /** |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 bool wantHelp = false; | 91 bool wantHelp = false; |
| 81 String outputLanguage = 'JavaScript'; | 92 String outputLanguage = 'JavaScript'; |
| 82 bool stripArgumentSet = false; | 93 bool stripArgumentSet = false; |
| 83 bool analyzeOnly = false; | 94 bool analyzeOnly = false; |
| 84 SourceFileProvider inputProvider = new SourceFileProvider(); | 95 SourceFileProvider inputProvider = new SourceFileProvider(); |
| 85 FormattingDiagnosticHandler diagnosticHandler = | 96 FormattingDiagnosticHandler diagnosticHandler = |
| 86 new FormattingDiagnosticHandler(inputProvider); | 97 new FormattingDiagnosticHandler(inputProvider); |
| 87 | 98 |
| 88 passThrough(String argument) => options.add(argument); | 99 passThrough(String argument) => options.add(argument); |
| 89 | 100 |
| 101 if (BUILD_ID != null) { | |
| 102 passThrough("--build-id=$BUILD_ID"); | |
| 103 } | |
| 104 | |
| 90 setLibraryRoot(String argument) { | 105 setLibraryRoot(String argument) { |
| 91 libraryRoot = cwd.resolve(extractPath(argument)); | 106 libraryRoot = cwd.resolve(extractPath(argument)); |
| 92 } | 107 } |
| 93 | 108 |
| 94 setPackageRoot(String argument) { | 109 setPackageRoot(String argument) { |
| 95 packageRoot = cwd.resolve(extractPath(argument)); | 110 packageRoot = cwd.resolve(extractPath(argument)); |
| 96 } | 111 } |
| 97 | 112 |
| 98 setOutput(String argument) { | 113 setOutput(String argument) { |
| 99 explicitOut = true; | 114 explicitOut = true; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 if (isPrimaryOutput) { | 319 if (isPrimaryOutput) { |
| 305 charactersWritten += sink.count; | 320 charactersWritten += sink.count; |
| 306 } | 321 } |
| 307 } | 322 } |
| 308 | 323 |
| 309 var controller = new StreamController<String>(); | 324 var controller = new StreamController<String>(); |
| 310 controller.stream.listen(output.write, onDone: onDone); | 325 controller.stream.listen(output.write, onDone: onDone); |
| 311 sink = new CountingSink(controller); | 326 sink = new CountingSink(controller); |
| 312 return sink; | 327 return sink; |
| 313 } | 328 } |
| 314 | 329 |
|
ahe
2013/04/10 14:50:08
Extra space.
ricow1
2013/04/11 05:45:12
Done.
| |
| 315 api.compile(uri, libraryRoot, packageRoot, | 330 api.compile(uri, libraryRoot, packageRoot, |
| 316 inputProvider.readStringFromUri, handler, | 331 inputProvider.readStringFromUri, handler, |
| 317 options, outputProvider) | 332 options, outputProvider) |
| 318 .then(compilationDone); | 333 .then(compilationDone); |
| 319 } | 334 } |
| 320 | 335 |
| 321 // TODO(ahe): Get rid of this class if http://dartbug.com/8118 is fixed. | 336 // TODO(ahe): Get rid of this class if http://dartbug.com/8118 is fixed. |
| 322 class CountingSink implements EventSink<String> { | 337 class CountingSink implements EventSink<String> { |
| 323 final EventSink<String> sink; | 338 final EventSink<String> sink; |
| 324 int count = 0; | 339 int count = 0; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 } | 494 } |
| 480 exit(0); | 495 exit(0); |
| 481 } | 496 } |
| 482 | 497 |
| 483 void helpAndFail(String message) { | 498 void helpAndFail(String message) { |
| 484 help(); | 499 help(); |
| 485 print(''); | 500 print(''); |
| 486 fail(message); | 501 fail(message); |
| 487 } | 502 } |
| 488 | 503 |
| 489 void main() { | 504 void mainWithErrorHandler(Options options) { |
| 490 try { | 505 try { |
| 491 compilerMain(new Options()); | 506 compilerMain(options); |
| 492 } catch (exception, trace) { | 507 } catch (exception, trace) { |
| 493 try { | 508 try { |
| 494 print('Internal error: $exception'); | 509 print('Internal error: $exception'); |
| 495 } catch (ignored) { | 510 } catch (ignored) { |
| 496 print('Internal error: error while printing exception'); | 511 print('Internal error: error while printing exception'); |
| 497 } | 512 } |
| 498 try { | 513 try { |
| 499 print(trace); | 514 print(trace); |
| 500 } finally { | 515 } finally { |
| 501 exit(253); // 253 is recognized as a crash by our test scripts. | 516 exit(253); // 253 is recognized as a crash by our test scripts. |
| 502 } | 517 } |
| 503 } | 518 } |
| 504 } | 519 } |
| 520 | |
|
ahe
2013/04/10 14:50:08
Extra line.
ricow1
2013/04/11 05:45:12
Done.
| |
| 521 | |
| 522 void main() { | |
| 523 mainWithErrorHandler(new Options()); | |
| 524 } | |
| OLD | NEW |