OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.serialization_helper; | 5 library dart2js.serialization_helper; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 SerializationResult(this.compiler, this.serializedData); | 146 SerializationResult(this.compiler, this.serializedData); |
147 } | 147 } |
148 | 148 |
149 Future<SerializationResult> serialize(Uri entryPoint, | 149 Future<SerializationResult> serialize(Uri entryPoint, |
150 {Map<String, String> memorySourceFiles: const <String, String>{}, | 150 {Map<String, String> memorySourceFiles: const <String, String>{}, |
151 List<Uri> resolutionInputs: const <Uri>[], | 151 List<Uri> resolutionInputs: const <Uri>[], |
152 Uri dataUri}) async { | 152 Uri dataUri}) async { |
153 if (dataUri == null) { | 153 if (dataUri == null) { |
154 dataUri = Uri.parse('memory:${DEFAULT_DATA_FILE_NAME}'); | 154 dataUri = Uri.parse('memory:${DEFAULT_DATA_FILE_NAME}'); |
155 } | 155 } |
| 156 OutputCollector outputCollector = new OutputCollector(); |
156 Compiler compiler = compilerFor( | 157 Compiler compiler = compilerFor( |
157 options: [Flags.analyzeAll], | 158 options: [Flags.resolveOnly], |
158 memorySourceFiles: memorySourceFiles, | 159 memorySourceFiles: memorySourceFiles, |
159 resolutionInputs: resolutionInputs); | 160 resolutionInputs: resolutionInputs, |
160 compiler.serialization.supportSerialization = true; | 161 outputProvider: outputCollector); |
161 await compiler.run(entryPoint); | 162 await compiler.run(entryPoint); |
162 BufferedEventSink sink = new BufferedEventSink(); | 163 SerializedData serializedData = new SerializedData( |
163 compiler.serialization.serializeToSink( | 164 dataUri, outputCollector.getOutput('', 'data')); |
164 sink, compiler.libraryLoader.libraries); | |
165 SerializedData serializedData = new SerializedData(dataUri, sink.text); | |
166 return new SerializationResult(compiler, serializedData); | 165 return new SerializationResult(compiler, serializedData); |
167 } | 166 } |
168 | 167 |
169 class SerializedData { | 168 class SerializedData { |
170 final Uri uri; | 169 final Uri uri; |
171 final String data; | 170 final String data; |
172 | 171 |
173 SerializedData(this.uri, this.data); | 172 SerializedData(this.uri, this.data); |
174 | 173 |
175 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { | 174 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 await compiler.run(null); | 232 await compiler.run(null); |
234 List<LibraryElement> libraries = <LibraryElement>[]; | 233 List<LibraryElement> libraries = <LibraryElement>[]; |
235 for (Uri uri in uriList) { | 234 for (Uri uri in uriList) { |
236 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); | 235 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); |
237 } | 236 } |
238 SerializedData additionalSerializedData = | 237 SerializedData additionalSerializedData = |
239 new SerializedData(Uri.parse('memory:additional.data'), | 238 new SerializedData(Uri.parse('memory:additional.data'), |
240 extractSerializedData(compiler, libraries)); | 239 extractSerializedData(compiler, libraries)); |
241 return <SerializedData>[serializedData, additionalSerializedData]; | 240 return <SerializedData>[serializedData, additionalSerializedData]; |
242 } | 241 } |
OLD | NEW |