From f38ee15286bd7e652d5dda360e06018ce9e8faf7 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 30 May 2019 10:14:23 -0700 Subject: [PATCH] add daemon command to enumerate supported platforms (#33472) --- packages/flutter_tools/doc/daemon.md | 11 ++++ .../lib/src/commands/daemon.dart | 54 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/packages/flutter_tools/doc/daemon.md b/packages/flutter_tools/doc/daemon.md index aa94ba4751..0df93762aa 100644 --- a/packages/flutter_tools/doc/daemon.md +++ b/packages/flutter_tools/doc/daemon.md @@ -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 diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 0071cd5fad..9283e4ff0d 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -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> getSupportedPlatforms(Map args) async { + final String projectRoot = _getStringArg(args, 'projectRoot', required: true); + final List result = []; + 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 { + 'platforms': result, + }; + } catch (err, stackTrace) { + sendEvent('log', { + '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 { + 'platforms': [ + 'android', + 'ios', + ], + }; + } + } } typedef _RunOrAttach = Future Function({