Add reset method to reset incremental compiler. (flutter/engine#4187)

* Add reset method to reset incremental compiler.

This is needed to support Flutter app restart request.

* Indent constructor calls
This commit is contained in:
Alexander Aprelev
2017-10-09 14:58:27 -07:00
committed by GitHub
parent d4ab705952
commit d73c211831
2 changed files with 31 additions and 4 deletions

View File

@@ -82,6 +82,10 @@ abstract class CompilerInterface {
/// This let's compiler know that source file identifed by `uri` was changed.
void invalidate(Uri uri);
/// Resets incremental compiler accept/reject status so that next time
/// recompile is requested, complete kernel file is produced.
void resetIncrementalCompiler();
}
/// Class that for test mocking purposes encapsulates creation of [BinaryPrinter].
@@ -191,6 +195,11 @@ class _FrontendCompiler implements CompilerInterface {
_generator.invalidate(uri);
}
@override
void resetIncrementalCompiler() {
_generator.reset();
}
Uri _ensureFolderPath(String path) {
// This is a URI, not a file path, so the forward slash is correct even
// on Windows.
@@ -257,6 +266,8 @@ Future<int> starter(List<String> args, {
compiler.acceptLastDelta();
else if (string == 'reject')
compiler.rejectLastDelta();
else if (string == 'reset')
compiler.resetIncrementalCompiler();
else if (string == 'quit')
exit(0);
break;

View File

@@ -59,7 +59,7 @@ Future<int> main() async {
test('compile one file', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
new StreamController<List<int>>();
final ReceivePort compileCalled = new ReceivePort();
when(compiler.compile(any, any, generator: any)).thenAnswer(
(Invocation invocation) {
@@ -80,7 +80,7 @@ Future<int> main() async {
test('compile few files', () async {
final StreamController<List<int>> streamController =
new StreamController<List<int>>();
new StreamController<List<int>>();
final ReceivePort compileCalled = new ReceivePort();
int counter = 1;
when(compiler.compile(any, any, generator: any)).thenAnswer(
@@ -154,7 +154,7 @@ Future<int> main() async {
test('reject', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
new StreamController<List<int>>();
final ReceivePort rejectCalled = new ReceivePort();
when(compiler.rejectLastDelta()).thenAnswer((Invocation invocation) {
rejectCalled.sendPort.send(true);
@@ -168,9 +168,25 @@ Future<int> main() async {
inputStreamController.close();
});
test('reset', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
final ReceivePort resetCalled = new ReceivePort();
when(compiler.resetIncrementalCompiler()).thenAnswer((Invocation invocation) {
resetCalled.sendPort.send(true);
});
final int exitcode = await starter(args, compiler: compiler,
input: inputStreamController.stream,
);
expect(exitcode, equals(0));
inputStreamController.add('reset\n'.codeUnits);
await resetCalled.first;
inputStreamController.close();
});
test('compile then recompile', () async {
final StreamController<List<int>> streamController =
new StreamController<List<int>>();
new StreamController<List<int>>();
final ReceivePort recompileCalled = new ReceivePort();
when(compiler.recompileDelta()).thenAnswer((Invocation invocation) {