diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 4058e6785a..62a177df5a 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -600,7 +600,7 @@ class DefaultResidentCompiler implements ResidentCompiler { message = fileUri.toString(); } else { message = request.packageConfig.toPackageUri(fileUri)?.toString() ?? - toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows); + toMultiRootPath(fileUri, fileSystemScheme, fileSystemRoots, _platform.isWindows); } _server.stdin.writeln(message); _logger.printTrace(message.toString()); diff --git a/packages/flutter_tools/test/general.shard/compile_incremental_test.dart b/packages/flutter_tools/test/general.shard/compile_incremental_test.dart index 4652cfb54f..48f12eb9cc 100644 --- a/packages/flutter_tools/test/general.shard/compile_incremental_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_incremental_test.dart @@ -199,14 +199,70 @@ void main() { await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n', mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'), - expectedUri: 'scheme:///main.dart'); + expectedMainUri: 'scheme:///main.dart'); await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$'); await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n', mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'), - expectedUri: 'scheme:///main.dart'); + expectedMainUri: 'scheme:///main.dart'); + // No sources returned from reject command. + await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n', + r'^reject\n$'); + verifyNoMoreInteractions(mockFrontendServerStdIn); + expect(mockFrontendServerStdIn.getAndClear(), isEmpty); + expect(testLogger.errorText, equals( + 'line0\nline1\n' + 'line1\nline2\n' + 'line1\nline2\n' + )); + }); + + testWithoutContext('incremental compile and recompile non-entrypoint file with filesystem scheme', () async { + final Uri mainUri = Uri.parse('file:///foo/bar/fizz/main.dart'); + const String expectedMainUri = 'scheme:///main.dart'; + final List updatedUris = [ + mainUri, + Uri.parse('file:///foo/bar/fizz/other.dart'), + ]; + const List expectedUpdatedUris = [ + expectedMainUri, + 'scheme:///other.dart', + ]; + + final StreamController> streamController = StreamController>(); + when(mockFrontendServer.stdout) + .thenAnswer((Invocation invocation) => streamController.stream); + streamController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n')); + await generatorWithScheme.recompile( + Uri.parse('file:///foo/bar/fizz/main.dart'), + null, /* invalidatedFiles */ + outputPath: '/build/', + packageConfig: PackageConfig.empty, + ); + expect(mockFrontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n'); + + // No accept or reject commands should be issued until we + // send recompile request. + await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, ''); + await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, '', ''); + + await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn, + 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n', + mainUri: mainUri, + expectedMainUri: expectedMainUri, + updatedUris: updatedUris, + expectedUpdatedUris: expectedUpdatedUris); + + await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$'); + + await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn, + 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n', + mainUri: mainUri, + expectedMainUri: expectedMainUri, + updatedUris: updatedUris, + expectedUpdatedUris: expectedUpdatedUris); // No sources returned from reject command. await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n', r'^reject\n$'); @@ -291,9 +347,13 @@ Future _recompile( String mockCompilerOutput, { bool suppressErrors = false, Uri mainUri, - String expectedUri = '/path/to/main.dart', + String expectedMainUri = '/path/to/main.dart', + List updatedUris, + List expectedUpdatedUris, }) async { mainUri ??= Uri.parse('/path/to/main.dart'); + updatedUris ??= [mainUri]; + expectedUpdatedUris ??= [expectedMainUri]; // Put content into the output stream after generator.recompile gets // going few lines below, resets completer. @@ -302,7 +362,7 @@ Future _recompile( }); final CompilerOutput output = await generator.recompile( mainUri, - [mainUri], + updatedUris, outputPath: '/build/', packageConfig: PackageConfig.empty, suppressErrors: suppressErrors, @@ -313,8 +373,11 @@ Future _recompile( final List parts = commands.split(whitespace); // Test that uuid matches at beginning and end. - expect(parts[2], equals(parts[4])); - expect(parts[1], equals(expectedUri)); + expect(parts[2], equals(parts[3 + updatedUris.length])); + expect(parts[1], equals(expectedMainUri)); + for (int i = 0; i < expectedUpdatedUris.length; i++) { + expect(parts[3 + i], equals(expectedUpdatedUris[i])); + } mockFrontendServerStdIn.stdInWrites.clear(); }