| 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 = 'build number could not be determined'; |
| 32 |
| 33 /** |
| 34 * Allows wrapping scripts to explicitly provide the options passed to the |
| 35 * program instead of using the standard dart:io. |
| 36 */ |
| 37 Options OPTIONS_OVERRIDE = null; |
| 38 |
| 23 typedef void HandleOption(String option); | 39 typedef void HandleOption(String option); |
| 24 | 40 |
| 25 class OptionHandler { | 41 class OptionHandler { |
| 26 String pattern; | 42 String pattern; |
| 27 HandleOption handle; | 43 HandleOption handle; |
| 28 | 44 |
| 29 OptionHandler(this.pattern, this.handle); | 45 OptionHandler(this.pattern, this.handle); |
| 30 } | 46 } |
| 31 | 47 |
| 32 /** | 48 /** |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 if (isPrimaryOutput) { | 320 if (isPrimaryOutput) { |
| 305 charactersWritten += sink.count; | 321 charactersWritten += sink.count; |
| 306 } | 322 } |
| 307 } | 323 } |
| 308 | 324 |
| 309 var controller = new StreamController<String>(); | 325 var controller = new StreamController<String>(); |
| 310 controller.stream.listen(output.write, onDone: onDone); | 326 controller.stream.listen(output.write, onDone: onDone); |
| 311 sink = new CountingSink(controller); | 327 sink = new CountingSink(controller); |
| 312 return sink; | 328 return sink; |
| 313 } | 329 } |
| 314 | 330 |
| 315 api.compile(uri, libraryRoot, packageRoot, | 331 api.compile(uri, libraryRoot, packageRoot, |
| 316 inputProvider.readStringFromUri, handler, | 332 inputProvider.readStringFromUri, handler, |
| 317 options, outputProvider) | 333 options, outputProvider) |
| 318 .then(compilationDone); | 334 .then(compilationDone); |
| 319 } | 335 } |
| 320 | 336 |
| 321 // TODO(ahe): Get rid of this class if http://dartbug.com/8118 is fixed. | 337 // TODO(ahe): Get rid of this class if http://dartbug.com/8118 is fixed. |
| 322 class CountingSink implements EventSink<String> { | 338 class CountingSink implements EventSink<String> { |
| 323 final EventSink<String> sink; | 339 final EventSink<String> sink; |
| 324 int count = 0; | 340 int count = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 351 } | 367 } |
| 352 | 368 |
| 353 void fail(String message) { | 369 void fail(String message) { |
| 354 print(message); | 370 print(message); |
| 355 exit(1); | 371 exit(1); |
| 356 } | 372 } |
| 357 | 373 |
| 358 void compilerMain(Options options) { | 374 void compilerMain(Options options) { |
| 359 var root = uriPathToNative("/$LIBRARY_ROOT"); | 375 var root = uriPathToNative("/$LIBRARY_ROOT"); |
| 360 List<String> argv = ['--library-root=${options.script}$root']; | 376 List<String> argv = ['--library-root=${options.script}$root']; |
| 377 if (OPTIONS_OVERRIDE != null) options = OPTIONS_OVERRIDE; |
| 361 argv.addAll(options.arguments); | 378 argv.addAll(options.arguments); |
| 362 compile(argv); | 379 compile(argv); |
| 363 } | 380 } |
| 364 | 381 |
| 365 void help() { | 382 void help() { |
| 366 // This message should be no longer than 20 lines. The default | 383 // This message should be no longer than 20 lines. The default |
| 367 // terminal size normally 80x24. Two lines are used for the prompts | 384 // terminal size normally 80x24. Two lines are used for the prompts |
| 368 // before and after running the compiler. Another two lines may be | 385 // before and after running the compiler. Another two lines may be |
| 369 // used to print an error message. | 386 // used to print an error message. |
| 370 print(''' | 387 print(''' |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } catch (ignored) { | 512 } catch (ignored) { |
| 496 print('Internal error: error while printing exception'); | 513 print('Internal error: error while printing exception'); |
| 497 } | 514 } |
| 498 try { | 515 try { |
| 499 print(trace); | 516 print(trace); |
| 500 } finally { | 517 } finally { |
| 501 exit(253); // 253 is recognized as a crash by our test scripts. | 518 exit(253); // 253 is recognized as a crash by our test scripts. |
| 502 } | 519 } |
| 503 } | 520 } |
| 504 } | 521 } |
| OLD | NEW |