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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 Future<List<SerializedData>> preserializeData( | 209 Future<List<SerializedData>> preserializeData( |
210 SerializedData serializedData, Test test) async { | 210 SerializedData serializedData, Test test) async { |
211 if (test == null || | 211 if (test == null || |
212 test.preserializedSourceFiles == null || | 212 test.preserializedSourceFiles == null || |
213 test.preserializedSourceFiles.isEmpty) { | 213 test.preserializedSourceFiles.isEmpty) { |
214 return <SerializedData>[serializedData]; | 214 return <SerializedData>[serializedData]; |
215 } | 215 } |
| 216 |
216 List<Uri> uriList = <Uri>[]; | 217 List<Uri> uriList = <Uri>[]; |
217 for (String key in test.preserializedSourceFiles.keys) { | 218 for (String key in test.preserializedSourceFiles.keys) { |
218 uriList.add(Uri.parse('memory:$key')); | 219 uriList.add(Uri.parse('memory:$key')); |
219 } | 220 } |
220 Map<String, String> sourceFiles = serializedData.toMemorySourceFiles(); | 221 Map<String, String> sourceFiles = serializedData.toMemorySourceFiles(); |
221 sourceFiles.addAll(test.preserializedSourceFiles); | 222 sourceFiles.addAll(test.preserializedSourceFiles); |
222 if (test.unserializedSourceFiles != null) { | 223 if (test.unserializedSourceFiles != null) { |
223 sourceFiles.addAll(test.unserializedSourceFiles); | 224 sourceFiles.addAll(test.unserializedSourceFiles); |
224 } | 225 } |
225 OutputCollector outputCollector = new OutputCollector(); | 226 Uri additionalDataUri = Uri.parse('memory:additional.data'); |
226 Compiler compiler = compilerFor( | 227 SerializedData additionalSerializedData; |
227 memorySourceFiles: sourceFiles, | 228 if (test.sourceFiles.isEmpty) { |
228 resolutionInputs: serializedData.toUris(), | 229 SerializationResult result = await serialize( |
229 options: [Flags.resolveOnly], | 230 uriList.first, |
230 outputProvider: outputCollector); | 231 memorySourceFiles: sourceFiles, |
231 compiler.librariesToAnalyzeWhenRun = uriList; | 232 resolutionInputs: serializedData.toUris(), |
232 await compiler.run(null); | 233 dataUri: additionalDataUri); |
233 List<LibraryElement> libraries = <LibraryElement>[]; | 234 additionalSerializedData = result.serializedData; |
234 for (Uri uri in uriList) { | 235 } else { |
235 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); | 236 OutputCollector outputCollector = new OutputCollector(); |
| 237 Compiler compiler = compilerFor( |
| 238 entryPoint: test.sourceFiles.isEmpty ? uriList.first : null, |
| 239 memorySourceFiles: sourceFiles, |
| 240 resolutionInputs: serializedData.toUris(), |
| 241 options: [Flags.resolveOnly], |
| 242 outputProvider: outputCollector); |
| 243 compiler.librariesToAnalyzeWhenRun = uriList; |
| 244 await compiler.run(null); |
| 245 List<LibraryElement> libraries = <LibraryElement>[]; |
| 246 for (Uri uri in uriList) { |
| 247 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); |
| 248 } |
| 249 additionalSerializedData = new SerializedData( |
| 250 additionalDataUri, |
| 251 outputCollector.getOutput('', 'data')); |
236 } | 252 } |
237 SerializedData additionalSerializedData = new SerializedData( | |
238 Uri.parse('memory:additional.data'), | |
239 outputCollector.getOutput('', 'data')); | |
240 return <SerializedData>[serializedData, additionalSerializedData]; | 253 return <SerializedData>[serializedData, additionalSerializedData]; |
241 } | 254 } |
242 | 255 |
243 class MeasurementResult { | 256 class MeasurementResult { |
244 final String title; | 257 final String title; |
245 final String taskTitle; | 258 final String taskTitle; |
246 final int elapsedMilliseconds; | 259 final int elapsedMilliseconds; |
247 | 260 |
248 MeasurementResult(this.title, this.taskTitle, this.elapsedMilliseconds); | 261 MeasurementResult(this.title, this.taskTitle, this.elapsedMilliseconds); |
249 } | 262 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 print('$taskTitle: $title'); | 301 print('$taskTitle: $title'); |
289 print('----------------------------------------------------------------'); | 302 print('----------------------------------------------------------------'); |
290 var result = await task(); | 303 var result = await task(); |
291 stopwatch.stop(); | 304 stopwatch.stop(); |
292 int elapsedMilliseconds = stopwatch.elapsedMilliseconds; | 305 int elapsedMilliseconds = stopwatch.elapsedMilliseconds; |
293 print('$taskTitle: $title: ${elapsedMilliseconds}ms'); | 306 print('$taskTitle: $title: ${elapsedMilliseconds}ms'); |
294 measurementResults.add( | 307 measurementResults.add( |
295 new MeasurementResult(title, taskTitle, elapsedMilliseconds)); | 308 new MeasurementResult(title, taskTitle, elapsedMilliseconds)); |
296 return result; | 309 return result; |
297 } | 310 } |
OLD | NEW |