From e2e3c5df058240e85c8b6bc0b986bd538011b68a Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 11 Jan 2018 14:33:50 -0800 Subject: [PATCH] =?UTF-8?q?Reland=209534082fc097dadf075c1eda7938af48df59ce?= =?UTF-8?q?3e=20with=20fix=20for=20incremen=E2=80=A6=20(#14040)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Reland 9534082fc097dadf075c1eda7938af48df59ce3e with fix for incremental compilation. When in incremental mode, awaiting exitCode won't work because compiler is not expected to exit after compilation. Instead listen for stdout stream closing and report error if outputFilename has not been received. * Fix lints --- .../lib/src/commands/build_aot.dart | 4 ++ packages/flutter_tools/lib/src/compile.dart | 15 +++++-- packages/flutter_tools/lib/src/flx.dart | 3 ++ packages/flutter_tools/test/compile_test.dart | 40 ++++++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart index f132f0c5aa..37346a0898 100644 --- a/packages/flutter_tools/lib/src/commands/build_aot.dart +++ b/packages/flutter_tools/lib/src/commands/build_aot.dart @@ -342,6 +342,10 @@ Future _buildAotSnapshot( aot : true, strongMode: strongMode, ); + if (mainPath == null) { + printError('Compiler terminated unexpectedly.'); + return null; + } } genSnapshotCmd.add(mainPath); diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 27d096ff27..70ece1016f 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -110,8 +110,8 @@ Future compile( .transform(UTF8.decoder) .transform(const LineSplitter()) .listen(stdoutHandler.handler); - await server.exitCode; - return stdoutHandler.outputFilename.future; + final int exitCode = await server.exitCode; + return exitCode == 0 ? stdoutHandler.outputFilename.future : null; } /// Wrapper around incremental frontend server compiler, that communicates with @@ -173,7 +173,16 @@ class ResidentCompiler { _server.stdout .transform(UTF8.decoder) .transform(const LineSplitter()) - .listen(stdoutHandler.handler); + .listen( + stdoutHandler.handler, + onDone: () { + // when outputFilename future is not completed, but stdout is closed + // process has died unexpectedly. + if (!stdoutHandler.outputFilename.isCompleted) { + stdoutHandler.outputFilename.complete(null); + } + }); + _server.stderr .transform(UTF8.decoder) .transform(const LineSplitter()) diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index 860ae1ffbf..310481087f 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -76,6 +76,9 @@ Future build({ mainPath: fs.file(mainPath).absolute.path, strongMode: strongMode ); + if (kernelBinaryFilename == null) { + throwToolExit('Compiler terminated unexpectedly on $mainPath'); + } kernelContent = new DevFSFileContent(fs.file(kernelBinaryFilename)); } diff --git a/packages/flutter_tools/test/compile_test.dart b/packages/flutter_tools/test/compile_test.dart index 6285eb77d7..36f3847114 100644 --- a/packages/flutter_tools/test/compile_test.dart +++ b/packages/flutter_tools/test/compile_test.dart @@ -74,6 +74,28 @@ void main() { }, overrides: { ProcessManager: () => mockProcessManager, }); + + testUsingContext('single dart abnormal compiler termination', () async { + when(mockFrontendServer.exitCode).thenReturn(255); + + final BufferLogger logger = context[Logger]; + + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => new Stream>.fromFuture( + new Future>.value(UTF8.encode( + 'result abc\nline1\nline2\nabc' + )) + )); + + final String output = await compile(sdkRoot: '/path/to/sdkroot', + mainPath: '/path/to/main.dart' + ); + expect(mockFrontendServerStdIn.getAndClear(), isEmpty); + expect(logger.errorText, equals('compiler message: line1\ncompiler message: line2\n')); + expect(output, equals(null)); + }, overrides: { + ProcessManager: () => mockProcessManager, + }); }); group('incremental compile', () { @@ -101,7 +123,10 @@ void main() { when(mockProcessManager.start(any)).thenAnswer( (Invocation invocation) => new Future.value(mockFrontendServer) ); - when(mockFrontendServer.exitCode).thenReturn(0); + }); + + tearDown(() { + verifyNever(mockFrontendServer.exitCode); }); testUsingContext('single dart compile', () async { @@ -125,6 +150,19 @@ void main() { ProcessManager: () => mockProcessManager, }); + testUsingContext('single dart compile abnormally terminates', () async { + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => const Stream>.empty() + ); + + final String output = await generator.recompile( + '/path/to/main.dart', null /* invalidatedFiles */ + ); + expect(output, equals(null)); + }, overrides: { + ProcessManager: () => mockProcessManager, + }); + testUsingContext('compile and recompile', () async { final BufferLogger logger = context[Logger];