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.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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 int exitCode; | 782 int exitCode; |
| 780 exitFunc = (errorCode) { | 783 exitFunc = (errorCode) { |
| 781 // Since we only throw another part of the compiler might intercept our | 784 // Since we only throw another part of the compiler might intercept our |
| 782 // exception and try to exit with a different code. | 785 // exception and try to exit with a different code. |
| 783 if (exitCode == 0) { | 786 if (exitCode == 0) { |
| 784 exitCode = errorCode; | 787 exitCode = errorCode; |
| 785 } | 788 } |
| 786 throw _EXIT_SIGNAL; | 789 throw _EXIT_SIGNAL; |
| 787 }; | 790 }; |
| 788 | 791 |
| 792 if (USE_SERIALIZED_DART_CORE) { | |
| 793 CompileFunc oldCompileFunc = compileFunc; | |
| 794 String serializedData; | |
| 795 Future<api.CompilationResult> _compileFunc(CompilerOptions compilerOptions, | |
| 796 api.CompilerInput compilerInput, | |
| 797 api.CompilerDiagnostics compilerDiagnostics, | |
| 798 api.CompilerOutput compilerOutput) async { | |
| 799 if (serializedData == null) { | |
|
Siggi Cherem (dart-lang)
2016/05/17 21:30:15
nit: consider adding a few functions at the end of
Johnni Winther
2016/05/18 11:00:07
Done.
| |
| 800 _CompilerOutput output = new _CompilerOutput(); | |
| 801 api.CompilationResult result = await oldCompileFunc( | |
| 802 new CompilerOptions.parse( | |
| 803 entryPoint: Uris.dart_core, | |
| 804 libraryRoot: compilerOptions.libraryRoot, | |
| 805 packageRoot: compilerOptions.packageRoot, | |
| 806 packageConfig: compilerOptions.packageConfig, | |
| 807 packagesDiscoveryProvider: | |
| 808 compilerOptions.packagesDiscoveryProvider, | |
| 809 environment: | |
| 810 compilerOptions.environment, | |
| 811 serializationTarget: Uri.parse('file:fake.data'), | |
| 812 options: [Flags.analyzeAll]), | |
| 813 compilerInput, | |
| 814 compilerDiagnostics, | |
| 815 output); | |
| 816 serializedData = output.serializedData; | |
| 817 } | |
| 818 CompilerImpl compiler = new CompilerImpl( | |
| 819 compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); | |
| 820 compiler.serialization.deserializeFromText(serializedData); | |
| 821 return compiler.run(compilerOptions.entryPoint).then((bool success) { | |
| 822 return new api.CompilationResult(compiler, isSuccess: success); | |
| 823 }); | |
| 824 } | |
| 825 compileFunc = _compileFunc; | |
| 826 } | |
| 827 | |
| 828 | |
| 789 var stream = stdin.transform(UTF8.decoder).transform(new LineSplitter()); | 829 var stream = stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
| 790 var subscription; | 830 var subscription; |
| 791 subscription = stream.listen((line) { | 831 subscription = stream.listen((line) { |
| 792 new Future.sync(() { | 832 new Future.sync(() { |
| 793 subscription.pause(); | 833 subscription.pause(); |
| 794 exitCode = 0; | 834 exitCode = 0; |
| 795 if (line == null) exit(0); | 835 if (line == null) exit(0); |
| 796 List<String> args = <String>[]; | 836 List<String> args = <String>[]; |
| 797 args.addAll(batchArguments); | 837 args.addAll(batchArguments); |
| 798 args.addAll(splitLine(line, windows: Platform.isWindows)); | 838 args.addAll(splitLine(line, windows: Platform.isWindows)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 809 } else if (exitCode == 253) { | 849 } else if (exitCode == 253) { |
| 810 print(">>> TEST CRASH"); | 850 print(">>> TEST CRASH"); |
| 811 } else { | 851 } else { |
| 812 print(">>> TEST FAIL"); | 852 print(">>> TEST FAIL"); |
| 813 } | 853 } |
| 814 stderr.writeln(">>> EOF STDERR"); | 854 stderr.writeln(">>> EOF STDERR"); |
| 815 subscription.resume(); | 855 subscription.resume(); |
| 816 }); | 856 }); |
| 817 }); | 857 }); |
| 818 } | 858 } |
| 859 | |
| 860 final bool USE_SERIALIZED_DART_CORE = | |
| 861 Platform.environment['USE_SERIALIZED_DART_CORE'] == 'true'; | |
| 862 | |
| 863 class _CompilerOutput extends NullCompilerOutput { | |
| 864 _BufferedEventSink sink; | |
| 865 | |
| 866 @override | |
| 867 EventSink<String> createEventSink(String name, String extension) { | |
| 868 if (name == '' && extension == 'data') { | |
| 869 return sink = new _BufferedEventSink(); | |
| 870 } | |
| 871 return super.createEventSink(name, extension); | |
| 872 } | |
| 873 | |
| 874 String get serializedData => sink.sb.toString(); | |
| 875 } | |
| 876 | |
| 877 class _BufferedEventSink implements EventSink<String> { | |
| 878 StringBuffer sb = new StringBuffer(); | |
| 879 | |
| 880 @override | |
| 881 void add(String event) { | |
| 882 sb.write(event); | |
| 883 } | |
| 884 | |
| 885 @override | |
| 886 void close() { | |
| 887 // Do nothing. | |
| 888 } | |
| 889 | |
| 890 @override | |
| 891 void addError(errorEvent, [StackTrace stackTrace]) { | |
| 892 // Ignore | |
| 893 } | |
| 894 } | |
| OLD | NEW |