From 4da52281aa35b6c1951b3e269a6934412b15b105 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 29 Mar 2018 02:45:39 +0000 Subject: [PATCH] [frontend-server] Return non-zero exit code if there are errors. Change-Id: I2a1c28b391fae1cb2f7dd20b9302c70fa2fbd44e Reviewed-on: https://dart-review.googlesource.com/48684 Commit-Queue: Alexander Aprelev Reviewed-by: Siva Annamalai --- pkg/vm/bin/frontend_server_starter.dart | 7 +++-- pkg/vm/lib/frontend_server.dart | 36 ++++++++++++++++++++----- pkg/vm/test/frontend_server_test.dart | 3 +++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/pkg/vm/bin/frontend_server_starter.dart b/pkg/vm/bin/frontend_server_starter.dart index 229410b1caf..f81d98b40fe 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 15ee47f8285..0b96037c5fb 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 3279881ff4f..7109a0028dd 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 = [