| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 await compiler.run(entryPoint); | 162 await compiler.run(entryPoint); |
| 163 SerializedData serializedData = new SerializedData( | 163 SerializedData serializedData = new SerializedData( |
| 164 dataUri, outputCollector.getOutput('', 'data')); | 164 dataUri, outputCollector.getOutput('', 'data')); |
| 165 return new SerializationResult(compiler, serializedData); | 165 return new SerializationResult(compiler, serializedData); |
| 166 } | 166 } |
| 167 | 167 |
| 168 class SerializedData { | 168 class SerializedData { |
| 169 final Uri uri; | 169 final Uri uri; |
| 170 final String data; | 170 final String data; |
| 171 | 171 |
| 172 SerializedData(this.uri, this.data); | 172 SerializedData(this.uri, this.data) { |
| 173 assert(uri != null); |
| 174 assert(data != null); |
| 175 } |
| 173 | 176 |
| 174 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { | 177 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { |
| 175 Map<String, String> sourceFiles = <String, String>{}; | 178 Map<String, String> sourceFiles = <String, String>{}; |
| 176 if (input != null) { | 179 if (input != null) { |
| 177 sourceFiles.addAll(input); | 180 sourceFiles.addAll(input); |
| 178 } | 181 } |
| 179 expandMemorySourceFiles(sourceFiles); | 182 expandMemorySourceFiles(sourceFiles); |
| 180 return sourceFiles; | 183 return sourceFiles; |
| 181 } | 184 } |
| 182 | 185 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 193 } | 196 } |
| 194 expandUris(uris); | 197 expandUris(uris); |
| 195 return uris; | 198 return uris; |
| 196 } | 199 } |
| 197 | 200 |
| 198 void expandUris(List<Uri> uris) { | 201 void expandUris(List<Uri> uris) { |
| 199 uris.add(uri); | 202 uris.add(uri); |
| 200 } | 203 } |
| 201 } | 204 } |
| 202 | 205 |
| 203 String extractSerializedData( | |
| 204 Compiler compiler, Iterable<LibraryElement> libraries) { | |
| 205 BufferedEventSink sink = new BufferedEventSink(); | |
| 206 compiler.serialization.serializeToSink(sink, libraries); | |
| 207 return sink.text; | |
| 208 } | |
| 209 | |
| 210 Future<List<SerializedData>> preserializeData( | 206 Future<List<SerializedData>> preserializeData( |
| 211 SerializedData serializedData, Test test) async { | 207 SerializedData serializedData, Test test) async { |
| 212 if (test == null || | 208 if (test == null || |
| 213 test.preserializedSourceFiles == null || | 209 test.preserializedSourceFiles == null || |
| 214 test.preserializedSourceFiles.isEmpty) { | 210 test.preserializedSourceFiles.isEmpty) { |
| 215 return <SerializedData>[serializedData]; | 211 return <SerializedData>[serializedData]; |
| 216 } | 212 } |
| 217 List<Uri> uriList = <Uri>[]; | 213 List<Uri> uriList = <Uri>[]; |
| 218 for (String key in test.preserializedSourceFiles.keys) { | 214 for (String key in test.preserializedSourceFiles.keys) { |
| 219 uriList.add(Uri.parse('memory:$key')); | 215 uriList.add(Uri.parse('memory:$key')); |
| 220 } | 216 } |
| 221 Map<String, String> sourceFiles = serializedData.toMemorySourceFiles(); | 217 Map<String, String> sourceFiles = serializedData.toMemorySourceFiles(); |
| 222 sourceFiles.addAll(test.preserializedSourceFiles); | 218 sourceFiles.addAll(test.preserializedSourceFiles); |
| 223 if (test.unserializedSourceFiles != null) { | 219 if (test.unserializedSourceFiles != null) { |
| 224 sourceFiles.addAll(test.unserializedSourceFiles); | 220 sourceFiles.addAll(test.unserializedSourceFiles); |
| 225 } | 221 } |
| 222 OutputCollector outputCollector = new OutputCollector(); |
| 226 Compiler compiler = compilerFor( | 223 Compiler compiler = compilerFor( |
| 227 memorySourceFiles: sourceFiles, | 224 memorySourceFiles: sourceFiles, |
| 228 resolutionInputs: serializedData.toUris(), | 225 resolutionInputs: serializedData.toUris(), |
| 229 options: [Flags.analyzeOnly, Flags.analyzeMain]); | 226 options: [Flags.resolveOnly], |
| 227 outputProvider: outputCollector); |
| 230 compiler.librariesToAnalyzeWhenRun = uriList; | 228 compiler.librariesToAnalyzeWhenRun = uriList; |
| 231 compiler.serialization.supportSerialization = true; | |
| 232 await compiler.run(null); | 229 await compiler.run(null); |
| 233 List<LibraryElement> libraries = <LibraryElement>[]; | 230 List<LibraryElement> libraries = <LibraryElement>[]; |
| 234 for (Uri uri in uriList) { | 231 for (Uri uri in uriList) { |
| 235 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); | 232 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); |
| 236 } | 233 } |
| 237 SerializedData additionalSerializedData = | 234 SerializedData additionalSerializedData = new SerializedData( |
| 238 new SerializedData(Uri.parse('memory:additional.data'), | 235 Uri.parse('memory:additional.data'), |
| 239 extractSerializedData(compiler, libraries)); | 236 outputCollector.getOutput('', 'data')); |
| 240 return <SerializedData>[serializedData, additionalSerializedData]; | 237 return <SerializedData>[serializedData, additionalSerializedData]; |
| 241 } | 238 } |
| OLD | NEW |