-
Notifications
You must be signed in to change notification settings - Fork 28.7k
implement plugins for custom devices #90958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
4915821
to
75bb480
Compare
7ea7daf
to
a1f785d
Compare
(ping) @christopherfujino |
packages/flutter_tools/lib/src/custom_devices/custom_device.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/lib/src/custom_devices/custom_device.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/lib/src/custom_devices/custom_device_config.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/lib/src/custom_devices/custom_device_config.dart
Outdated
Show resolved
Hide resolved
required String pluginPath, | ||
required FileSystem fileSystem | ||
}) { | ||
assert(validate(yaml)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so asserts don't run in the tool unless you explicitly enable them by editing the shell script entrypoint. should we run this validation always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check in
static List<String> validatePluginYaml(YamlMap? yaml) { |
@stuartmorgan can you review the changes to:
|
custom_devices/custom_device_config.dart: - add 3 new keys: - `embedder`, the name of the embedder - `configureNativeProject` (should basically invoke `cmake` in the native project directory) - `buildNativeProject` (should basically invoke `ninja` in the native project directory) - native project directory is the `x-flutter-pi` subdir of the flutter project directory - (if the embedder is called flutter-pi) - add `-tt` ssh argument on linux and macOS to force a pseudo-terminal (so remote will get a SIGHUP when the host kills ssh, otherwise the embedder won't terminate) - add trailing comma to argument lists custom_devices/custom_device.dart: - add methods for invoking the `configureNativeProject` and `buildNativeProject` commands of the custom device config - check the return value of the postBuildCommand, return LaunchResult.failed() if not successful - check the return value of the installCommand, return LaunchResult.failed() if not successful plugins.dart: - add validation, parsing for pubspec.yaml custom device stuff flutter_plugins.dart: - expand writing of .flutter-plugins-dependencies for custom devices plugins - expand the generated dart plugin registrant for custom devices plugins - for example, the `flutter-pi` variant of a plugin is activated if `-Dflutter.customPlatform=flutter-pi` was given as a dart define, or the `FLUTTER_CUSTOM_PLATFORM` environment variable equals `flutter-pi` (needed for debug mode) - also creating plugin symlinks for custom devices plugins - allow resolving platform interface resolutions for custom devices plugins - add method to find all plugins for custom embedder with a given platform key project.dart: - expand `FlutterProjectFactory` and `FlutterProject` for custom devices support - `FlutterProject.customEmbedderProjects` lists all custom embedder subprojects of this flutter project - to do that, it needs to know which custom embedders are currently configured - it gets that info from the flutter project factory (which just queries the CustomDevicesConfig) - add tests for all the changes - add makeProjectFactory inside test/src/common.dart with creates a project factory with some default arguments, make all tests use that instead of constructing a FlutterProjectFactory themselves packages/flutter_tools/lib/src/custom_devices/custom_device.dart packages/flutter_tools/lib/src/custom_devices/custom_device_config.dart packages/flutter_tools/test/commands.shard/hermetic/custom_devices_test.dart packages/flutter_tools/test/general.shard/android/android_device_test.dart packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart packages/flutter_tools/test/general.shard/crash_reporting_test.dart packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart packages/flutter_tools/test/general.shard/custom_devices/custom_devices_config_test.dart packages/flutter_tools/test/general.shard/custom_devices/custom_devices_plugins_test.dart packages/flutter_tools/test/general.shard/github_template_test.dart packages/flutter_tools/test/general.shard/linux/linux_device_test.dart packages/flutter_tools/test/general.shard/macos/macos_device_test.dart packages/flutter_tools/test/general.shard/plugin_parsing_test.dart packages/flutter_tools/test/general.shard/windows/windows_device_test.dart
platform_plugins.dart: - remove `CustomEmbedderPlugin.isNative`, no longer present in parent - support `hasDart`, `hasFfi`, `hasMethodChannel` (just add some boolean flags in the pubspec for the latter two) flutter_plugins.dart: - rework findNativeCustomEmbedderPlugins
a1f785d
to
90fa1b3
Compare
Sorry for the delay! (had to squash because I had 1000s of merge conflicts because of formatting changes in my commits that I reverted in later commits, sry if that messes up the review or something) |
- custom device config template has changed, update test to match against the updated template
@@ -532,6 +535,78 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { | |||
} | |||
} | |||
|
|||
class CustomEmbedderPlugin extends PluginPlatform implements NativeOrDartPlugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to my comments on the design document: I don't think that this should implement NativeOrDartPlugin
, because it's a specific set of implementation keys, and keys are 100% platform-dependent. An alternate web embedder, for instance, would definitely not be a NativeOrDartPlugin
.
required this.embedderName, | ||
required this.name, | ||
required this.pluginPath, | ||
this.dartPluginClass, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the discussion in the doc, there's currently no approach to actually implement this, so it shouldn't be a universal key.
required this.pluginPath, | ||
this.dartPluginClass, | ||
this.defaultPackage, | ||
bool? ffiPlugin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not apply to all embedders.
this.dartPluginClass, | ||
this.defaultPackage, | ||
bool? ffiPlugin, | ||
bool? methodChannelPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nor this.
I'm not even clear on what this is; it's unused AFAICT.
List<String> platforms, | ||
String pluginClass, | ||
String androidPackage, [ | ||
List<String> emptyPlatforms = const <String>[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs explanation in the method comment.
@@ -320,6 +350,11 @@ class Plugin { | |||
if (isInvalid(WindowsPlugin.kConfigKey, WindowsPlugin.validate)) { | |||
errors.add('Invalid "windows" plugin specification.'); | |||
} | |||
yaml.forEach((dynamic key, dynamic value) { | |||
if (key is String && key.startsWith('x-')) { | |||
isInvalid(key, CustomEmbedderPlugin.validate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can meaningfully validate custom plugin sections; they could contain anything.
I apologize for the delay. I hope I'll get to it this week or next week. |
@ardera do you have plans regarding this feature? |
Hey @ardera, I am going to close this PR just to get it off our PR review queue. Feel free to re-open if/when you have time to pick it up again. |
Implements plugin for custom devices: See #86864
See also the design doc: https://flutter.dev/go/plugin-support-for-custom-embeddings
Summary of the changes
custom_devices/custom_device_config.dart
:embedder
, the name of the embedderconfigureNativeProject
(should basically invokecmake
in the native project directory)buildNativeProject
(should basically invokeninja
in the native project directory)x-flutter-pi
subdir of the flutter project directorycustom_devices/custom_device.dart
:configureNativeProject
andbuildNativeProject
commands of the custom device configflutter_plugins.dart
:flutter-pi
variant of a plugin is activated if-Dflutter.customPlatform=flutter-pi
was given as a dart define, or theFLUTTER_CUSTOM_PLATFORM
environment variable equalsflutter-pi
(needed for debug mode)project.dart
:FlutterProjectFactory
andFlutterProject
for custom devices supportFlutterProject.customEmbedderProjects
lists all custom embedder subprojects of this flutter projectTests:
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.