| 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'; |
| 11 import 'package:compiler/src/common/names.dart'; | 11 import 'package:compiler/src/common/names.dart'; |
| 12 import 'package:compiler/src/compiler.dart'; | 12 import 'package:compiler/src/compiler.dart'; |
| 13 import 'package:compiler/src/elements/elements.dart'; |
| 13 | 14 |
| 14 import '../memory_compiler.dart'; | 15 import '../memory_compiler.dart'; |
| 15 import 'test_data.dart'; | 16 import 'test_data.dart'; |
| 16 | 17 |
| 17 const String DEFAULT_DATA_FILE_NAME = 'out.data'; | 18 const String DEFAULT_DATA_FILE_NAME = 'out.data'; |
| 18 | 19 |
| 19 class Arguments { | 20 class Arguments { |
| 20 final String filename; | 21 final String filename; |
| 21 final int start; | 22 final int start; |
| 22 final int end; | 23 final int end; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 return new Arguments( | 65 return new Arguments( |
| 65 filename: filename, | 66 filename: filename, |
| 66 start: start, | 67 start: start, |
| 67 end: end, | 68 end: end, |
| 68 verbose: verbose, | 69 verbose: verbose, |
| 69 loadSerializedData: loadSerializedData, | 70 loadSerializedData: loadSerializedData, |
| 70 saveSerializedData: saveSerializedData); | 71 saveSerializedData: saveSerializedData); |
| 71 } | 72 } |
| 72 | 73 |
| 73 Future forEachTest(List<Test> tests, Future f(int index, Test test)) async { | 74 Future forEachTest( |
| 75 SerializedData serializedData, |
| 76 List<Test> tests, |
| 77 TestFunction testFunction) async { |
| 78 Uri entryPoint = Uri.parse('memory:main.dart'); |
| 74 int first = start ?? 0; | 79 int first = start ?? 0; |
| 75 int last = end ?? tests.length - 1; | 80 int last = end ?? tests.length - 1; |
| 81 |
| 76 for (int index = first; index <= last; index++) { | 82 for (int index = first; index <= last; index++) { |
| 77 Test test = TESTS[index]; | 83 Test test = TESTS[index]; |
| 78 await f(index, test); | 84 List<SerializedData> dataList = |
| 85 await preserializeData(serializedData, test); |
| 86 Map<String, String> sourceFiles = <String, String>{}; |
| 87 sourceFiles.addAll(test.sourceFiles); |
| 88 if (test.preserializedSourceFiles != null) { |
| 89 sourceFiles.addAll(test.preserializedSourceFiles); |
| 90 } |
| 91 List<Uri> resolutionInputs = <Uri>[]; |
| 92 for (SerializedData data in dataList) { |
| 93 data.expandMemorySourceFiles(sourceFiles); |
| 94 data.expandUris(resolutionInputs); |
| 95 } |
| 96 await testFunction(entryPoint, |
| 97 sourceFiles: sourceFiles, |
| 98 resolutionInputs: resolutionInputs, |
| 99 index: index, |
| 100 test: test, |
| 101 verbose: verbose); |
| 79 } | 102 } |
| 80 } | 103 } |
| 81 } | 104 } |
| 82 | 105 |
| 106 typedef Future TestFunction( |
| 107 Uri entryPoint, |
| 108 {Map<String, String> sourceFiles, |
| 109 List<Uri> resolutionInputs, |
| 110 int index, |
| 111 Test test, |
| 112 bool verbose}); |
| 83 | 113 |
| 84 Future<SerializedData> serializeDartCore( | 114 Future<SerializedData> serializeDartCore( |
| 85 {Arguments arguments: const Arguments()}) async { | 115 {Arguments arguments: const Arguments()}) async { |
| 86 Uri uri = Uri.parse('memory:${arguments.serializedDataFileName}'); | 116 Uri uri = Uri.parse('memory:${arguments.serializedDataFileName}'); |
| 87 print('------------------------------------------------------------------'); | 117 print('------------------------------------------------------------------'); |
| 88 print('serialize dart:core'); | 118 print('serialize dart:core'); |
| 89 print('------------------------------------------------------------------'); | 119 print('------------------------------------------------------------------'); |
| 90 SerializedData serializedData; | 120 SerializedData serializedData; |
| 91 if (arguments.loadSerializedData) { | 121 if (arguments.loadSerializedData) { |
| 92 File file = new File(arguments.serializedDataFileName); | 122 File file = new File(arguments.serializedDataFileName); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (input != null) { | 169 if (input != null) { |
| 140 uris.addAll(input); | 170 uris.addAll(input); |
| 141 } | 171 } |
| 142 expandUris(uris); | 172 expandUris(uris); |
| 143 return uris; | 173 return uris; |
| 144 } | 174 } |
| 145 | 175 |
| 146 void expandUris(List<Uri> uris) { | 176 void expandUris(List<Uri> uris) { |
| 147 uris.add(uri); | 177 uris.add(uri); |
| 148 } | 178 } |
| 149 } | 179 } |
| 180 |
| 181 String extractSerializedData( |
| 182 Compiler compiler, Iterable<LibraryElement> libraries) { |
| 183 BufferedEventSink sink = new BufferedEventSink(); |
| 184 compiler.serialization.serializeToSink(sink, libraries); |
| 185 return sink.text; |
| 186 } |
| 187 |
| 188 Future<List<SerializedData>> preserializeData( |
| 189 SerializedData serializedData, Test test) async { |
| 190 if (test == null || |
| 191 test.preserializedSourceFiles == null || |
| 192 test.preserializedSourceFiles.isEmpty) { |
| 193 return <SerializedData>[serializedData]; |
| 194 } |
| 195 List<Uri> uriList = <Uri>[]; |
| 196 for (String key in test.preserializedSourceFiles.keys) { |
| 197 uriList.add(Uri.parse('memory:$key')); |
| 198 } |
| 199 Compiler compiler = compilerFor( |
| 200 memorySourceFiles: |
| 201 serializedData.toMemorySourceFiles(test.preserializedSourceFiles), |
| 202 resolutionInputs: serializedData.toUris(), |
| 203 options: [Flags.analyzeOnly, Flags.analyzeMain]); |
| 204 compiler.librariesToAnalyzeWhenRun = uriList; |
| 205 compiler.serialization.supportSerialization = true; |
| 206 await compiler.run(null); |
| 207 List<LibraryElement> libraries = <LibraryElement>[]; |
| 208 for (Uri uri in uriList) { |
| 209 libraries.add(compiler.libraryLoader.lookupLibrary(uri)); |
| 210 } |
| 211 SerializedData additionalSerializedData = |
| 212 new SerializedData(Uri.parse('memory:additional.data'), |
| 213 extractSerializedData(compiler, libraries)); |
| 214 return <SerializedData>[serializedData, additionalSerializedData]; |
| 215 } |
| OLD | NEW |