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 /// This is an interface to the Dart Kernel parser and Kernel binary generator. | 5 /// This is an interface to the Dart Kernel parser and Kernel binary generator. |
6 /// | 6 /// |
7 /// It is used by the kernel-isolate to load Dart source code and generate | 7 /// It is used by the kernel-isolate to load Dart source code and generate |
8 /// Kernel binary format. | 8 /// Kernel binary format. |
9 /// | 9 /// |
10 /// This is either invoked as the root script of the Kernel isolate when used | 10 /// This is either invoked as the root script of the Kernel isolate when used |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 .resolve('platform.dill'); | 63 .resolve('platform.dill'); |
64 | 64 |
65 if (verbose) { | 65 if (verbose) { |
66 print("DFE: scriptUri: ${script}"); | 66 print("DFE: scriptUri: ${script}"); |
67 print("DFE: Platform.packageConfig: ${Platform.packageConfig}"); | 67 print("DFE: Platform.packageConfig: ${Platform.packageConfig}"); |
68 print("DFE: packagesUri: ${packagesUri}"); | 68 print("DFE: packagesUri: ${packagesUri}"); |
69 print("DFE: Platform.resolvedExecutable: ${Platform.resolvedExecutable}"); | 69 print("DFE: Platform.resolvedExecutable: ${Platform.resolvedExecutable}"); |
70 print("DFE: sdkSummary: ${sdkSummary}"); | 70 print("DFE: sdkSummary: ${sdkSummary}"); |
71 } | 71 } |
72 | 72 |
73 var errors = <String>[]; | 73 bool hasErrors = false; |
74 var options = new CompilerOptions() | 74 var options = new CompilerOptions() |
75 ..strongMode = strongMode | 75 ..strongMode = strongMode |
76 ..fileSystem = fileSystem | 76 ..fileSystem = fileSystem |
77 ..target = new VmFastaTarget(new TargetFlags(strongMode: strongMode)) | 77 ..target = new VmFastaTarget(new TargetFlags(strongMode: strongMode)) |
78 ..packagesFileUri = packagesUri | 78 ..packagesFileUri = packagesUri |
79 ..sdkSummary = sdkSummary | 79 ..sdkSummary = sdkSummary |
80 ..verbose = verbose | 80 ..verbose = verbose |
81 ..onError = (CompilationError e) => errors.add(e.message); | 81 ..reportMessages = true |
82 ..onError = (CompilationMessage e) { | |
83 if (e.severity == Severity.error) { | |
84 hasErrors = true; | |
85 } | |
86 }; | |
82 | 87 |
83 CompilationResult result; | 88 CompilationResult result; |
84 try { | 89 try { |
85 Program program = await kernelForProgram(script, options); | 90 Program program = await kernelForProgram(script, options); |
86 if (errors.isNotEmpty) { | 91 if (hasErrors) { |
ahe
2017/07/18 16:54:37
Something has regressed here, and I think we need
Siggi Cherem (dart-lang)
2017/07/18 22:50:44
I see, let's talk on our next sync up about this.
| |
87 result = new CompilationResult.errors(errors); | 92 // Note: the compiler prints errors to the console, so we don't print |
93 // those messages again here. | |
94 result = | |
95 new CompilationResult.error("Compile-time errors found in $script"); | |
88 } else { | 96 } else { |
89 // We serialize the program excluding platform.dill because the VM has | 97 // We serialize the program excluding platform.dill because the VM has |
90 // these sources built-in. Everything loaded as a summary in | 98 // these sources built-in. Everything loaded as a summary in |
91 // [kernelForProgram] is marked `external`, so we can use that bit to | 99 // [kernelForProgram] is marked `external`, so we can use that bit to |
92 // decide what to excluce. | 100 // decide what to excluce. |
93 // TODO(sigmund): remove the following line (Issue #30111) | 101 // TODO(sigmund): remove the following line (Issue #30111) |
94 program.libraries.forEach((e) => e.isExternal = false); | 102 program.libraries.forEach((e) => e.isExternal = false); |
95 result = new CompilationResult.ok( | 103 result = new CompilationResult.ok( |
96 serializeProgram(program, filter: (lib) => !lib.isExternal)); | 104 serializeProgram(program, filter: (lib) => !lib.isExternal)); |
97 } | 105 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 186 |
179 /// Compiler crashed. | 187 /// Compiler crashed. |
180 crash, | 188 crash, |
181 } | 189 } |
182 | 190 |
183 abstract class CompilationResult { | 191 abstract class CompilationResult { |
184 CompilationResult._(); | 192 CompilationResult._(); |
185 | 193 |
186 factory CompilationResult.ok(Uint8List bytes) = _CompilationOk; | 194 factory CompilationResult.ok(Uint8List bytes) = _CompilationOk; |
187 | 195 |
188 factory CompilationResult.errors(List<String> errors) = _CompilationError; | 196 factory CompilationResult.error(String error) = _CompilationError; |
189 | 197 |
190 factory CompilationResult.crash(Object exception, StackTrace stack) = | 198 factory CompilationResult.crash(Object exception, StackTrace stack) = |
191 _CompilationCrash; | 199 _CompilationCrash; |
192 | 200 |
193 Status get status; | 201 Status get status; |
194 | 202 |
195 get payload; | 203 get payload; |
196 | 204 |
197 List toResponse() => [status.index, payload]; | 205 List toResponse() => [status.index, payload]; |
198 } | 206 } |
(...skipping 15 matching lines...) Expand all Loading... | |
214 abstract class _CompilationFail extends CompilationResult { | 222 abstract class _CompilationFail extends CompilationResult { |
215 _CompilationFail() : super._(); | 223 _CompilationFail() : super._(); |
216 | 224 |
217 String get errorString; | 225 String get errorString; |
218 | 226 |
219 @override | 227 @override |
220 get payload => errorString; | 228 get payload => errorString; |
221 } | 229 } |
222 | 230 |
223 class _CompilationError extends _CompilationFail { | 231 class _CompilationError extends _CompilationFail { |
224 final List<String> errors; | 232 @override |
233 final String errorString; | |
225 | 234 |
226 _CompilationError(this.errors); | 235 _CompilationError(this.errorString); |
227 | 236 |
228 @override | 237 @override |
229 Status get status => Status.error; | 238 Status get status => Status.error; |
230 | 239 |
231 @override | |
232 String get errorString => errors.take(10).join('\n'); | |
233 | |
234 String toString() => "_CompilationError(${errorString})"; | 240 String toString() => "_CompilationError(${errorString})"; |
235 } | 241 } |
236 | 242 |
237 class _CompilationCrash extends _CompilationFail { | 243 class _CompilationCrash extends _CompilationFail { |
238 final Object exception; | 244 final Object exception; |
239 final StackTrace stack; | 245 final StackTrace stack; |
240 | 246 |
241 _CompilationCrash(this.exception, this.stack); | 247 _CompilationCrash(this.exception, this.stack); |
242 | 248 |
243 @override | 249 @override |
244 Status get status => Status.crash; | 250 Status get status => Status.crash; |
245 | 251 |
246 @override | 252 @override |
247 String get errorString => "${exception}\n${stack}"; | 253 String get errorString => "${exception}\n${stack}"; |
248 | 254 |
249 String toString() => "_CompilationCrash(${errorString})"; | 255 String toString() => "_CompilationCrash(${errorString})"; |
250 } | 256 } |
OLD | NEW |