Skip to content

Commit

Permalink
[vm/frontend-server] Fix frontend_server so that it can be tested.
Browse files Browse the repository at this point in the history
With explicit exit() invocation, frontend_server_test only gets through first two tests before exiting.

Change-Id: Ica0b6f4f09baa8262b6097779be772877ca6f8d8
Reviewed-on: https://dart-review.googlesource.com/69220
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
aam authored and commit-bot@chromium.org committed Aug 9, 2018
1 parent 1be785a commit 3d0a663
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 83 deletions.
6 changes: 5 additions & 1 deletion pkg/vm/bin/frontend_server_starter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
library frontend_server;

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

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

Future<Null> main(List<String> args) async {
starter(args);
final int exitCode = await starter(args);
if (exitCode != 0) {
exit(exitCode);
}
}
31 changes: 19 additions & 12 deletions pkg/vm/lib/frontend_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,13 @@ class FrontendCompiler implements CompilerInterface {
if (uri == null || '$uri' == '') continue nextUri;

final List<int> oldBytes = component.uriToSource[uri].source;
final FileSystemEntity entity =
_compilerOptions.fileSystem.entityForUri(uri);
FileSystemEntity entity;
try {
entity = _compilerOptions.fileSystem.entityForUri(uri);
} catch (_) {
// Ignore errors that might be caused by non-file uris.
continue nextUri;
}
if (!await entity.exists()) {
_generator.invalidate(uri);
continue nextUri;
Expand Down Expand Up @@ -554,7 +559,7 @@ class _CompileExpressionRequest {
/// Listens for the compilation commands on [input] stream.
/// This supports "interactive" recompilation mode of execution.
void listenAndCompile(CompilerInterface compiler, Stream<List<int>> input,
ArgResults options, void quit(),
ArgResults options, Completer<int> completer,
{IncrementalCompiler generator}) {
_State state = _State.READY_FOR_INSTRUCTION;
_CompileExpressionRequest compileExpressionRequest;
Expand Down Expand Up @@ -608,7 +613,7 @@ void listenAndCompile(CompilerInterface compiler, Stream<List<int>> input,
} else if (string == 'reset') {
compiler.resetIncrementalCompiler();
} else if (string == 'quit') {
quit();
completer.complete(0);
}
break;
case _State.RECOMPILE_LIST:
Expand Down Expand Up @@ -668,7 +673,7 @@ void listenAndCompile(CompilerInterface compiler, Stream<List<int>> input,
/// processes user input.
/// `compiler` is an optional parameter so it can be replaced with mocked
/// version for testing.
Future<void> starter(
Future<int> starter(
List<String> args, {
CompilerInterface compiler,
Stream<List<int>> input,
Expand All @@ -682,7 +687,7 @@ Future<void> starter(
} catch (error) {
print('ERROR: $error\n');
print(usage);
exit(1);
return 1;
}

if (options['train']) {
Expand Down Expand Up @@ -714,7 +719,7 @@ Future<void> starter(
compiler.acceptLastDelta();
await compiler.recompileDelta();
compiler.acceptLastDelta();
return;
return 0;
} finally {
temp.deleteSync(recursive: true);
}
Expand All @@ -726,12 +731,14 @@ Future<void> starter(
);

if (options.rest.isNotEmpty) {
exit(await compiler.compile(options.rest[0], options, generator: generator)
return await compiler.compile(options.rest[0], options,
generator: generator)
? 0
: 254);
: 254;
}

listenAndCompile(compiler, input ?? stdin, options, () {
exit(0);
}, generator: generator);
Completer<int> completer = new Completer<int>();
listenAndCompile(compiler, input ?? stdin, options, completer,
generator: generator);
return completer.future;
}
Loading

0 comments on commit 3d0a663

Please sign in to comment.