Unverified Commit 60033828 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] add vm service method to pull SkSL (#57813)

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