Skip to content

Commit 583db83

Browse files
authored
request.mainUri should be fileUri (flutter#68329)
1 parent 198e40c commit 583db83

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

packages/flutter_tools/lib/src/compile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
600600
message = fileUri.toString();
601601
} else {
602602
message = request.packageConfig.toPackageUri(fileUri)?.toString() ??
603-
toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
603+
toMultiRootPath(fileUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
604604
}
605605
_server.stdin.writeln(message);
606606
_logger.printTrace(message.toString());

packages/flutter_tools/test/general.shard/compile_incremental_test.dart

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,70 @@ void main() {
199199
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
200200
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
201201
mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'),
202-
expectedUri: 'scheme:///main.dart');
202+
expectedMainUri: 'scheme:///main.dart');
203203

204204
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$');
205205

206206
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
207207
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
208208
mainUri: Uri.parse('file:///foo/bar/fizz/main.dart'),
209-
expectedUri: 'scheme:///main.dart');
209+
expectedMainUri: 'scheme:///main.dart');
210+
// No sources returned from reject command.
211+
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n',
212+
r'^reject\n$');
213+
verifyNoMoreInteractions(mockFrontendServerStdIn);
214+
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
215+
expect(testLogger.errorText, equals(
216+
'line0\nline1\n'
217+
'line1\nline2\n'
218+
'line1\nline2\n'
219+
));
220+
});
221+
222+
testWithoutContext('incremental compile and recompile non-entrypoint file with filesystem scheme', () async {
223+
final Uri mainUri = Uri.parse('file:///foo/bar/fizz/main.dart');
224+
const String expectedMainUri = 'scheme:///main.dart';
225+
final List<Uri> updatedUris = <Uri>[
226+
mainUri,
227+
Uri.parse('file:///foo/bar/fizz/other.dart'),
228+
];
229+
const List<String> expectedUpdatedUris = <String>[
230+
expectedMainUri,
231+
'scheme:///other.dart',
232+
];
233+
234+
final StreamController<List<int>> streamController = StreamController<List<int>>();
235+
when(mockFrontendServer.stdout)
236+
.thenAnswer((Invocation invocation) => streamController.stream);
237+
streamController.add(utf8.encode('result abc\nline0\nline1\nabc\nabc /path/to/main.dart.dill 0\n'));
238+
await generatorWithScheme.recompile(
239+
Uri.parse('file:///foo/bar/fizz/main.dart'),
240+
null, /* invalidatedFiles */
241+
outputPath: '/build/',
242+
packageConfig: PackageConfig.empty,
243+
);
244+
expect(mockFrontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
245+
246+
// No accept or reject commands should be issued until we
247+
// send recompile request.
248+
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, '');
249+
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, '', '');
250+
251+
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
252+
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
253+
mainUri: mainUri,
254+
expectedMainUri: expectedMainUri,
255+
updatedUris: updatedUris,
256+
expectedUpdatedUris: expectedUpdatedUris);
257+
258+
await _accept(streamController, generatorWithScheme, mockFrontendServerStdIn, r'^accept\n$');
259+
260+
await _recompile(streamController, generatorWithScheme, mockFrontendServerStdIn,
261+
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0\n',
262+
mainUri: mainUri,
263+
expectedMainUri: expectedMainUri,
264+
updatedUris: updatedUris,
265+
expectedUpdatedUris: expectedUpdatedUris);
210266
// No sources returned from reject command.
211267
await _reject(streamController, generatorWithScheme, mockFrontendServerStdIn, 'result abc\nabc\n',
212268
r'^reject\n$');
@@ -291,9 +347,13 @@ Future<void> _recompile(
291347
String mockCompilerOutput, {
292348
bool suppressErrors = false,
293349
Uri mainUri,
294-
String expectedUri = '/path/to/main.dart',
350+
String expectedMainUri = '/path/to/main.dart',
351+
List<Uri> updatedUris,
352+
List<String> expectedUpdatedUris,
295353
}) async {
296354
mainUri ??= Uri.parse('/path/to/main.dart');
355+
updatedUris ??= <Uri>[mainUri];
356+
expectedUpdatedUris ??= <String>[expectedMainUri];
297357

298358
// Put content into the output stream after generator.recompile gets
299359
// going few lines below, resets completer.
@@ -302,7 +362,7 @@ Future<void> _recompile(
302362
});
303363
final CompilerOutput output = await generator.recompile(
304364
mainUri,
305-
<Uri>[mainUri],
365+
updatedUris,
306366
outputPath: '/build/',
307367
packageConfig: PackageConfig.empty,
308368
suppressErrors: suppressErrors,
@@ -313,8 +373,11 @@ Future<void> _recompile(
313373
final List<String> parts = commands.split(whitespace);
314374

315375
// Test that uuid matches at beginning and end.
316-
expect(parts[2], equals(parts[4]));
317-
expect(parts[1], equals(expectedUri));
376+
expect(parts[2], equals(parts[3 + updatedUris.length]));
377+
expect(parts[1], equals(expectedMainUri));
378+
for (int i = 0; i < expectedUpdatedUris.length; i++) {
379+
expect(parts[3 + i], equals(expectedUpdatedUris[i]));
380+
}
318381
mockFrontendServerStdIn.stdInWrites.clear();
319382
}
320383

0 commit comments

Comments
 (0)