Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

ardera
Copy link
Contributor

@ardera ardera commented Sep 29, 2021

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:

  • 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)

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

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)

Tests:

  • 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

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 29, 2021
@google-cla google-cla bot added the cla: yes label Sep 29, 2021
@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ardera ardera force-pushed the feature/custom-devices-plugins branch 2 times, most recently from 4915821 to 75bb480 Compare November 6, 2021 10:58
@ardera ardera force-pushed the feature/custom-devices-plugins branch from 7ea7daf to a1f785d Compare November 15, 2021 12:43
@christopherfujino christopherfujino self-requested a review January 13, 2022 22:13
@ardera
Copy link
Contributor Author

ardera commented Feb 8, 2022

(ping) @christopherfujino

@christopherfujino christopherfujino self-assigned this Feb 17, 2022
required String pluginPath,
required FileSystem fileSystem
}) {
assert(validate(yaml));
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
should've already made sure the yaml is valid (except I forgot to add some validation there, but I did that now)

@christopherfujino
Copy link
Contributor

@stuartmorgan can you review the changes to:

  • packages/flutter_tools/lib/src/flutter_plugins.dart
  • packages/flutter_tools/lib/src/platform_plugins.dart

ardera added 2 commits April 19, 2022 10:22
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
@ardera
Copy link
Contributor Author

ardera commented Apr 19, 2022

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)

ardera added 3 commits April 19, 2022 11:13
- fix passing of removed parameter `fileSystem` for `CustomEmbedderPlugin`
- remove unused import in test
- documentation URL was updated to point to an actual website, use that in the test too
- custom device config template has changed, update test to match against the updated template
@guidezpl guidezpl removed the cla: yes label May 1, 2022
@@ -532,6 +535,78 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
}
}

class CustomEmbedderPlugin extends PluginPlatform implements NativeOrDartPlugin {
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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>[],
Copy link
Contributor

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);
Copy link
Contributor

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.

@ardera
Copy link
Contributor Author

ardera commented Aug 17, 2022

I apologize for the delay. I hope I'll get to it this week or next week.

@Jasguerrero Jasguerrero added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 22, 2022
@eximius313
Copy link

@ardera do you have plans regarding this feature?

@christopherfujino
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels. waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants