OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 compiler_configuration; | 5 library compiler_configuration; |
6 | 6 |
7 import 'dart:io' show Platform; | 7 import 'dart:io' show Platform; |
8 | 8 |
9 import 'runtime_configuration.dart' show RuntimeConfiguration; | 9 import 'runtime_configuration.dart' show RuntimeConfiguration; |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 case 'dart2app': | 82 case 'dart2app': |
83 return new Dart2AppSnapshotCompilerConfiguration( | 83 return new Dart2AppSnapshotCompilerConfiguration( |
84 isDebug: isDebug, isChecked: isChecked, useBlobs: useBlobs); | 84 isDebug: isDebug, isChecked: isChecked, useBlobs: useBlobs); |
85 case 'precompiler': | 85 case 'precompiler': |
86 return new PrecompilerCompilerConfiguration( | 86 return new PrecompilerCompilerConfiguration( |
87 isDebug: isDebug, | 87 isDebug: isDebug, |
88 isChecked: isChecked, | 88 isChecked: isChecked, |
89 arch: configuration['arch'], | 89 arch: configuration['arch'], |
90 useBlobs: useBlobs, | 90 useBlobs: useBlobs, |
91 isAndroid: configuration['system'] == 'android'); | 91 isAndroid: configuration['system'] == 'android'); |
92 case 'dartk': | |
93 return ComposedCompilerConfiguration.createDartKConfiguration( | |
94 isHostChecked: isHostChecked, | |
95 kernel_transformers: configuration['kernel_transformers'], | |
96 useSdk: useSdk); | |
97 case 'dartkp': | |
98 return ComposedCompilerConfiguration.createDartKPConfiguration( | |
99 isHostChecked: isHostChecked, | |
100 arch: configuration['arch'], | |
101 useBlobs: useBlobs, | |
102 isAndroid: configuration['system'] == 'android', | |
103 kernel_transformers: configuration['kernel_transformers'], | |
104 useSdk: useSdk); | |
105 case 'none': | 92 case 'none': |
106 return new NoneCompilerConfiguration( | 93 return new NoneCompilerConfiguration( |
107 isDebug: isDebug, | 94 isDebug: isDebug, |
108 isChecked: isChecked, | 95 isChecked: isChecked, |
109 isHostChecked: isHostChecked, | 96 isHostChecked: isHostChecked, |
110 useSdk: useSdk, | 97 useSdk: useSdk, |
111 hotReload: hotReload, | 98 hotReload: hotReload, |
112 hotReloadRollback: hotReloadRollback); | 99 hotReloadRollback: hotReloadRollback); |
113 default: | 100 default: |
114 throw "Unknown compiler '$compiler'"; | 101 throw "Unknown compiler '$compiler'"; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } else if (hotReloadRollback) { | 192 } else if (hotReloadRollback) { |
206 args.add('--hot-reload-rollback-test-mode'); | 193 args.add('--hot-reload-rollback-test-mode'); |
207 } | 194 } |
208 return args | 195 return args |
209 ..addAll(vmOptions) | 196 ..addAll(vmOptions) |
210 ..addAll(sharedOptions) | 197 ..addAll(sharedOptions) |
211 ..addAll(originalArguments); | 198 ..addAll(originalArguments); |
212 } | 199 } |
213 } | 200 } |
214 | 201 |
215 /// The "dartk" compiler. | |
216 class DartKCompilerConfiguration extends CompilerConfiguration { | |
217 DartKCompilerConfiguration({bool isHostChecked, bool useSdk}) | |
218 : super._subclass(isHostChecked: isHostChecked, useSdk: useSdk); | |
219 | |
220 @override | |
221 String computeCompilerPath(String buildDir) { | |
222 return 'third_party/pkg/kernel/bin/dartk.dart'; | |
223 } | |
224 | |
225 CompilationCommand computeCompilationCommand( | |
226 String outputFileName, | |
227 String buildDir, | |
228 CommandBuilder commandBuilder, | |
229 List arguments, | |
230 Map<String, String> environmentOverrides) { | |
231 var extraArguments = [ | |
232 '--sdk', | |
233 '$buildDir/obj/gen/patched_sdk', | |
234 '--link', | |
235 '--target=vm', | |
236 '--out', | |
237 outputFileName | |
238 ]; | |
239 return commandBuilder.getKernelCompilationCommand( | |
240 'dartk', | |
241 outputFileName, | |
242 true, | |
243 bootstrapDependencies(buildDir), | |
244 computeCompilerPath(buildDir), | |
245 []..addAll(arguments)..addAll(extraArguments), | |
246 environmentOverrides); | |
247 } | |
248 | |
249 CommandArtifact computeCompilationArtifact( | |
250 String buildDir, | |
251 String tempDir, | |
252 CommandBuilder commandBuilder, | |
253 List arguments, | |
254 Map<String, String> environmentOverrides) { | |
255 return new CommandArtifact(<Command>[ | |
256 this.computeCompilationCommand('$tempDir/out.dill', buildDir, | |
257 CommandBuilder.instance, arguments, environmentOverrides) | |
258 ], '$tempDir/out.dill', 'application/dart'); | |
259 } | |
260 } | |
261 | |
262 typedef List<String> CompilerArgumentsFunction( | |
263 List<String> globalArguments, | |
264 String previousCompilerOutput); | |
265 | |
266 class PipelineCommand { | |
267 final CompilerConfiguration compilerConfiguration; | |
268 final CompilerArgumentsFunction _argumentsFunction; | |
269 | |
270 PipelineCommand._(this.compilerConfiguration, this._argumentsFunction); | |
271 | |
272 factory PipelineCommand.runWithGlobalArguments(CompilerConfiguration conf) { | |
273 return new PipelineCommand._(conf, (List<String> globalArguments, | |
274 String previousOutput) { | |
275 assert(previousOutput == null); | |
276 return globalArguments; | |
277 }); | |
278 } | |
279 | |
280 factory PipelineCommand.runWithDartOrKernelFile(CompilerConfiguration conf) { | |
281 return new PipelineCommand._(conf, (List<String> globalArguments, | |
282 String previousOutput) { | |
283 var filtered = globalArguments | |
284 .where((String name) => name.endsWith('.dart') || | |
285 name.endsWith('.dill')) | |
286 .toList(); | |
287 assert(filtered.length == 1); | |
288 return filtered; | |
289 }); | |
290 } | |
291 | |
292 factory PipelineCommand.runWithPreviousKernelOutput( | |
293 CompilerConfiguration conf) { | |
294 return new PipelineCommand._(conf, (List<String> globalArguments, | |
295 String previousOutput) { | |
296 assert(previousOutput.endsWith('.dill')); | |
297 return [previousOutput]; | |
298 }); | |
299 } | |
300 | |
301 List<String> extractArguments(List<String> globalArguments, | |
302 String previousOutput) { | |
303 return _argumentsFunction(globalArguments, previousOutput); | |
304 } | |
305 } | |
306 | |
307 class ComposedCompilerConfiguration extends CompilerConfiguration { | |
308 final List<PipelineCommand> pipelineCommands; | |
309 | |
310 ComposedCompilerConfiguration(this.pipelineCommands) | |
311 : super._subclass(); | |
312 | |
313 CommandArtifact computeCompilationArtifact( | |
314 String buildDir, | |
315 String tempDir, | |
316 CommandBuilder commandBuilder, | |
317 List globalArguments, | |
318 Map<String, String> environmentOverrides) { | |
319 | |
320 List<Command> allCommands = []; | |
321 | |
322 // The first compilation command is as usual. | |
323 var arguments = pipelineCommands[0].extractArguments(globalArguments, null); | |
324 CommandArtifact artifact = | |
325 pipelineCommands[0].compilerConfiguration.computeCompilationArtifact( | |
326 buildDir, tempDir, commandBuilder, arguments, environmentOverrides); | |
327 allCommands.addAll(artifact.commands); | |
328 | |
329 // The following compilation commands are based on the output of the | |
330 // previous one. | |
331 for (int i = 1; i < pipelineCommands.length; i++) { | |
332 PipelineCommand pc = pipelineCommands[i]; | |
333 | |
334 arguments = pc.extractArguments(globalArguments, artifact.filename); | |
335 artifact = pc.compilerConfiguration.computeCompilationArtifact( | |
336 buildDir, tempDir, commandBuilder, arguments, environmentOverrides); | |
337 | |
338 allCommands.addAll(artifact.commands); | |
339 } | |
340 | |
341 return new CommandArtifact( | |
342 allCommands, artifact.filename, artifact.mimeType); | |
343 } | |
344 | |
345 List<String> computeCompilerArguments(vmOptions, sharedOptions, args) { | |
346 // The result will be passed as an input to [extractArguments] | |
347 // (i.e. the arguments to the [PipelineCommand]). | |
348 return new List<String>.from(sharedOptions)..addAll(args); | |
349 } | |
350 | |
351 List<String> computeRuntimeArguments( | |
352 RuntimeConfiguration runtimeConfiguration, | |
353 String buildDir, | |
354 TestInformation info, | |
355 List<String> vmOptions, | |
356 List<String> sharedOptions, | |
357 List<String> originalArguments, | |
358 CommandArtifact artifact) { | |
359 return <String>[artifact.filename]; | |
360 } | |
361 | |
362 static ComposedCompilerConfiguration createDartKPConfiguration( | |
363 {bool isHostChecked, String arch, bool useBlobs, bool isAndroid, | |
364 String kernel_transformers, bool useSdk}) { | |
365 var nested = []; | |
366 | |
367 // Compile with dartk. | |
368 nested.add(new PipelineCommand.runWithGlobalArguments( | |
369 new DartKCompilerConfiguration(isHostChecked: isHostChecked, | |
370 useSdk: useSdk))); | |
371 | |
372 // Run zero or more transformations. | |
373 addKernelTransformations(nested, kernel_transformers); | |
374 | |
375 // Run the normal precompiler. | |
376 nested.add(new PipelineCommand.runWithPreviousKernelOutput( | |
377 new PrecompilerCompilerConfiguration( | |
378 arch: arch, useBlobs: useBlobs, isAndroid: isAndroid))); | |
379 | |
380 return new ComposedCompilerConfiguration(nested); | |
381 } | |
382 | |
383 static ComposedCompilerConfiguration createDartKConfiguration( | |
384 {bool isHostChecked, bool useSdk, String kernel_transformers}) { | |
385 var nested = []; | |
386 | |
387 // Compile with dartk. | |
388 nested.add(new PipelineCommand.runWithGlobalArguments( | |
389 new DartKCompilerConfiguration(isHostChecked: isHostChecked, | |
390 useSdk: useSdk))); | |
391 | |
392 // Run zero or more transformations. | |
393 addKernelTransformations(nested, kernel_transformers); | |
394 | |
395 return new ComposedCompilerConfiguration(nested); | |
396 } | |
397 | |
398 static void addKernelTransformations(List<PipelineCommand> nested, | |
399 String kernel_transformers) { | |
400 if (kernel_transformers != null && kernel_transformers.length > 0) { | |
401 List<String> names = kernel_transformers.split(','); | |
402 for (var name in names) { | |
403 var transformation = new KernelTransformation(name); | |
404 nested.add(nested.isEmpty | |
405 ? new PipelineCommand.runWithDartOrKernelFile(transformation) | |
406 : new PipelineCommand.runWithPreviousKernelOutput(transformation)); | |
407 } | |
408 } | |
409 } | |
410 } | |
411 | |
412 class KernelTransformation extends CompilerConfiguration { | |
413 final String transformation; | |
414 | |
415 KernelTransformation(this.transformation) : super._subclass(); | |
416 | |
417 CommandArtifact computeCompilationArtifact( | |
418 String buildDir, | |
419 String tempDir, | |
420 CommandBuilder commandBuilder, | |
421 List arguments, | |
422 Map<String, String> environmentOverrides) { | |
423 assert(arguments.length == 1); | |
424 assert(arguments.last.contains('/')); | |
425 assert(arguments.last.endsWith('.dill')); | |
426 | |
427 // The --kernel-transformers=a,b can be specified as | |
428 // a = <name> | |
429 // a = <name>:<path-to-transformer-executable> | |
430 int colonIndex = transformation.indexOf(':'); | |
431 String transformationName = transformation; | |
432 String executable; | |
433 if (colonIndex > 0) { | |
434 executable = transformation.substring(colonIndex + 1); | |
435 transformationName = transformation.substring(0, colonIndex); | |
436 } | |
437 | |
438 // The transformed output will be always written to a new file in the | |
439 // test-specific temporary directory. | |
440 var inputFile = arguments.last; | |
441 var baseInputFilename = inputFile.substring( | |
442 inputFile.lastIndexOf('/') + 1, inputFile.length - '.dill'.length); | |
443 var outputFile = '$tempDir/$baseInputFilename.$transformationName.dill'; | |
444 | |
445 // Use the user-supplied transformer or fall back to `transformer.dart`. | |
446 List<String> transformerArguments; | |
447 bool useBatchMode = false; | |
448 if (executable == null) { | |
449 executable = 'third_party/pkg/kernel/bin/transform.dart'; | |
450 transformerArguments = | |
451 ['-f', 'bin', '-t', transformation, '-o', outputFile, inputFile]; | |
452 useBatchMode = true; | |
453 } else { | |
454 transformerArguments = [inputFile, outputFile]; | |
455 } | |
456 | |
457 var command = commandBuilder.getKernelTransformationCommand( | |
458 transformationName, executable, transformerArguments, outputFile, | |
459 environmentOverrides, useBatchMode); | |
460 | |
461 return new CommandArtifact( | |
462 <Command>[ command ], outputFile, 'application/dart'); | |
463 } | |
464 } | |
465 | |
466 /// Common configuration for dart2js-based tools, such as, dart2js | 202 /// Common configuration for dart2js-based tools, such as, dart2js |
467 class Dart2xCompilerConfiguration extends CompilerConfiguration { | 203 class Dart2xCompilerConfiguration extends CompilerConfiguration { |
468 final String moniker; | 204 final String moniker; |
469 static Map<String, List<Uri>> _bootstrapDependenciesCache = | 205 static Map<String, List<Uri>> _bootstrapDependenciesCache = |
470 new Map<String, List<Uri>>(); | 206 new Map<String, List<Uri>>(); |
471 | 207 |
472 Dart2xCompilerConfiguration(this.moniker, | 208 Dart2xCompilerConfiguration(this.moniker, |
473 {bool isDebug, bool isChecked, bool isHostChecked, bool useSdk}) | 209 {bool isDebug, bool isChecked, bool isHostChecked, bool useSdk}) |
474 : super._subclass( | 210 : super._subclass( |
475 isDebug: isDebug, | 211 isDebug: isDebug, |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 RuntimeConfiguration runtimeConfiguration, | 639 RuntimeConfiguration runtimeConfiguration, |
904 String buildDir, | 640 String buildDir, |
905 TestInformation info, | 641 TestInformation info, |
906 List<String> vmOptions, | 642 List<String> vmOptions, |
907 List<String> sharedOptions, | 643 List<String> sharedOptions, |
908 List<String> originalArguments, | 644 List<String> originalArguments, |
909 CommandArtifact artifact) { | 645 CommandArtifact artifact) { |
910 return <String>[]; | 646 return <String>[]; |
911 } | 647 } |
912 } | 648 } |
OLD | NEW |