Skip to content

Commit

Permalink
[frontend-server] Return non-zero exit code if there are errors.
Browse files Browse the repository at this point in the history
Change-Id: I2a1c28b391fae1cb2f7dd20b9302c70fa2fbd44e
Reviewed-on: https://dart-review.googlesource.com/48684
Commit-Queue: Alexander Aprelev <[email protected]>
Reviewed-by: Siva Annamalai <[email protected]>
  • Loading branch information
aam authored and [email protected] committed Mar 29, 2018
1 parent d7a540b commit 4da5228
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
7 changes: 5 additions & 2 deletions pkg/vm/bin/frontend_server_starter.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
library frontend_server;

import 'dart:async';
import 'dart:io';

import '../lib/frontend_server.dart';

void main(List<String> args) {
starter(args);
Future<Null> main(List<String> args) async {
exit(await starter(args));
}
36 changes: 29 additions & 7 deletions pkg/vm/lib/frontend_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Null> compile(
/// Returns [true] if compilation was successful and produced no errors.
Future<bool> compile(
String filename,
ArgResults options, {
IncrementalCompiler generator,
Expand Down Expand Up @@ -175,13 +177,15 @@ class FrontendCompiler implements CompilerInterface {

final ProgramTransformer transformer;

final List<String> errors = new List<String>();

void setMainSourceFilename(String filename) {
final Uri filenameUri = _getFileOrUri(filename);
_mainSource = filenameUri;
}

@override
Future<Null> compile(
Future<bool> compile(
String filename,
ArgResults options, {
IncrementalCompiler generator,
Expand All @@ -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<Uri> rootUris = <Uri>[];
for (String root in options['filesystem-root']) {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -265,7 +285,7 @@ class FrontendCompiler implements CompilerInterface {
_kernelBinaryFilename = _kernelBinaryFilenameIncremental;
} else
_outputStream.writeln(boundaryKey);
return null;
return errors.isEmpty;
}

Future<Null> invalidateIfBootstrapping() async {
Expand Down Expand Up @@ -516,8 +536,10 @@ Future<int> 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, () {
Expand Down
3 changes: 3 additions & 0 deletions pkg/vm/test/frontend_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Future<int> 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<String> args = <String>[
Expand Down Expand Up @@ -212,6 +213,7 @@ Future<int> 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<String> args = <String>[
'--sdk-root',
Expand Down Expand Up @@ -405,6 +407,7 @@ Future<int> 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<String> args = <String>[
Expand Down

0 comments on commit 4da5228

Please sign in to comment.