diff --git a/pkg/vm/bin/frontend_server_starter.dart b/pkg/vm/bin/frontend_server_starter.dart index 229410b1caf12..f81d98b40fe4f 100644 --- a/pkg/vm/bin/frontend_server_starter.dart +++ b/pkg/vm/bin/frontend_server_starter.dart @@ -1,7 +1,10 @@ library frontend_server; +import 'dart:async'; +import 'dart:io'; + import '../lib/frontend_server.dart'; -void main(List args) { - starter(args); +Future main(List args) async { + exit(await starter(args)); } diff --git a/pkg/vm/lib/frontend_server.dart b/pkg/vm/lib/frontend_server.dart index 15ee47f828537..0b96037c5fb7f 100644 --- a/pkg/vm/lib/frontend_server.dart +++ b/pkg/vm/lib/frontend_server.dart @@ -17,6 +17,7 @@ import 'package:args/args.dart'; import 'package:front_end/src/api_prototype/compiler_options.dart'; import 'package:front_end/src/api_prototype/file_system.dart' show FileSystemEntity; +import 'package:front_end/src/api_prototype/front_end.dart'; // Use of multi_root_file_system.dart directly from front_end package is a // temporarily solution while we are looking for better home for that // functionality. @@ -119,7 +120,8 @@ abstract class CompilerInterface { /// `options`. When `generator` parameter is omitted, new instance of /// `IncrementalKernelGenerator` is created by this method. Main use for this /// parameter is for mocking in tests. - Future compile( + /// Returns [true] if compilation was successful and produced no errors. + Future compile( String filename, ArgResults options, { IncrementalCompiler generator, @@ -175,13 +177,15 @@ class FrontendCompiler implements CompilerInterface { final ProgramTransformer transformer; + final List errors = new List(); + void setMainSourceFilename(String filename) { final Uri filenameUri = _getFileOrUri(filename); _mainSource = filenameUri; } @override - Future compile( + Future compile( String filename, ArgResults options, { IncrementalCompiler generator, @@ -204,7 +208,23 @@ class FrontendCompiler implements CompilerInterface { ..packagesFileUri = _getFileOrUri(_options['packages']) ..strongMode = options['strong'] ..sdkSummary = sdkRoot.resolve(platformKernelDill) - ..reportMessages = true; + ..onProblem = + (message, Severity severity, String formatted, int line, int column) { + switch (severity) { + case Severity.error: + case Severity.errorLegacyWarning: + case Severity.internalProblem: + _outputStream.writeln(formatted); + errors.add(formatted); + break; + case Severity.nit: + break; + case Severity.warning: + case Severity.context: + _outputStream.writeln(formatted); + break; + } + }; if (options.wasParsed('filesystem-root')) { List rootUris = []; for (String root in options['filesystem-root']) { @@ -217,7 +237,7 @@ class FrontendCompiler implements CompilerInterface { print("When --filesystem-root is specified it is required to specify" " --output-dill option that points to physical file system location" " of a target dill file."); - exit(1); + return false; } } @@ -265,7 +285,7 @@ class FrontendCompiler implements CompilerInterface { _kernelBinaryFilename = _kernelBinaryFilenameIncremental; } else _outputStream.writeln(boundaryKey); - return null; + return errors.isEmpty; } Future invalidateIfBootstrapping() async { @@ -516,8 +536,10 @@ Future starter( ); if (options.rest.isNotEmpty) { - await compiler.compile(options.rest[0], options, generator: generator); - return 0; + return await compiler.compile(options.rest[0], options, + generator: generator) + ? 0 + : 254; } listenAndCompile(compiler, input ?? stdin, options, () { diff --git a/pkg/vm/test/frontend_server_test.dart b/pkg/vm/test/frontend_server_test.dart index 3279881ff4f98..7109a0028dd52 100644 --- a/pkg/vm/test/frontend_server_test.dart +++ b/pkg/vm/test/frontend_server_test.dart @@ -32,6 +32,7 @@ Future main() async { group('batch compile with mocked compiler', () { final CompilerInterface compiler = new _MockedCompiler(); + when(compiler.compile(any, any, generator: any)).thenReturn(true); test('compile from command line', () async { final List args = [ @@ -212,6 +213,7 @@ Future main() async { group('interactive incremental compile with mocked compiler', () { final CompilerInterface compiler = new _MockedCompiler(); + when(compiler.compile(any, any, generator: any)).thenReturn(true); final List args = [ '--sdk-root', @@ -405,6 +407,7 @@ Future main() async { group('compile with output path', () { final CompilerInterface compiler = new _MockedCompiler(); + when(compiler.compile(any, any, generator: any)).thenReturn(true); test('compile from command line', () async { final List args = [