Unverified Commit 583db838 authored by Lau Ching Jun's avatar Lau Ching Jun Committed by GitHub

request.mainUri should be fileUri (#68329)

parent 198e40c9
......@@ -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());
......
......@@ -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<Uri> updatedUris = <Uri>[
mainUri,
Uri.parse('file:///foo/bar/fizz/other.dart'),
];
const List<String> expectedUpdatedUris = <String>[
expectedMainUri,
'scheme:///other.dart',
];
final StreamController<List<int>> streamController = StreamController<List<int>>();
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<void> _recompile(
String mockCompilerOutput, {
bool suppressErrors = false,
Uri mainUri,
String expectedUri = '/path/to/main.dart',
String expectedMainUri = '/path/to/main.dart',
List<Uri> updatedUris,
List<String> expectedUpdatedUris,
}) async {
mainUri ??= Uri.parse('/path/to/main.dart');
updatedUris ??= <Uri>[mainUri];
expectedUpdatedUris ??= <String>[expectedMainUri];
// Put content into the output stream after generator.recompile gets
// going few lines below, resets completer.
......@@ -302,7 +362,7 @@ Future<void> _recompile(
});
final CompilerOutput output = await generator.recompile(
mainUri,
<Uri>[mainUri],
updatedUris,
outputPath: '/build/',
packageConfig: PackageConfig.empty,
suppressErrors: suppressErrors,
......@@ -313,8 +373,11 @@ Future<void> _recompile(
final List<String> 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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment