OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // Partial test that the closed world computed from [WorldImpact]s derived from | 5 // Partial test that the closed world computed from [WorldImpact]s derived from |
6 // kernel is equivalent to the original computed from resolution. | 6 // kernel is equivalent to the original computed from resolution. |
7 library dart2js.kernel.compiler_helper; | 7 library dart2js.kernel.compiler_helper; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 MemoryDillLibraryLoaderTask(KernelToElementMapImpl elementMap, | 132 MemoryDillLibraryLoaderTask(KernelToElementMapImpl elementMap, |
133 DiagnosticReporter reporter, Measurer measurer, this.program) | 133 DiagnosticReporter reporter, Measurer measurer, this.program) |
134 : super(elementMap, null, null, reporter, measurer); | 134 : super(elementMap, null, null, reporter, measurer); |
135 | 135 |
136 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 136 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
137 {bool skipFileWithPartOfTag: false}) async { | 137 {bool skipFileWithPartOfTag: false}) async { |
138 return createLoadedLibraries(program); | 138 return createLoadedLibraries(program); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 Future createTemp(Uri entryPoint, Map<String, String> memorySourceFiles, | 142 Future<Compiler> compileWithDill( |
143 {bool printSteps: false}) async { | 143 Uri entryPoint, Map<String, String> memorySourceFiles, List<String> options, |
| 144 {bool printSteps: false, |
| 145 CompilerOutput compilerOutput, |
| 146 void beforeRun(Compiler compiler)}) async { |
144 if (memorySourceFiles.isNotEmpty) { | 147 if (memorySourceFiles.isNotEmpty) { |
145 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); | 148 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); |
146 if (printSteps) { | 149 if (printSteps) { |
147 print('--- create temp directory $dir -------------------------------'); | 150 print('--- create temp directory $dir -------------------------------'); |
148 } | 151 } |
149 memorySourceFiles.forEach((String name, String source) { | 152 memorySourceFiles.forEach((String name, String source) { |
150 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); | 153 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); |
151 }); | 154 }); |
152 entryPoint = dir.uri.resolve(entryPoint.path); | 155 entryPoint = dir.uri.resolve(entryPoint.path); |
153 } | 156 } |
154 if (printSteps) { | 157 if (printSteps) { |
155 print('---- generate dill -----------------------------------------------'); | 158 print('---- generate dill -----------------------------------------------'); |
156 } | 159 } |
157 | 160 |
158 Uri dillFile = Uri.parse('$entryPoint.dill'); | 161 Uri dillFile = Uri.parse('$entryPoint.dill'); |
159 String buildDir = Platform.isMacOS ? 'xcodebuild' : 'out'; | 162 String buildDir = Platform.isMacOS ? 'xcodebuild' : 'out'; |
160 String configuration = | 163 String configuration = |
161 Platform.environment['DART_CONFIGURATION'] ?? 'ReleaseX64'; | 164 Platform.environment['DART_CONFIGURATION'] ?? 'ReleaseX64'; |
162 await generate.main([ | 165 await generate.main([ |
163 '--platform=$buildDir/$configuration/patched_dart2js_sdk/platform.dill', | 166 '--platform=$buildDir/$configuration/patched_dart2js_sdk/platform.dill', |
164 '$entryPoint' | 167 '$entryPoint' |
165 ]); | 168 ]); |
166 return dillFile; | |
167 } | |
168 | |
169 Future<Compiler> compileWithDill( | |
170 Uri entryPoint, Map<String, String> memorySourceFiles, List<String> options, | |
171 {bool printSteps: false, | |
172 CompilerOutput compilerOutput, | |
173 void beforeRun(Compiler compiler)}) async { | |
174 Uri dillFile = | |
175 await createTemp(entryPoint, memorySourceFiles, printSteps: printSteps); | |
176 | 169 |
177 if (printSteps) { | 170 if (printSteps) { |
178 print('---- compile from dill $dillFile ---------------------------------'); | 171 print('---- compile from dill $dillFile ---------------------------------'); |
179 } | 172 } |
180 Compiler compiler = compilerFor( | 173 Compiler compiler = compilerFor( |
181 entryPoint: dillFile, | 174 entryPoint: dillFile, |
182 options: [Flags.loadFromDill]..addAll(options), | 175 options: [Flags.loadFromDill]..addAll(options), |
183 outputProvider: compilerOutput); | 176 outputProvider: compilerOutput); |
184 ElementResolutionWorldBuilder.useInstantiationMap = true; | 177 ElementResolutionWorldBuilder.useInstantiationMap = true; |
185 compiler.resolution.retainCachesForTesting = true; | 178 compiler.resolution.retainCachesForTesting = true; |
186 if (beforeRun != null) { | 179 if (beforeRun != null) { |
187 beforeRun(compiler); | 180 beforeRun(compiler); |
188 } | 181 } |
189 await compiler.run(dillFile); | 182 await compiler.run(dillFile); |
190 return compiler; | 183 return compiler; |
191 } | 184 } |
OLD | NEW |