mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Use multiroot scheme for initial compilation in ResidentRunner recompile (#68280)
This commit is contained in:
parent
dd93ee301f
commit
3393566b56
@ -584,16 +584,14 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
|||||||
_compileRequestNeedsConfirmation = true;
|
_compileRequestNeedsConfirmation = true;
|
||||||
_stdoutHandler._suppressCompilerMessages = request.suppressErrors;
|
_stdoutHandler._suppressCompilerMessages = request.suppressErrors;
|
||||||
|
|
||||||
if (_server == null) {
|
|
||||||
return _compile(
|
|
||||||
request.packageConfig.toPackageUri(request.mainUri)?.toString() ?? request.mainUri.toString(),
|
|
||||||
request.outputPath,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final String inputKey = Uuid().generateV4();
|
|
||||||
final String mainUri = request.packageConfig.toPackageUri(request.mainUri)?.toString() ??
|
final String mainUri = request.packageConfig.toPackageUri(request.mainUri)?.toString() ??
|
||||||
toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
|
toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
|
||||||
|
|
||||||
|
if (_server == null) {
|
||||||
|
return _compile(mainUri, request.outputPath);
|
||||||
|
}
|
||||||
|
final String inputKey = Uuid().generateV4();
|
||||||
|
|
||||||
_server.stdin.writeln('recompile $mainUri $inputKey');
|
_server.stdin.writeln('recompile $mainUri $inputKey');
|
||||||
_logger.printTrace('<- recompile $mainUri $inputKey');
|
_logger.printTrace('<- recompile $mainUri $inputKey');
|
||||||
for (final Uri fileUri in request.invalidatedFiles) {
|
for (final Uri fileUri in request.invalidatedFiles) {
|
||||||
|
@ -240,7 +240,7 @@ void main() {
|
|||||||
expect(latestCommand, containsAllInOrder(<String>['-DFOO=bar', '-DBAZ=qux']));
|
expect(latestCommand, containsAllInOrder(<String>['-DFOO=bar', '-DBAZ=qux']));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('maps a file to a multiroot scheme if providfed', () async {
|
testWithoutContext('maps a file to a multiroot scheme if provided', () async {
|
||||||
// Use unsuccessful result because it's easier to setup in test. We only care about arguments passed to the compiler.
|
// Use unsuccessful result because it's easier to setup in test. We only care about arguments passed to the compiler.
|
||||||
when(mockFrontendServer.exitCode).thenAnswer((_) async => 255);
|
when(mockFrontendServer.exitCode).thenAnswer((_) async => 255);
|
||||||
when(mockFrontendServer.stdout).thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
when(mockFrontendServer.stdout).thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||||
|
@ -23,6 +23,7 @@ import '../src/mocks.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
ProcessManager mockProcessManager;
|
ProcessManager mockProcessManager;
|
||||||
ResidentCompiler generator;
|
ResidentCompiler generator;
|
||||||
|
ResidentCompiler generatorWithScheme;
|
||||||
MockProcess mockFrontendServer;
|
MockProcess mockFrontendServer;
|
||||||
MockStdIn mockFrontendServerStdIn;
|
MockStdIn mockFrontendServerStdIn;
|
||||||
MockStream mockFrontendServerStdErr;
|
MockStream mockFrontendServerStdErr;
|
||||||
@ -43,6 +44,18 @@ void main() {
|
|||||||
artifacts: Artifacts.test(),
|
artifacts: Artifacts.test(),
|
||||||
platform: FakePlatform(operatingSystem: 'linux'),
|
platform: FakePlatform(operatingSystem: 'linux'),
|
||||||
);
|
);
|
||||||
|
generatorWithScheme = ResidentCompiler(
|
||||||
|
'sdkroot',
|
||||||
|
buildMode: BuildMode.debug,
|
||||||
|
logger: testLogger,
|
||||||
|
processManager: mockProcessManager,
|
||||||
|
artifacts: Artifacts.test(),
|
||||||
|
platform: FakePlatform(operatingSystem: 'linux'),
|
||||||
|
fileSystemRoots: <String>[
|
||||||
|
'/foo/bar/fizz',
|
||||||
|
],
|
||||||
|
fileSystemScheme: 'scheme',
|
||||||
|
);
|
||||||
|
|
||||||
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
||||||
when(mockFrontendServer.stderr)
|
when(mockFrontendServer.stderr)
|
||||||
@ -80,6 +93,26 @@ void main() {
|
|||||||
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWithoutContext('incremental compile single dart compile with filesystem scheme', () async {
|
||||||
|
when(mockFrontendServer.stdout)
|
||||||
|
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||||
|
Future<List<int>>.value(utf8.encode(
|
||||||
|
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
||||||
|
))
|
||||||
|
));
|
||||||
|
|
||||||
|
final CompilerOutput output = 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');
|
||||||
|
verifyNoMoreInteractions(mockFrontendServerStdIn);
|
||||||
|
expect(testLogger.errorText, equals('line1\nline2\n'));
|
||||||
|
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
||||||
|
});
|
||||||
|
|
||||||
testWithoutContext('incremental compile single dart compile abnormally terminates', () async {
|
testWithoutContext('incremental compile single dart compile abnormally terminates', () async {
|
||||||
when(mockFrontendServer.stdout)
|
when(mockFrontendServer.stdout)
|
||||||
.thenAnswer((Invocation invocation) => const Stream<List<int>>.empty()
|
.thenAnswer((Invocation invocation) => const Stream<List<int>>.empty()
|
||||||
@ -145,6 +178,47 @@ void main() {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWithoutContext('incremental compile and recompile with filesystem scheme', () async {
|
||||||
|
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: Uri.parse('file:///foo/bar/fizz/main.dart'),
|
||||||
|
expectedUri: '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');
|
||||||
|
// 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 can suppress errors', () async {
|
testWithoutContext('incremental compile can suppress errors', () async {
|
||||||
final StreamController<List<int>> stdoutController = StreamController<List<int>>();
|
final StreamController<List<int>> stdoutController = StreamController<List<int>>();
|
||||||
when(mockFrontendServer.stdout)
|
when(mockFrontendServer.stdout)
|
||||||
@ -214,17 +288,21 @@ Future<void> _recompile(
|
|||||||
StreamController<List<int>> streamController,
|
StreamController<List<int>> streamController,
|
||||||
ResidentCompiler generator,
|
ResidentCompiler generator,
|
||||||
MockStdIn mockFrontendServerStdIn,
|
MockStdIn mockFrontendServerStdIn,
|
||||||
String mockCompilerOutput,
|
String mockCompilerOutput, {
|
||||||
{ bool suppressErrors = false }
|
bool suppressErrors = false,
|
||||||
) async {
|
Uri mainUri,
|
||||||
|
String expectedUri = '/path/to/main.dart',
|
||||||
|
}) async {
|
||||||
|
mainUri ??= Uri.parse('/path/to/main.dart');
|
||||||
|
|
||||||
// Put content into the output stream after generator.recompile gets
|
// Put content into the output stream after generator.recompile gets
|
||||||
// going few lines below, resets completer.
|
// going few lines below, resets completer.
|
||||||
scheduleMicrotask(() {
|
scheduleMicrotask(() {
|
||||||
streamController.add(utf8.encode(mockCompilerOutput));
|
streamController.add(utf8.encode(mockCompilerOutput));
|
||||||
});
|
});
|
||||||
final CompilerOutput output = await generator.recompile(
|
final CompilerOutput output = await generator.recompile(
|
||||||
Uri.parse('/path/to/main.dart'),
|
mainUri,
|
||||||
<Uri>[Uri.parse('/path/to/main.dart')],
|
<Uri>[mainUri],
|
||||||
outputPath: '/build/',
|
outputPath: '/build/',
|
||||||
packageConfig: PackageConfig.empty,
|
packageConfig: PackageConfig.empty,
|
||||||
suppressErrors: suppressErrors,
|
suppressErrors: suppressErrors,
|
||||||
@ -236,6 +314,7 @@ Future<void> _recompile(
|
|||||||
|
|
||||||
// Test that uuid matches at beginning and end.
|
// Test that uuid matches at beginning and end.
|
||||||
expect(parts[2], equals(parts[4]));
|
expect(parts[2], equals(parts[4]));
|
||||||
|
expect(parts[1], equals(expectedUri));
|
||||||
mockFrontendServerStdIn.stdInWrites.clear();
|
mockFrontendServerStdIn.stdInWrites.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user