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