mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
[flutter_tools] add vm service method to pull SkSL (#57813)
This commit is contained in:
parent
f640ad6914
commit
600338286f
|
@ -186,6 +186,7 @@ class FlutterDevice {
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
}) {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
StreamSubscription<void> subscription;
|
||||
|
@ -204,6 +205,7 @@ class FlutterDevice {
|
|||
restart: restart,
|
||||
compileExpression: compileExpression,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: getSkSLMethod,
|
||||
device: device,
|
||||
);
|
||||
} on Exception catch (exception) {
|
||||
|
@ -853,7 +855,9 @@ abstract class ResidentRunner {
|
|||
}
|
||||
|
||||
/// Write the SkSL shaders to a zip file in build directory.
|
||||
Future<void> writeSkSL() async {
|
||||
///
|
||||
/// Returns the name of the file, or `null` on failures.
|
||||
Future<String> writeSkSL() async {
|
||||
if (!supportsWriteSkSL) {
|
||||
throw Exception('writeSkSL is not supported by this runner.');
|
||||
}
|
||||
|
@ -870,7 +874,7 @@ abstract class ResidentRunner {
|
|||
' 1. Pass "--cache-sksl" as an argument to flutter run.\n'
|
||||
' 2. Interact with the application to force shaders to be compiled.\n'
|
||||
);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final File outputFile = globals.fsUtils.getUniqueFile(
|
||||
globals.fs.currentDirectory,
|
||||
|
@ -899,6 +903,7 @@ abstract class ResidentRunner {
|
|||
};
|
||||
outputFile.writeAsStringSync(json.encode(manifest));
|
||||
globals.logger.printStatus('Wrote SkSL data to ${outputFile.path}.');
|
||||
return outputFile.path;
|
||||
}
|
||||
|
||||
/// The resident runner API for interaction with the reloadMethod vmservice
|
||||
|
@ -1103,6 +1108,7 @@ abstract class ResidentRunner {
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
}) async {
|
||||
if (!debuggingOptions.debuggingEnabled) {
|
||||
throw 'The service protocol is not enabled.';
|
||||
|
@ -1115,6 +1121,7 @@ abstract class ResidentRunner {
|
|||
restart: restart,
|
||||
compileExpression: compileExpression,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: getSkSLMethod
|
||||
);
|
||||
// This will wait for at least one flutter view before returning.
|
||||
final Status status = globals.logger.startProgress(
|
||||
|
|
|
@ -129,7 +129,9 @@ class ColdRunner extends ResidentRunner {
|
|||
}) async {
|
||||
_didAttach = true;
|
||||
try {
|
||||
await connectToServiceProtocol();
|
||||
await connectToServiceProtocol(
|
||||
getSkSLMethod: writeSkSL,
|
||||
);
|
||||
} on Exception catch (error) {
|
||||
globals.printError('Error connecting to the service protocol: $error');
|
||||
// https://github.com/flutter/flutter/issues/33050
|
||||
|
|
|
@ -225,6 +225,7 @@ class HotRunner extends ResidentRunner {
|
|||
restart: _restartService,
|
||||
compileExpression: _compileExpressionService,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: writeSkSL,
|
||||
);
|
||||
// Catches all exceptions, non-Exception objects are rethrown.
|
||||
} catch (error) { // ignore: avoid_catches_without_on_clauses
|
||||
|
|
|
@ -81,6 +81,12 @@ typedef ReloadMethod = Future<void> Function({
|
|||
String libraryId,
|
||||
});
|
||||
|
||||
|
||||
/// A method that pulls an SkSL shader from the device and writes it to a file.
|
||||
///
|
||||
/// The name of the file returned as a result.
|
||||
typedef GetSkSLMethod = Future<String> Function();
|
||||
|
||||
Future<io.WebSocket> _defaultOpenChannel(String url, {
|
||||
io.CompressionOptions compression = io.CompressionOptions.compressionDefault
|
||||
}) async {
|
||||
|
@ -139,6 +145,7 @@ typedef VMServiceConnector = Future<vm_service.VmService> Function(Uri httpUri,
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
io.CompressionOptions compression,
|
||||
Device device,
|
||||
});
|
||||
|
@ -164,6 +171,7 @@ vm_service.VmService setUpVmService(
|
|||
CompileExpression compileExpression,
|
||||
Device device,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod skSLMethod,
|
||||
vm_service.VmService vmService
|
||||
) {
|
||||
if (reloadSources != null) {
|
||||
|
@ -270,6 +278,18 @@ vm_service.VmService setUpVmService(
|
|||
});
|
||||
vmService.registerService('flutterMemoryInfo', 'Flutter Tools');
|
||||
}
|
||||
if (skSLMethod != null) {
|
||||
vmService.registerServiceCallback('flutterGetSkSL', (Map<String, dynamic> params) async {
|
||||
final String filename = await skSLMethod();
|
||||
return <String, dynamic>{
|
||||
'result': <String, Object>{
|
||||
'type': 'Success',
|
||||
'filename': filename,
|
||||
}
|
||||
};
|
||||
});
|
||||
vmService.registerService('flutterGetSkSL', 'Flutter Tools');
|
||||
}
|
||||
return vmService;
|
||||
}
|
||||
|
||||
|
@ -287,6 +307,7 @@ Future<vm_service.VmService> connectToVmService(
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
io.CompressionOptions compression = io.CompressionOptions.compressionDefault,
|
||||
Device device,
|
||||
}) async {
|
||||
|
@ -298,6 +319,7 @@ Future<vm_service.VmService> connectToVmService(
|
|||
compression: compression,
|
||||
device: device,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: getSkSLMethod,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -307,6 +329,7 @@ Future<vm_service.VmService> _connect(
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
io.CompressionOptions compression = io.CompressionOptions.compressionDefault,
|
||||
Device device,
|
||||
}) async {
|
||||
|
@ -333,6 +356,7 @@ Future<vm_service.VmService> _connect(
|
|||
compileExpression,
|
||||
device,
|
||||
reloadMethod,
|
||||
getSkSLMethod,
|
||||
delegateService,
|
||||
);
|
||||
_httpAddressExpando[service] = httpUri;
|
||||
|
|
|
@ -678,6 +678,7 @@ VMServiceConnector getFakeVmServiceFactory({
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
CompressionOptions compression,
|
||||
Device device,
|
||||
}) async {
|
||||
|
|
|
@ -184,6 +184,7 @@ class TestFlutterDevice extends FlutterDevice {
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
}) async {
|
||||
throw exception;
|
||||
}
|
||||
|
|
|
@ -541,6 +541,7 @@ class TestFlutterDevice extends FlutterDevice {
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
}) async {
|
||||
throw exception;
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ void main() {
|
|||
reloadSources: anyNamed('reloadSources'),
|
||||
restart: anyNamed('restart'),
|
||||
compileExpression: anyNamed('compileExpression'),
|
||||
getSkSLMethod: anyNamed('getSkSLMethod'),
|
||||
)).thenAnswer((Invocation invocation) async { });
|
||||
when(mockFlutterDevice.setupDevFS(any, any, packagesFilePath: anyNamed('packagesFilePath')))
|
||||
.thenAnswer((Invocation invocation) async {
|
||||
|
@ -1191,6 +1192,7 @@ void main() {
|
|||
Restart restart,
|
||||
CompileExpression compileExpression,
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
io.CompressionOptions compression,
|
||||
Device device,
|
||||
}) async => mockVMService,
|
||||
|
|
|
@ -103,6 +103,7 @@ void main() {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
mockVMService,
|
||||
);
|
||||
|
||||
|
@ -121,6 +122,7 @@ void main() {
|
|||
null,
|
||||
null,
|
||||
reloadMethod,
|
||||
null,
|
||||
mockVMService,
|
||||
);
|
||||
|
||||
|
@ -139,6 +141,7 @@ void main() {
|
|||
null,
|
||||
mockDevice,
|
||||
null,
|
||||
null,
|
||||
mockVMService,
|
||||
);
|
||||
|
||||
|
@ -147,6 +150,23 @@ void main() {
|
|||
Logger: () => BufferLogger.test()
|
||||
});
|
||||
|
||||
testUsingContext('VmService registers flutterGetSkSL service', () async {
|
||||
final MockVMService mockVMService = MockVMService();
|
||||
setUpVmService(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
() async => 'hello',
|
||||
mockVMService,
|
||||
);
|
||||
|
||||
verify(mockVMService.registerService('flutterGetSkSL', 'Flutter Tools')).called(1);
|
||||
}, overrides: <Type, Generator>{
|
||||
Logger: () => BufferLogger.test()
|
||||
});
|
||||
|
||||
testUsingContext('VMService returns correct FlutterVersion', () async {
|
||||
final MockVMService mockVMService = MockVMService();
|
||||
setUpVmService(
|
||||
|
@ -155,6 +175,7 @@ void main() {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
mockVMService,
|
||||
);
|
||||
|
||||
|
|
|
@ -82,6 +82,12 @@ void main() {
|
|||
expect(response, throwsA(const TypeMatcher<RPCError>()));
|
||||
});
|
||||
|
||||
test('flutterGetSkSL can be called', () async {
|
||||
final Response response = await vmService.callMethod('s0.flutterGetSkSL');
|
||||
|
||||
expect(response.type, 'Success');
|
||||
});
|
||||
|
||||
// TODO(devoncarew): These tests fail on cirrus-ci windows.
|
||||
}, skip: Platform.isWindows);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue