| 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 EventSink, 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 |
| 11 import 'package:package_config/discovery.dart' show findPackages; | 11 import 'package:package_config/discovery.dart' show findPackages; |
| 12 | 12 |
| 13 import '../compiler_new.dart' as api; | 13 import '../compiler_new.dart' as api; |
| 14 import 'apiimpl.dart'; |
| 15 import 'common/names.dart' show Uris; |
| 14 import 'commandline_options.dart'; | 16 import 'commandline_options.dart'; |
| 15 import 'filenames.dart'; | 17 import 'filenames.dart'; |
| 16 import 'io/source_file.dart'; | 18 import 'io/source_file.dart'; |
| 19 import 'null_compiler_output.dart'; |
| 17 import 'options.dart' show CompilerOptions; | 20 import 'options.dart' show CompilerOptions; |
| 18 import 'source_file_provider.dart'; | 21 import 'source_file_provider.dart'; |
| 19 import 'util/command_line.dart'; | 22 import 'util/command_line.dart'; |
| 20 import 'util/uri_extras.dart'; | 23 import 'util/uri_extras.dart'; |
| 21 import 'util/util.dart' show stackTraceFilePrefix; | 24 import 'util/util.dart' show stackTraceFilePrefix; |
| 22 | 25 |
| 23 const String LIBRARY_ROOT = '../../../../../sdk'; | 26 const String LIBRARY_ROOT = '../../../../../sdk'; |
| 24 const String OUTPUT_LANGUAGE_DART = 'Dart'; | 27 const String OUTPUT_LANGUAGE_DART = 'Dart'; |
| 25 | 28 |
| 26 /** | 29 /** |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 int exitCode; | 789 int exitCode; |
| 787 exitFunc = (errorCode) { | 790 exitFunc = (errorCode) { |
| 788 // Since we only throw another part of the compiler might intercept our | 791 // Since we only throw another part of the compiler might intercept our |
| 789 // exception and try to exit with a different code. | 792 // exception and try to exit with a different code. |
| 790 if (exitCode == 0) { | 793 if (exitCode == 0) { |
| 791 exitCode = errorCode; | 794 exitCode = errorCode; |
| 792 } | 795 } |
| 793 throw _EXIT_SIGNAL; | 796 throw _EXIT_SIGNAL; |
| 794 }; | 797 }; |
| 795 | 798 |
| 799 if (USE_SERIALIZED_DART_CORE) { |
| 800 _useSerializedDataForDartCore(compileFunc); |
| 801 } |
| 802 |
| 796 var stream = stdin.transform(UTF8.decoder).transform(new LineSplitter()); | 803 var stream = stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
| 797 var subscription; | 804 var subscription; |
| 798 subscription = stream.listen((line) { | 805 subscription = stream.listen((line) { |
| 799 new Future.sync(() { | 806 new Future.sync(() { |
| 800 subscription.pause(); | 807 subscription.pause(); |
| 801 exitCode = 0; | 808 exitCode = 0; |
| 802 if (line == null) exit(0); | 809 if (line == null) exit(0); |
| 803 List<String> args = <String>[]; | 810 List<String> args = <String>[]; |
| 804 args.addAll(batchArguments); | 811 args.addAll(batchArguments); |
| 805 args.addAll(splitLine(line, windows: Platform.isWindows)); | 812 args.addAll(splitLine(line, windows: Platform.isWindows)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 816 } else if (exitCode == 253) { | 823 } else if (exitCode == 253) { |
| 817 print(">>> TEST CRASH"); | 824 print(">>> TEST CRASH"); |
| 818 } else { | 825 } else { |
| 819 print(">>> TEST FAIL"); | 826 print(">>> TEST FAIL"); |
| 820 } | 827 } |
| 821 stderr.writeln(">>> EOF STDERR"); | 828 stderr.writeln(">>> EOF STDERR"); |
| 822 subscription.resume(); | 829 subscription.resume(); |
| 823 }); | 830 }); |
| 824 }); | 831 }); |
| 825 } | 832 } |
| 833 |
| 834 final bool USE_SERIALIZED_DART_CORE = |
| 835 Platform.environment['USE_SERIALIZED_DART_CORE'] == 'true'; |
| 836 |
| 837 void _useSerializedDataForDartCore(CompileFunc oldCompileFunc) { |
| 838 String serializedData; |
| 839 |
| 840 Future<api.CompilationResult> compileWithSerializedData( |
| 841 CompilerOptions compilerOptions, |
| 842 api.CompilerInput compilerInput, |
| 843 api.CompilerDiagnostics compilerDiagnostics, |
| 844 api.CompilerOutput compilerOutput) async { |
| 845 CompilerImpl compiler = new CompilerImpl( |
| 846 compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); |
| 847 compiler.serialization.deserializeFromText(serializedData); |
| 848 return compiler.run(compilerOptions.entryPoint).then((bool success) { |
| 849 return new api.CompilationResult(compiler, isSuccess: success); |
| 850 }); |
| 851 } |
| 852 |
| 853 Future<api.CompilationResult> generateSerializedDataForDartCore( |
| 854 CompilerOptions compilerOptions, |
| 855 api.CompilerInput compilerInput, |
| 856 api.CompilerDiagnostics compilerDiagnostics, |
| 857 api.CompilerOutput compilerOutput) async { |
| 858 _CompilerOutput output = new _CompilerOutput(); |
| 859 api.CompilationResult result = await oldCompileFunc( |
| 860 new CompilerOptions.parse( |
| 861 entryPoint: Uris.dart_core, |
| 862 libraryRoot: compilerOptions.libraryRoot, |
| 863 packageRoot: compilerOptions.packageRoot, |
| 864 packageConfig: compilerOptions.packageConfig, |
| 865 packagesDiscoveryProvider: |
| 866 compilerOptions.packagesDiscoveryProvider, |
| 867 environment: compilerOptions.environment, |
| 868 resolutionOutput: Uri.parse('file:fake.data'), |
| 869 options: [Flags.resolveOnly]), |
| 870 compilerInput, |
| 871 compilerDiagnostics, |
| 872 output); |
| 873 serializedData = output.serializedData; |
| 874 compileFunc = compileWithSerializedData; |
| 875 return compileWithSerializedData( |
| 876 compilerOptions, compilerInput, compilerDiagnostics, compilerOutput); |
| 877 } |
| 878 |
| 879 compileFunc = generateSerializedDataForDartCore; |
| 880 } |
| 881 |
| 882 class _CompilerOutput extends NullCompilerOutput { |
| 883 _BufferedEventSink sink; |
| 884 |
| 885 @override |
| 886 EventSink<String> createEventSink(String name, String extension) { |
| 887 if (name == '' && extension == 'data') { |
| 888 return sink = new _BufferedEventSink(); |
| 889 } |
| 890 return super.createEventSink(name, extension); |
| 891 } |
| 892 |
| 893 String get serializedData => sink.sb.toString(); |
| 894 } |
| 895 |
| 896 class _BufferedEventSink implements EventSink<String> { |
| 897 StringBuffer sb = new StringBuffer(); |
| 898 |
| 899 @override |
| 900 void add(String event) { |
| 901 sb.write(event); |
| 902 } |
| 903 |
| 904 @override |
| 905 void close() { |
| 906 // Do nothing. |
| 907 } |
| 908 |
| 909 @override |
| 910 void addError(errorEvent, [StackTrace stackTrace]) { |
| 911 // Ignore |
| 912 } |
| 913 } |
| OLD | NEW |