Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4da5228

Browse files
aamcommit-bot@chromium.org
authored andcommitted
[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 <aam@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
1 parent d7a540b commit 4da5228

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
library frontend_server;
22

3+
import 'dart:async';
4+
import 'dart:io';
5+
36
import '../lib/frontend_server.dart';
47

5-
void main(List<String> args) {
6-
starter(args);
8+
Future<Null> main(List<String> args) async {
9+
exit(await starter(args));
710
}

pkg/vm/lib/frontend_server.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:args/args.dart';
1717
import 'package:front_end/src/api_prototype/compiler_options.dart';
1818
import '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, () {

pkg/vm/test/frontend_server_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Future<int> main() async {
3232

3333
group('batch compile with mocked compiler', () {
3434
final CompilerInterface compiler = new _MockedCompiler();
35+
when(compiler.compile(any, any, generator: any)).thenReturn(true);
3536

3637
test('compile from command line', () async {
3738
final List<String> args = <String>[
@@ -212,6 +213,7 @@ Future<int> main() async {
212213

213214
group('interactive incremental compile with mocked compiler', () {
214215
final CompilerInterface compiler = new _MockedCompiler();
216+
when(compiler.compile(any, any, generator: any)).thenReturn(true);
215217

216218
final List<String> args = <String>[
217219
'--sdk-root',
@@ -405,6 +407,7 @@ Future<int> main() async {
405407

406408
group('compile with output path', () {
407409
final CompilerInterface compiler = new _MockedCompiler();
410+
when(compiler.compile(any, any, generator: any)).thenReturn(true);
408411

409412
test('compile from command line', () async {
410413
final List<String> args = <String>[

0 commit comments

Comments
 (0)