Chromium Code Reviews| Index: pkg/compiler/lib/src/dart2js.dart |
| diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart |
| index fc6fda6446496f08e1203f6d66ac62e91c62c598..ed90edc1e92a0543e19d5eaf788ac8462f1ccfb5 100644 |
| --- a/pkg/compiler/lib/src/dart2js.dart |
| +++ b/pkg/compiler/lib/src/dart2js.dart |
| @@ -4,16 +4,19 @@ |
| library dart2js.cmdline; |
| -import 'dart:async' show Future; |
| +import 'dart:async' show EventSink, Future; |
| import 'dart:convert' show UTF8, LineSplitter; |
| import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; |
| import 'package:package_config/discovery.dart' show findPackages; |
| import '../compiler_new.dart' as api; |
| +import 'apiimpl.dart'; |
| +import 'common/names.dart' show Uris; |
| import 'commandline_options.dart'; |
| import 'filenames.dart'; |
| import 'io/source_file.dart'; |
| +import 'null_compiler_output.dart'; |
| import 'options.dart' show CompilerOptions; |
| import 'source_file_provider.dart'; |
| import 'util/command_line.dart'; |
| @@ -786,6 +789,43 @@ void batchMain(List<String> batchArguments) { |
| throw _EXIT_SIGNAL; |
| }; |
| + if (USE_SERIALIZED_DART_CORE) { |
| + CompileFunc oldCompileFunc = compileFunc; |
| + String serializedData; |
| + Future<api.CompilationResult> _compileFunc(CompilerOptions compilerOptions, |
| + api.CompilerInput compilerInput, |
| + api.CompilerDiagnostics compilerDiagnostics, |
| + api.CompilerOutput compilerOutput) async { |
| + 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.
|
| + _CompilerOutput output = new _CompilerOutput(); |
| + api.CompilationResult result = await oldCompileFunc( |
| + new CompilerOptions.parse( |
| + entryPoint: Uris.dart_core, |
| + libraryRoot: compilerOptions.libraryRoot, |
| + packageRoot: compilerOptions.packageRoot, |
| + packageConfig: compilerOptions.packageConfig, |
| + packagesDiscoveryProvider: |
| + compilerOptions.packagesDiscoveryProvider, |
| + environment: |
| + compilerOptions.environment, |
| + serializationTarget: Uri.parse('file:fake.data'), |
| + options: [Flags.analyzeAll]), |
| + compilerInput, |
| + compilerDiagnostics, |
| + output); |
| + serializedData = output.serializedData; |
| + } |
| + CompilerImpl compiler = new CompilerImpl( |
| + compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); |
| + compiler.serialization.deserializeFromText(serializedData); |
| + return compiler.run(compilerOptions.entryPoint).then((bool success) { |
| + return new api.CompilationResult(compiler, isSuccess: success); |
| + }); |
| + } |
| + compileFunc = _compileFunc; |
| + } |
| + |
| + |
| var stream = stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
| var subscription; |
| subscription = stream.listen((line) { |
| @@ -816,3 +856,39 @@ void batchMain(List<String> batchArguments) { |
| }); |
| }); |
| } |
| + |
| +final bool USE_SERIALIZED_DART_CORE = |
| + Platform.environment['USE_SERIALIZED_DART_CORE'] == 'true'; |
| + |
| +class _CompilerOutput extends NullCompilerOutput { |
| + _BufferedEventSink sink; |
| + |
| + @override |
| + EventSink<String> createEventSink(String name, String extension) { |
| + if (name == '' && extension == 'data') { |
| + return sink = new _BufferedEventSink(); |
| + } |
| + return super.createEventSink(name, extension); |
| + } |
| + |
| + String get serializedData => sink.sb.toString(); |
| +} |
| + |
| +class _BufferedEventSink implements EventSink<String> { |
| + StringBuffer sb = new StringBuffer(); |
| + |
| + @override |
| + void add(String event) { |
| + sb.write(event); |
| + } |
| + |
| + @override |
| + void close() { |
| + // Do nothing. |
| + } |
| + |
| + @override |
| + void addError(errorEvent, [StackTrace stackTrace]) { |
| + // Ignore |
| + } |
| +} |