diff --git a/bin/internal/engine.version b/bin/internal/engine.version index f948993ba8f..ecee599fe8d 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -8a6e64a8ef09f1f1af207725b40022d8d7a9dcd7 +76cb311d9c33720dcd19274228b39ecdbad8d9af diff --git a/dev/bots/analyze-sample-code.dart b/dev/bots/analyze-sample-code.dart index 4b46108bf53..c27adb50aa0 100644 --- a/dev/bots/analyze-sample-code.dart +++ b/dev/bots/analyze-sample-code.dart @@ -238,8 +238,14 @@ dependencies: throw 'failed to parse error message: $error'; } final String column = error.substring(colon2 + kColon.length, bullet2); - final int lineNumber = int.parse(line, radix: 10, onError: (String source) => throw 'failed to parse error message: $error'); - final int columnNumber = int.parse(column, radix: 10, onError: (String source) => throw 'failed to parse error message: $error'); + final int lineNumber = int.tryParse(line, radix: 10); + if (lineNumber == null) { + throw 'failed to parse error message: $error'; + } + final int columnNumber = int.tryParse(column, radix: 10); + if (columnNumber == null) { + throw 'failed to parse error message: $error'; + } if (lineNumber < 1 || lineNumber > lines.length) { keepMain = true; throw 'failed to parse error message (read line number as $lineNumber; total number of lines is ${lines.length}): $error'; diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 0fbbf76d3dd..f96eda93cfc 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -210,7 +210,7 @@ class AndroidDevice extends Device { // Sample output: '22' final String sdkVersion = await _getProperty('ro.build.version.sdk'); - final int sdkVersionParsed = int.parse(sdkVersion, onError: (String source) => null); + final int sdkVersionParsed = int.tryParse(sdkVersion); if (sdkVersionParsed == null) { printError('Unexpected response from getprop: "$sdkVersion"'); return false; @@ -817,7 +817,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder { final AndroidDevice device; static int _extractPort(String portString) { - return int.parse(portString.trim(), onError: (_) => null); + return int.tryParse(portString.trim()); } @override diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index 3d7d392c531..0a5e18a2a21 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -105,7 +105,7 @@ Future build({ String kernelBinaryFilename; if (needBuild) { ensureDirectoryExists(applicationKernelFilePath); - kernelBinaryFilename = await compile( + final CompilerOutput compilerOutput = await compile( sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()), mainPath: fs.file(mainPath).absolute.path, @@ -116,6 +116,7 @@ Future build({ fileSystemScheme: fileSystemScheme, packagesPath: packagesPath, ); + kernelBinaryFilename = compilerOutput?.outputFilename; if (kernelBinaryFilename == null) { throwToolExit('Compiler failed on $mainPath'); } diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart index 61485506718..7f82d3a65eb 100644 --- a/packages/flutter_tools/lib/src/commands/build_aot.dart +++ b/packages/flutter_tools/lib/src/commands/build_aot.dart @@ -387,7 +387,7 @@ Future _buildAotSnapshot( } if (previewDart2) { - mainPath = await compile( + final CompilerOutput compilerOutput = await compile( sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), mainPath: mainPath, outputFilePath: kApplicationKernelPath, @@ -398,6 +398,7 @@ Future _buildAotSnapshot( entryPointsJsonFiles: entryPointsJsonFiles, trackWidgetCreation: false, ); + mainPath = compilerOutput?.outputFilename; if (mainPath == null) { printError('Compiler terminated unexpectedly.'); return null; diff --git a/packages/flutter_tools/lib/src/commands/fuchsia_reload.dart b/packages/flutter_tools/lib/src/commands/fuchsia_reload.dart index 6e31feebc15..88507820762 100644 --- a/packages/flutter_tools/lib/src/commands/fuchsia_reload.dart +++ b/packages/flutter_tools/lib/src/commands/fuchsia_reload.dart @@ -384,7 +384,7 @@ class FuchsiaReloadCommand extends FlutterCommand { final int lastSpace = trimmed.lastIndexOf(' '); final String lastWord = trimmed.substring(lastSpace + 1); if ((lastWord != '.') && (lastWord != '..')) { - final int value = int.parse(lastWord, onError: (_) => null); + final int value = int.tryParse(lastWord); if (value != null) ports.add(value); } diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart index 9d377a2b5ed..6ea4d410f70 100644 --- a/packages/flutter_tools/lib/src/commands/update_packages.dart +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -784,7 +784,7 @@ class PubspecChecksum extends PubspecLine { if (twoLines.length != 2) { return new PubspecChecksum(-1, line); } - final int value = int.parse(twoLines.last.trim(), radix: 16, onError: (String _) => -1); + final int value = int.tryParse(twoLines.last.trim(), radix: 16) ?? -1; return new PubspecChecksum(value, line); } } diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 338c001df73..4e3d3baf4a0 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -15,6 +15,13 @@ import 'globals.dart'; typedef void CompilerMessageConsumer(String message); +class CompilerOutput { + String outputFilename; + int errorCount; + + CompilerOutput(this.outputFilename, this.errorCount); +} + class _StdoutHandler { _StdoutHandler({this.consumer: printError}) { reset(); @@ -22,17 +29,24 @@ class _StdoutHandler { final CompilerMessageConsumer consumer; String boundaryKey; - Completer outputFilename; + Completer compilerOutput; void handler(String string) { const String kResultPrefix = 'result '; if (boundaryKey == null) { if (string.startsWith(kResultPrefix)) boundaryKey = string.substring(kResultPrefix.length); - } else if (string.startsWith(boundaryKey)) - outputFilename.complete(string.length > boundaryKey.length - ? string.substring(boundaryKey.length + 1) - : null); + } else if (string.startsWith(boundaryKey)) { + if (string.length <= boundaryKey.length) { + compilerOutput.complete(null); + return; + } + final int spaceDelimiter = string.lastIndexOf(' '); + compilerOutput.complete( + new CompilerOutput( + string.substring(boundaryKey.length + 1, spaceDelimiter), + int.parse(string.substring(spaceDelimiter + 1).trim()))); + } else consumer('compiler message: $string'); } @@ -41,11 +55,11 @@ class _StdoutHandler { // with its own boundary key and new completer. void reset() { boundaryKey = null; - outputFilename = new Completer(); + compilerOutput = new Completer(); } } -Future compile( +Future compile( {String sdkRoot, String mainPath, String outputFilePath, @@ -132,7 +146,7 @@ Future compile( .transform(const LineSplitter()) .listen(stdoutHandler.handler); final int exitCode = await server.exitCode; - return exitCode == 0 ? stdoutHandler.outputFilename.future : null; + return exitCode == 0 ? stdoutHandler.compilerOutput.future : null; } /// Wrapper around incremental frontend server compiler, that communicates with @@ -170,7 +184,7 @@ class ResidentCompiler { /// point that is used for recompilation. /// Binary file name is returned if compilation was successful, otherwise /// null is returned. - Future recompile(String mainPath, List invalidatedFiles, + Future recompile(String mainPath, List invalidatedFiles, {String outputPath, String packagesFilePath}) async { stdoutHandler.reset(); @@ -186,10 +200,11 @@ class ResidentCompiler { } _server.stdin.writeln(inputKey); - return stdoutHandler.outputFilename.future; + return stdoutHandler.compilerOutput.future; } - Future _compile(String scriptFilename, String outputPath, String packagesFilePath) async { + Future _compile(String scriptFilename, String outputPath, + String packagesFilePath) async { final String frontendServer = artifacts.getArtifactPath( Artifact.frontendServerSnapshotForEngineDartSdk ); @@ -231,8 +246,8 @@ class ResidentCompiler { onDone: () { // when outputFilename future is not completed, but stdout is closed // process has died unexpectedly. - if (!stdoutHandler.outputFilename.isCompleted) { - stdoutHandler.outputFilename.complete(null); + if (!stdoutHandler.compilerOutput.isCompleted) { + stdoutHandler.compilerOutput.complete(null); } }); @@ -243,7 +258,7 @@ class ResidentCompiler { _server.stdin.writeln('compile $scriptFilename'); - return stdoutHandler.outputFilename.future; + return stdoutHandler.compilerOutput.future; } diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index c07eea05445..ce9e6e8036d 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -501,10 +501,11 @@ class DevFS { if (fullRestart) { generator.reset(); } - final String compiledBinary = + final CompilerOutput compilerOutput = await generator.recompile(mainPath, invalidatedFiles, outputPath: dillOutputPath ?? fs.path.join(getBuildDirectory(), 'app.dill'), packagesFilePath : _packagesFilePath); + final String compiledBinary = compilerOutput?.outputFilename; if (compiledBinary != null && compiledBinary.isNotEmpty) { final String entryUri = projectRootPath != null ? fs.path.relative(mainPath, from: projectRootPath): diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 32ae8b93432..7c0ca7a8f8d 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -143,10 +143,13 @@ class _Compiler { printTrace('Compiling ${request.path}'); compiler ??= createCompiler(); suppressOutput = false; - final String outputPath = await handleTimeout(compiler.recompile(request.path, - [request.path], - outputPath: outputDill.path, - ), request.path); + final CompilerOutput compilerOutput = await handleTimeout( + compiler.recompile( + request.path, + [request.path], + outputPath: outputDill.path), + request.path); + final String outputPath = compilerOutput?.outputFilename; // Check if the compiler produced the output. If it failed then // outputPath would be null. In this case pass null upwards to the @@ -179,7 +182,7 @@ class _Compiler { Future compile(String mainDart) { final Completer completer = new Completer(); compilerController.add(new _CompilationRequest(mainDart, completer)); - return handleTimeout(completer.future, mainDart); + return handleTimeout(completer.future, mainDart); } Future shutdown() async { @@ -187,7 +190,7 @@ class _Compiler { compiler = null; } - static Future handleTimeout(Future value, String path) { + static Future handleTimeout(Future value, String path) { return value.timeout(const Duration(minutes: 5), onTimeout: () { printError('Compilation of $path timed out after 5 minutes.'); return null; diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 7e889045c6c..ec05da46e2b 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -499,7 +499,7 @@ class GitTagVersion { return const GitTagVersion.unknown(); } final List parsedParts = parts.take(4).map( - (String value) => int.parse(value, onError: (String value) => null), + (String value) => int.tryParse(value), ).toList(); return new GitTagVersion(parsedParts[0], parsedParts[1], parsedParts[2], parsedParts[3], parts[4]); } diff --git a/packages/flutter_tools/test/compile_test.dart b/packages/flutter_tools/test/compile_test.dart index f50578993cb..f5931e0a8da 100644 --- a/packages/flutter_tools/test/compile_test.dart +++ b/packages/flutter_tools/test/compile_test.dart @@ -43,15 +43,15 @@ void main() { when(mockFrontendServer.stdout) .thenAnswer((Invocation invocation) => new Stream>.fromFuture( new Future>.value(utf8.encode( - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill 0' )) )); - final String output = await compile(sdkRoot: '/path/to/sdkroot', + final CompilerOutput 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('/path/to/main.dart.dill')); + expect(output.outputFilename, equals('/path/to/main.dart.dill')); }, overrides: { ProcessManager: () => mockProcessManager, }); @@ -66,7 +66,7 @@ void main() { )) )); - final String output = await compile(sdkRoot: '/path/to/sdkroot', + final CompilerOutput output = await compile(sdkRoot: '/path/to/sdkroot', mainPath: '/path/to/main.dart' ); expect(mockFrontendServerStdIn.getAndClear(), isEmpty); @@ -88,7 +88,7 @@ void main() { )) )); - final String output = await compile(sdkRoot: '/path/to/sdkroot', + final CompilerOutput output = await compile(sdkRoot: '/path/to/sdkroot', mainPath: '/path/to/main.dart' ); expect(mockFrontendServerStdIn.getAndClear(), isEmpty); @@ -137,17 +137,17 @@ void main() { when(mockFrontendServer.stdout) .thenAnswer((Invocation invocation) => new Stream>.fromFuture( new Future>.value(utf8.encode( - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill' + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill 0' )) )); - final String output = await generator.recompile( + final CompilerOutput output = await generator.recompile( '/path/to/main.dart', null /* invalidatedFiles */ ); expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n'); verifyNoMoreInteractions(mockFrontendServerStdIn); expect(logger.errorText, equals('compiler message: line1\ncompiler message: line2\n')); - expect(output, equals('/path/to/main.dart.dill')); + expect(output.outputFilename, equals('/path/to/main.dart.dill')); }, overrides: { ProcessManager: () => mockProcessManager, }); @@ -157,7 +157,7 @@ void main() { .thenAnswer((Invocation invocation) => const Stream>.empty() ); - final String output = await generator.recompile( + final CompilerOutput output = await generator.recompile( '/path/to/main.dart', null /* invalidatedFiles */ ); expect(output, equals(null)); @@ -171,12 +171,12 @@ void main() { final StreamController> streamController = new StreamController>(); when(mockFrontendServer.stdout) .thenAnswer((Invocation invocation) => streamController.stream); - streamController.add(utf8.encode('result abc\nline0\nline1\nabc /path/to/main.dart.dill\n')); + streamController.add(utf8.encode('result abc\nline0\nline1\nabc /path/to/main.dart.dill 0\n')); await generator.recompile('/path/to/main.dart', null /* invalidatedFiles */); expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n'); await _recompile(streamController, generator, mockFrontendServerStdIn, - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill\n'); + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill 0\n'); verifyNoMoreInteractions(mockFrontendServerStdIn); expect(mockFrontendServerStdIn.getAndClear(), isEmpty); @@ -195,15 +195,15 @@ void main() { when(mockFrontendServer.stdout) .thenAnswer((Invocation invocation) => streamController.stream); streamController.add(utf8.encode( - 'result abc\nline0\nline1\nabc /path/to/main.dart.dill\n' + 'result abc\nline0\nline1\nabc /path/to/main.dart.dill 0\n' )); await generator.recompile('/path/to/main.dart', null /* invalidatedFiles */); expect(mockFrontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n'); await _recompile(streamController, generator, mockFrontendServerStdIn, - 'result abc\nline1\nline2\nabc /path/to/main.dart.dill\n'); + 'result abc\nline1\nline2\nabc /path/to/main.dart.dill 0\n'); await _recompile(streamController, generator, mockFrontendServerStdIn, - 'result abc\nline2\nline3\nabc /path/to/main.dart.dill\n'); + 'result abc\nline2\nline3\nabc /path/to/main.dart.dill 0\n'); verifyNoMoreInteractions(mockFrontendServerStdIn); expect(mockFrontendServerStdIn.getAndClear(), isEmpty); @@ -226,8 +226,8 @@ Future _recompile(StreamController> streamController, new Future>(() { streamController.add(utf8.encode(mockCompilerOutput)); }); - final String output = await generator.recompile(null /* mainPath */, ['/path/to/main.dart']); - expect(output, equals('/path/to/main.dart.dill')); + final CompilerOutput output = await generator.recompile(null /* mainPath */, ['/path/to/main.dart']); + expect(output.outputFilename, equals('/path/to/main.dart.dill')); final String commands = mockFrontendServerStdIn.getAndClear(); final RegExp re = new RegExp('^recompile (.*)\\n/path/to/main.dart\\n(.*)\\n\$'); expect(commands, matches(re)); diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart index ce2d51d2377..195321a37c6 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart @@ -197,7 +197,7 @@ class FuchsiaRemoteConnection { final int lastSpace = trimmed.lastIndexOf(' '); final String lastWord = trimmed.substring(lastSpace + 1); if ((lastWord != '.') && (lastWord != '..')) { - final int value = int.parse(lastWord, onError: (_) => null); + final int value = int.tryParse(lastWord); if (value != null) { ports.add(value); }