@@ -17,6 +17,7 @@ import 'package:args/args.dart';
1717import 'package:front_end/src/api_prototype/compiler_options.dart' ;
1818import 'package:front_end/src/api_prototype/file_system.dart'
1919 show FileSystemEntity;
20+ import 'package:front_end/src/api_prototype/front_end.dart' ;
2021// Use of multi_root_file_system.dart directly from front_end package is a
2122// temporarily solution while we are looking for better home for that
2223// functionality.
@@ -119,7 +120,8 @@ abstract class CompilerInterface {
119120 /// `options` . When `generator` parameter is omitted, new instance of
120121 /// `IncrementalKernelGenerator` is created by this method. Main use for this
121122 /// parameter is for mocking in tests.
122- Future <Null > compile (
123+ /// Returns [true] if compilation was successful and produced no errors.
124+ Future <bool > compile (
123125 String filename,
124126 ArgResults options, {
125127 IncrementalCompiler generator,
@@ -175,13 +177,15 @@ class FrontendCompiler implements CompilerInterface {
175177
176178 final ProgramTransformer transformer;
177179
180+ final List <String > errors = new List <String >();
181+
178182 void setMainSourceFilename (String filename) {
179183 final Uri filenameUri = _getFileOrUri (filename);
180184 _mainSource = filenameUri;
181185 }
182186
183187 @override
184- Future <Null > compile (
188+ Future <bool > compile (
185189 String filename,
186190 ArgResults options, {
187191 IncrementalCompiler generator,
@@ -204,7 +208,23 @@ class FrontendCompiler implements CompilerInterface {
204208 ..packagesFileUri = _getFileOrUri (_options['packages' ])
205209 ..strongMode = options['strong' ]
206210 ..sdkSummary = sdkRoot.resolve (platformKernelDill)
207- ..reportMessages = true ;
211+ ..onProblem =
212+ (message, Severity severity, String formatted, int line, int column) {
213+ switch (severity) {
214+ case Severity .error:
215+ case Severity .errorLegacyWarning:
216+ case Severity .internalProblem:
217+ _outputStream.writeln (formatted);
218+ errors.add (formatted);
219+ break ;
220+ case Severity .nit:
221+ break ;
222+ case Severity .warning:
223+ case Severity .context:
224+ _outputStream.writeln (formatted);
225+ break ;
226+ }
227+ };
208228 if (options.wasParsed ('filesystem-root' )) {
209229 List <Uri > rootUris = < Uri > [];
210230 for (String root in options['filesystem-root' ]) {
@@ -217,7 +237,7 @@ class FrontendCompiler implements CompilerInterface {
217237 print ("When --filesystem-root is specified it is required to specify"
218238 " --output-dill option that points to physical file system location"
219239 " of a target dill file." );
220- exit ( 1 ) ;
240+ return false ;
221241 }
222242 }
223243
@@ -265,7 +285,7 @@ class FrontendCompiler implements CompilerInterface {
265285 _kernelBinaryFilename = _kernelBinaryFilenameIncremental;
266286 } else
267287 _outputStream.writeln (boundaryKey);
268- return null ;
288+ return errors.isEmpty ;
269289 }
270290
271291 Future <Null > invalidateIfBootstrapping () async {
@@ -516,8 +536,10 @@ Future<int> starter(
516536 );
517537
518538 if (options.rest.isNotEmpty) {
519- await compiler.compile (options.rest[0 ], options, generator: generator);
520- return 0 ;
539+ return await compiler.compile (options.rest[0 ], options,
540+ generator: generator)
541+ ? 0
542+ : 254 ;
521543 }
522544
523545 listenAndCompile (compiler, input ?? stdin, options, () {
0 commit comments