OLD | NEW |
1 // Copyright (c) 2017, 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 import 'package:front_end/src/fasta/compile_platform.dart' show mainEntryPoint; | 5 library fasta.compile_platform; |
6 | 6 |
7 main(List<String> arguments) => mainEntryPoint(arguments); | 7 import 'dart:async' show Future; |
| 8 |
| 9 import 'dart:io' show exitCode, File; |
| 10 |
| 11 import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext; |
| 12 |
| 13 import 'package:front_end/src/fasta/deprecated_problems.dart' |
| 14 show deprecated_InputError; |
| 15 |
| 16 import 'package:front_end/src/fasta/kernel/utils.dart' show writeProgramToFile; |
| 17 |
| 18 import 'package:front_end/src/fasta/severity.dart' show Severity; |
| 19 |
| 20 import 'package:front_end/src/kernel_generator_impl.dart' |
| 21 show generateKernelInternal; |
| 22 |
| 23 import 'command_line.dart' show withGlobalOptions; |
| 24 |
| 25 const int iterations = const int.fromEnvironment("iterations", defaultValue: 1); |
| 26 |
| 27 Future main(List<String> arguments) async { |
| 28 for (int i = 0; i < iterations; i++) { |
| 29 if (i > 0) { |
| 30 print("\n"); |
| 31 } |
| 32 try { |
| 33 await compilePlatform(arguments); |
| 34 } on deprecated_InputError catch (e) { |
| 35 exitCode = 1; |
| 36 CompilerContext.runWithDefaultOptions( |
| 37 (c) => c.report(deprecated_InputError.toMessage(e), Severity.error)); |
| 38 return null; |
| 39 } |
| 40 } |
| 41 } |
| 42 |
| 43 Future compilePlatform(List<String> arguments) async { |
| 44 await withGlobalOptions("compile_platform", arguments, false, |
| 45 (CompilerContext c, List<String> restArguments) { |
| 46 c.options.inputs.add(Uri.parse('dart:core')); |
| 47 // Note: the patchedSdk argument is already stored in c.options.sdkRoot. |
| 48 Uri fullOutput = Uri.base.resolveUri(new Uri.file(restArguments[1])); |
| 49 Uri outlineOutput = Uri.base.resolveUri(new Uri.file(restArguments[2])); |
| 50 return compilePlatformInternal(c, fullOutput, outlineOutput); |
| 51 }); |
| 52 } |
| 53 |
| 54 Future compilePlatformInternal( |
| 55 CompilerContext c, Uri fullOutput, Uri outlineOutput) async { |
| 56 if (c.options.strongMode) { |
| 57 print("Note: strong mode support is preliminary and may not work."); |
| 58 } |
| 59 if (c.options.verbose) { |
| 60 print("Generating outline of ${c.options.sdkRoot} into $outlineOutput"); |
| 61 print("Compiling ${c.options.sdkRoot} to $fullOutput"); |
| 62 } |
| 63 |
| 64 var result = |
| 65 await generateKernelInternal(buildSummary: true, buildProgram: true); |
| 66 if (result == null) { |
| 67 // Note: an error should have been reported by now. |
| 68 print('The platform .dill files were not created.'); |
| 69 return; |
| 70 } |
| 71 new File.fromUri(outlineOutput).writeAsBytesSync(result.summary); |
| 72 c.options.ticker.logMs("Wrote outline to ${outlineOutput.toFilePath()}"); |
| 73 await writeProgramToFile(result.program, fullOutput); |
| 74 c.options.ticker.logMs("Wrote program to ${fullOutput.toFilePath()}"); |
| 75 } |
OLD | NEW |