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
Allow iOS and macOS plugins to share darwin directory #115337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_devicelab/framework/framework.dart'; | ||
import 'package:flutter_devicelab/tasks/plugin_tests.dart'; | ||
|
||
Future<void> main() async { | ||
await task(combine(<TaskFunction>[ | ||
PluginTest('macos', <String>['--platforms=macos']).call, | ||
// Test that Dart-only plugins are supported. | ||
PluginTest('macos', <String>['--platforms=macos'], dartOnlyPlugin: true).call, | ||
// Test that shared darwin directories are supported. | ||
PluginTest('macos', <String>['--platforms=ios,macos'], sharedDarwinSource: true).call, | ||
// Test that FFI plugins are supported. | ||
PluginTest('macos', <String>['--platforms=macos'], template: 'plugin_ffi').call, | ||
])); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,14 +266,19 @@ def flutter_install_plugin_pods(application_path = nil, relative_symlink_dir, pl | |
plugin_name = plugin_hash['name'] | ||
plugin_path = plugin_hash['path'] | ||
has_native_build = plugin_hash.fetch('native_build', true) | ||
|
||
# iOS and macOS code can be shared in "darwin" directory, otherwise | ||
# respectively in "ios" or "macos" directories. | ||
shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false) | ||
platform_directory = shared_darwin_source ? 'darwin' : platform | ||
next unless plugin_name && plugin_path && has_native_build | ||
symlink = File.join(symlink_plugins_dir, plugin_name) | ||
File.symlink(plugin_path, symlink) | ||
|
||
# Keep pod path relative so it can be checked into Podfile.lock. | ||
relative = flutter_relative_path_from_podfile(symlink) | ||
|
||
pod plugin_name, path: File.join(relative, platform) | ||
pod plugin_name, path: File.join(relative, platform_directory) | ||
end | ||
end | ||
|
||
|
@@ -288,7 +293,7 @@ def flutter_parse_plugins_file(file, platform) | |
|
||
# dependencies_hash.dig('plugins', 'ios') not available until Ruby 2.3 | ||
return [] unless dependencies_hash.has_key?('plugins') | ||
return [] unless dependencies_hash['plugins'].has_key?('ios') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How has this been working? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, I guess there aren't many plugins that support macOS but not iOS? I was not pleased when I spotted this though (my fault totally). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return [] unless dependencies_hash['plugins'].has_key?(platform) | ||
dependencies_hash['plugins'][platform] || [] | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ const String kFfiPlugin = 'ffiPlugin'; | |
// Constant for 'defaultPackage' key in plugin maps. | ||
const String kDefaultPackage = 'default_package'; | ||
|
||
/// Constant for 'sharedDarwinSource' key in plugin maps. | ||
/// Can be set for iOS and macOS plugins. | ||
const String kSharedDarwinSource = 'sharedDarwinSource'; | ||
|
||
/// Constant for 'supportedVariants' key in plugin maps. | ||
const String kSupportedVariants = 'supportedVariants'; | ||
|
||
|
@@ -52,6 +56,11 @@ abstract class NativeOrDartPlugin { | |
bool hasMethodChannel(); | ||
} | ||
|
||
abstract class DarwinPlugin { | ||
/// Indicates the iOS and macOS native code is shareable the subdirectory "darwin", | ||
bool get sharedDarwinSource; | ||
} | ||
|
||
/// Contains parameters to template an Android plugin. | ||
/// | ||
/// The [name] of the plugin is required. Additionally, either: | ||
|
@@ -227,15 +236,17 @@ class AndroidPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
/// - the [dartPluginClass] that will be the entry point for the plugin's | ||
/// Dart code | ||
/// is required. | ||
class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | ||
class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin, DarwinPlugin { | ||
const IOSPlugin({ | ||
required this.name, | ||
required this.classPrefix, | ||
this.pluginClass, | ||
this.dartPluginClass, | ||
bool? ffiPlugin, | ||
this.defaultPackage, | ||
}) : ffiPlugin = ffiPlugin ?? false; | ||
bool? sharedDarwinSource, | ||
}) : ffiPlugin = ffiPlugin ?? false, | ||
sharedDarwinSource = sharedDarwinSource ?? false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need to be able to explicitly pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes it easier to do: sharedDarwinSource: yaml[kSharedDarwinSource] as bool?, You're right the property should be nonnull though even when the constructor allows null. |
||
|
||
factory IOSPlugin.fromYaml(String name, YamlMap yaml) { | ||
assert(validate(yaml)); // TODO(zanderso): https://github.com/flutter/flutter/issues/67241 | ||
|
@@ -246,6 +257,7 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
dartPluginClass: yaml[kDartPluginClass] as String?, | ||
ffiPlugin: yaml[kFfiPlugin] as bool?, | ||
defaultPackage: yaml[kDefaultPackage] as String?, | ||
sharedDarwinSource: yaml[kSharedDarwinSource] as bool?, | ||
); | ||
} | ||
|
||
|
@@ -256,6 +268,7 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
return yaml[kPluginClass] is String || | ||
yaml[kDartPluginClass] is String || | ||
yaml[kFfiPlugin] == true || | ||
yaml[kSharedDarwinSource] == true || | ||
yaml[kDefaultPackage] is String; | ||
} | ||
|
||
|
@@ -271,6 +284,11 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
final bool ffiPlugin; | ||
final String? defaultPackage; | ||
|
||
/// Indicates the iOS native code is shareable with macOS in | ||
/// the subdirectory "darwin", otherwise in the subdirectory "ios". | ||
@override | ||
final bool sharedDarwinSource; | ||
|
||
@override | ||
bool hasMethodChannel() => pluginClass != null; | ||
|
||
|
@@ -288,6 +306,7 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
if (pluginClass != null) 'class': pluginClass, | ||
if (dartPluginClass != null) kDartPluginClass : dartPluginClass, | ||
if (ffiPlugin) kFfiPlugin: true, | ||
if (sharedDarwinSource) kSharedDarwinSource: true, | ||
if (defaultPackage != null) kDefaultPackage : defaultPackage, | ||
}; | ||
} | ||
|
@@ -298,14 +317,16 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
/// The [name] of the plugin is required. Either [dartPluginClass] or | ||
/// [pluginClass] or [ffiPlugin] are required. | ||
/// [pluginClass] will be the entry point to the plugin's native code. | ||
class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | ||
class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin, DarwinPlugin { | ||
const MacOSPlugin({ | ||
required this.name, | ||
this.pluginClass, | ||
this.dartPluginClass, | ||
bool? ffiPlugin, | ||
this.defaultPackage, | ||
}) : ffiPlugin = ffiPlugin ?? false; | ||
bool? sharedDarwinSource, | ||
}) : ffiPlugin = ffiPlugin ?? false, | ||
sharedDarwinSource = sharedDarwinSource ?? false; | ||
|
||
factory MacOSPlugin.fromYaml(String name, YamlMap yaml) { | ||
assert(validate(yaml)); | ||
|
@@ -320,6 +341,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
dartPluginClass: yaml[kDartPluginClass] as String?, | ||
ffiPlugin: yaml[kFfiPlugin] as bool?, | ||
defaultPackage: yaml[kDefaultPackage] as String?, | ||
sharedDarwinSource: yaml[kSharedDarwinSource] as bool?, | ||
); | ||
} | ||
|
||
|
@@ -330,6 +352,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
return yaml[kPluginClass] is String || | ||
yaml[kDartPluginClass] is String || | ||
yaml[kFfiPlugin] == true || | ||
yaml[kSharedDarwinSource] == true || | ||
yaml[kDefaultPackage] is String; | ||
} | ||
|
||
|
@@ -341,6 +364,11 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
final bool ffiPlugin; | ||
final String? defaultPackage; | ||
|
||
/// Indicates the macOS native code is shareable with iOS in | ||
/// the subdirectory "darwin", otherwise in the subdirectory "macos". | ||
@override | ||
final bool sharedDarwinSource; | ||
|
||
@override | ||
bool hasMethodChannel() => pluginClass != null; | ||
|
||
|
@@ -357,6 +385,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { | |
if (pluginClass != null) 'class': pluginClass, | ||
if (dartPluginClass != null) kDartPluginClass: dartPluginClass, | ||
if (ffiPlugin) kFfiPlugin: true, | ||
if (sharedDarwinSource) kSharedDarwinSource: true, | ||
if (defaultPackage != null) kDefaultPackage: defaultPackage, | ||
}; | ||
} | ||
|
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 really want to see if we can fix this; it bit me recently too. For Obj-C the change is transparent, but it's unclear to me if there's a way to change it without breaking Swift plugins. (Not for this PR, just venting.)
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 was surprised at the differences.