| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 print('------------------------------------------------------------------'); | 120 print('------------------------------------------------------------------'); |
| 121 print('serialize dart:core'); | 121 print('serialize dart:core'); |
| 122 print('------------------------------------------------------------------'); | 122 print('------------------------------------------------------------------'); |
| 123 SerializedData serializedData; | 123 SerializedData serializedData; |
| 124 if (arguments.loadSerializedData) { | 124 if (arguments.loadSerializedData) { |
| 125 File file = new File(arguments.serializedDataFileName); | 125 File file = new File(arguments.serializedDataFileName); |
| 126 if (file.existsSync()) { | 126 if (file.existsSync()) { |
| 127 print('Loading data from $file'); | 127 print('Loading data from $file'); |
| 128 serializedData = new SerializedData(uri, file.readAsStringSync()); | 128 serializedData = new SerializedData(uri, file.readAsStringSync()); |
| 129 } | 129 } |
| 130 } else { |
| 131 SerializationResult result = await serialize(Uris.dart_core, uri); |
| 132 serializedData = result.serializedData; |
| 130 } | 133 } |
| 131 if (serializedData == null) { | 134 if (arguments.saveSerializedData) { |
| 132 Compiler compiler = compilerFor( | 135 File file = new File(arguments.serializedDataFileName); |
| 133 options: [Flags.analyzeAll]); | 136 print('Saving data to $file'); |
| 134 compiler.serialization.supportSerialization = true; | 137 file.writeAsStringSync(serializedData.data); |
| 135 await compiler.run(Uris.dart_core); | |
| 136 BufferedEventSink sink = new BufferedEventSink(); | |
| 137 compiler.serialization.serializeToSink( | |
| 138 sink, compiler.libraryLoader.libraries); | |
| 139 serializedData = new SerializedData(uri, sink.text); | |
| 140 if (arguments.saveSerializedData) { | |
| 141 File file = new File(arguments.serializedDataFileName); | |
| 142 print('Saving data to $file'); | |
| 143 file.writeAsStringSync(serializedData.data); | |
| 144 } | |
| 145 } | 138 } |
| 146 return serializedData; | 139 return serializedData; |
| 147 } | 140 } |
| 148 | 141 |
| 142 class SerializationResult { |
| 143 final Compiler compiler; |
| 144 final SerializedData serializedData; |
| 145 |
| 146 SerializationResult(this.compiler, this.serializedData); |
| 147 } |
| 148 |
| 149 Future<SerializationResult> serialize(Uri entryPoint, [Uri dataUri]) async { |
| 150 if (dataUri == null) { |
| 151 dataUri = Uri.parse('memory:${DEFAULT_DATA_FILE_NAME}'); |
| 152 } |
| 153 Compiler compiler = compilerFor(options: [Flags.analyzeAll]); |
| 154 compiler.serialization.supportSerialization = true; |
| 155 await compiler.run(entryPoint); |
| 156 BufferedEventSink sink = new BufferedEventSink(); |
| 157 compiler.serialization.serializeToSink( |
| 158 sink, compiler.libraryLoader.libraries); |
| 159 SerializedData serializedData = new SerializedData(dataUri, sink.text); |
| 160 return new SerializationResult(compiler, serializedData); |
| 161 } |
| 162 |
| 149 class SerializedData { | 163 class SerializedData { |
| 150 final Uri uri; | 164 final Uri uri; |
| 151 final String data; | 165 final String data; |
| 152 | 166 |
| 153 SerializedData(this.uri, this.data); | 167 SerializedData(this.uri, this.data); |
| 154 | 168 |
| 155 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { | 169 Map<String, String> toMemorySourceFiles([Map<String, String> input]) { |
| 156 Map<String, String> sourceFiles = <String, String>{}; | 170 Map<String, String> sourceFiles = <String, String>{}; |
| 157 if (input != null) { | 171 if (input != null) { |
| 158 sourceFiles.addAll(input); | 172 sourceFiles.addAll(input); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 await compiler.run(null); | 227 await compiler.run(null); |
| 214 List<LibraryElement> libraries = <LibraryElement>[]; | 228 List<LibraryElement> libraries = <LibraryElement>[]; |
| 215 for (Uri uri in uriList) { | 229 for (Uri uri in uriList) { |
| 216 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); | 230 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); |
| 217 } | 231 } |
| 218 SerializedData additionalSerializedData = | 232 SerializedData additionalSerializedData = |
| 219 new SerializedData(Uri.parse('memory:additional.data'), | 233 new SerializedData(Uri.parse('memory:additional.data'), |
| 220 extractSerializedData(compiler, libraries)); | 234 extractSerializedData(compiler, libraries)); |
| 221 return <SerializedData>[serializedData, additionalSerializedData]; | 235 return <SerializedData>[serializedData, additionalSerializedData]; |
| 222 } | 236 } |
| OLD | NEW |