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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (memorySourceFiles.isNotEmpty) { | 145 if (memorySourceFiles.isNotEmpty) { |
146 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); | 146 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); |
147 if (printSteps) { | 147 if (printSteps) { |
148 print('--- create temp directory $dir -------------------------------'); | 148 print('--- create temp directory $dir -------------------------------'); |
149 } | 149 } |
150 memorySourceFiles.forEach((String name, String source) { | 150 memorySourceFiles.forEach((String name, String source) { |
151 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); | 151 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); |
152 }); | 152 }); |
153 entryPoint = dir.uri.resolve(entryPoint.path); | 153 entryPoint = dir.uri.resolve(entryPoint.path); |
154 } | 154 } |
| 155 return entryPoint; |
| 156 } |
| 157 |
| 158 Future generateDill(Uri entryPoint, Map<String, String> memorySourceFiles, |
| 159 {bool printSteps: false}) async { |
| 160 entryPoint = |
| 161 await createTemp(entryPoint, memorySourceFiles, printSteps: printSteps); |
155 if (printSteps) { | 162 if (printSteps) { |
156 print('---- generate dill -----------------------------------------------'); | 163 print('---- generate dill -----------------------------------------------'); |
157 } | 164 } |
158 | 165 |
159 Uri dillFile = Uri.parse('$entryPoint.dill'); | 166 Uri dillFile = Uri.parse('$entryPoint.dill'); |
160 String buildDir = Platform.isMacOS ? 'xcodebuild' : 'out'; | 167 String buildDir = Platform.isMacOS ? 'xcodebuild' : 'out'; |
161 String configuration = | 168 String configuration = |
162 Platform.environment['DART_CONFIGURATION'] ?? 'ReleaseX64'; | 169 Platform.environment['DART_CONFIGURATION'] ?? 'ReleaseX64'; |
163 await generate.main([ | 170 await generate.main([ |
164 '--platform=$buildDir/$configuration/patched_dart2js_sdk/platform.dill', | 171 '--platform=$buildDir/$configuration/patched_dart2js_sdk/platform.dill', |
165 '--out=${uriPathToNative(dillFile.path)}', | 172 '--out=${uriPathToNative(dillFile.path)}', |
166 '${entryPoint.path}', | 173 '${entryPoint.path}', |
167 ]); | 174 ]); |
168 return dillFile; | 175 return dillFile; |
169 } | 176 } |
170 | 177 |
171 Future<Compiler> compileWithDill( | 178 Future<Compiler> compileWithDill( |
172 Uri entryPoint, Map<String, String> memorySourceFiles, List<String> options, | 179 Uri entryPoint, Map<String, String> memorySourceFiles, List<String> options, |
173 {bool printSteps: false, | 180 {bool printSteps: false, |
174 CompilerOutput compilerOutput, | 181 CompilerOutput compilerOutput, |
175 void beforeRun(Compiler compiler)}) async { | 182 void beforeRun(Compiler compiler)}) async { |
176 Uri dillFile = | 183 Uri dillFile = |
177 await createTemp(entryPoint, memorySourceFiles, printSteps: printSteps); | 184 await generateDill(entryPoint, memorySourceFiles, printSteps: printSteps); |
178 | 185 |
179 if (printSteps) { | 186 if (printSteps) { |
180 print('---- compile from dill $dillFile ---------------------------------'); | 187 print('---- compile from dill $dillFile ---------------------------------'); |
181 } | 188 } |
182 Compiler compiler = compilerFor( | 189 Compiler compiler = compilerFor( |
183 entryPoint: dillFile, | 190 entryPoint: dillFile, |
184 options: [Flags.loadFromDill]..addAll(options), | 191 options: [Flags.loadFromDill]..addAll(options), |
185 outputProvider: compilerOutput); | 192 outputProvider: compilerOutput); |
186 ElementResolutionWorldBuilder.useInstantiationMap = true; | 193 ElementResolutionWorldBuilder.useInstantiationMap = true; |
187 compiler.resolution.retainCachesForTesting = true; | 194 compiler.resolution.retainCachesForTesting = true; |
188 if (beforeRun != null) { | 195 if (beforeRun != null) { |
189 beforeRun(compiler); | 196 beforeRun(compiler); |
190 } | 197 } |
191 await compiler.run(dillFile); | 198 await compiler.run(dillFile); |
192 return compiler; | 199 return compiler; |
193 } | 200 } |
OLD | NEW |