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

add daemon command to enumerate supported platforms (#33472)

parent 2cb5b24b
......@@ -60,6 +60,17 @@ The `version()` command responds with a String with the protocol version.
The `shutdown()` command will terminate the flutter daemon. It is not necessary to call this before shutting down the daemon; it is perfectly acceptable to just kill the daemon process.
### daemon.getSupportedPlatforms
The `getSupportedPlatforms()` command will enumerate all platforms supported by the project located at the provided `projectRoot`. It returns a Map with the key 'platforms' containing a List of strings which describe the set of all possibly supported platforms. Possible values include:
- android
- ios
- linux #experimental
- macos #experimental
- windows #experimental
- fuchsia #experimental
- web #experimental
#### Events
#### daemon.connected
......
......@@ -248,6 +248,7 @@ class DaemonDomain extends Domain {
DaemonDomain(Daemon daemon) : super(daemon, 'daemon') {
registerHandler('version', version);
registerHandler('shutdown', shutdown);
registerHandler('getSupportedPlatforms', getSupportedPlatforms);
sendEvent(
'daemon.connected',
......@@ -300,6 +301,59 @@ class DaemonDomain extends Domain {
void dispose() {
_subscription?.cancel();
}
/// Enumerates the platforms supported by the provided project.
///
/// This does not filter based on the current workflow restrictions, such
/// as whether command line tools are installed or whether the host platform
/// is correct.
Future<Map<String, Object>> getSupportedPlatforms(Map<String, dynamic> args) async {
final String projectRoot = _getStringArg(args, 'projectRoot', required: true);
final List<String> result = <String>[];
try {
// TODO(jonahwilliams): replace this with a project metadata check once
// that has been implemented.
final FlutterProject flutterProject = FlutterProject.fromDirectory(fs.directory(projectRoot));
if (flutterProject.linux.existsSync()) {
result.add('linux');
}
if (flutterProject.macos.existsSync()) {
result.add('macos');
}
if (flutterProject.windows.existsSync()) {
result.add('windows');
}
if (flutterProject.ios.existsSync()) {
result.add('ios');
}
if (flutterProject.android.existsSync()) {
result.add('android');
}
if (flutterProject.web.existsSync()) {
result.add('web');
}
if (flutterProject.fuchsia.existsSync()) {
result.add('fuchsia');
}
return <String, Object>{
'platforms': result,
};
} catch (err, stackTrace) {
sendEvent('log', <String, dynamic>{
'log': 'Failed to parse project metadata',
'stackTrace': stackTrace.toString(),
'error': true,
});
// On any sort of failure, fall back to Android and iOS for backwards
// comparability.
return <String, Object>{
'platforms': <String>[
'android',
'ios',
],
};
}
}
}
typedef _RunOrAttach = Future<void> Function({
......
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