Fully support Dart-only mobile and macOS plugins (#96183)
This commit is contained in:
@@ -152,14 +152,28 @@ Future<void> main() async {
|
||||
await flutter('clean');
|
||||
});
|
||||
|
||||
// Make a fake Dart-only plugin, since there are no existing examples.
|
||||
section('Create local plugin');
|
||||
|
||||
const String dartPluginName = 'dartplugin';
|
||||
await _createFakeDartPlugin(dartPluginName, tempDir);
|
||||
|
||||
section('Add plugins');
|
||||
|
||||
final File pubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
|
||||
String content = await pubspec.readAsString();
|
||||
content = content.replaceFirst(
|
||||
'\ndependencies:\n',
|
||||
// One dynamic framework, one static framework, and one that does not support iOS.
|
||||
'\ndependencies:\n device_info: 2.0.3\n google_sign_in: 4.5.1\n android_alarm_manager: 0.4.5+11\n',
|
||||
// One dynamic framework, one static framework, one Dart-only,
|
||||
// and one that does not support iOS.
|
||||
'''
|
||||
dependencies:
|
||||
device_info: 2.0.3
|
||||
google_sign_in: 4.5.1
|
||||
android_alarm_manager: 0.4.5+11
|
||||
$dartPluginName:
|
||||
path: ../$dartPluginName
|
||||
''',
|
||||
);
|
||||
await pubspec.writeAsString(content, flush: true);
|
||||
await inDirectory(projectDir, () async {
|
||||
@@ -191,7 +205,8 @@ Future<void> main() async {
|
||||
|| !podfileLockOutput.contains(':path: Flutter/FlutterPluginRegistrant')
|
||||
|| !podfileLockOutput.contains(':path: ".symlinks/plugins/device_info/ios"')
|
||||
|| !podfileLockOutput.contains(':path: ".symlinks/plugins/google_sign_in/ios"')
|
||||
|| podfileLockOutput.contains('android_alarm_manager')) {
|
||||
|| podfileLockOutput.contains('android_alarm_manager')
|
||||
|| podfileLockOutput.contains(dartPluginName)) {
|
||||
print(podfileLockOutput);
|
||||
return TaskResult.failure('Building ephemeral host app Podfile.lock does not contain expected pods');
|
||||
}
|
||||
@@ -205,6 +220,9 @@ Future<void> main() async {
|
||||
// Android-only, no embedded framework.
|
||||
checkDirectoryNotExists(path.join(ephemeralIOSHostApp.path, 'Frameworks', 'android_alarm_manager.framework'));
|
||||
|
||||
// Dart-only, no embedded framework.
|
||||
checkDirectoryNotExists(path.join(ephemeralIOSHostApp.path, 'Frameworks', '$dartPluginName.framework'));
|
||||
|
||||
section('Clean and pub get module');
|
||||
|
||||
await inDirectory(projectDir, () async {
|
||||
@@ -243,7 +261,8 @@ Future<void> main() async {
|
||||
|| !hostPodfileLockOutput.contains(':path: "../hello/.ios/Flutter/FlutterPluginRegistrant"')
|
||||
|| !hostPodfileLockOutput.contains(':path: "../hello/.ios/.symlinks/plugins/device_info/ios"')
|
||||
|| !hostPodfileLockOutput.contains(':path: "../hello/.ios/.symlinks/plugins/google_sign_in/ios"')
|
||||
|| hostPodfileLockOutput.contains('android_alarm_manager')) {
|
||||
|| hostPodfileLockOutput.contains('android_alarm_manager')
|
||||
|| hostPodfileLockOutput.contains(dartPluginName)) {
|
||||
print(hostPodfileLockOutput);
|
||||
throw TaskResult.failure('Building host app Podfile.lock does not contain expected pods');
|
||||
}
|
||||
@@ -501,3 +520,46 @@ Future<bool> _isAppAotBuild(Directory app) async {
|
||||
|
||||
return symbolTable.contains('kDartIsolateSnapshotInstructions');
|
||||
}
|
||||
|
||||
Future<void> _createFakeDartPlugin(String name, Directory parent) async {
|
||||
// Start from a standard plugin template.
|
||||
await inDirectory(parent, () async {
|
||||
await flutter(
|
||||
'create',
|
||||
options: <String>[
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'--template=plugin',
|
||||
'--platforms=ios',
|
||||
name,
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
final String pluginDir = path.join(parent.path, name);
|
||||
|
||||
// Convert the metadata to Dart-only.
|
||||
final String dartPluginClass = 'DartClassFor$name';
|
||||
final File pubspec = File(path.join(pluginDir, 'pubspec.yaml'));
|
||||
String content = await pubspec.readAsString();
|
||||
content = content.replaceAll(
|
||||
RegExp(r' pluginClass: .*?\n'),
|
||||
' dartPluginClass: $dartPluginClass\n',
|
||||
);
|
||||
await pubspec.writeAsString(content, flush: true);
|
||||
|
||||
// Add the Dart registration hook that the build will generate a call to.
|
||||
final File dartCode = File(path.join(pluginDir, 'lib', '$name.dart'));
|
||||
content = await dartCode.readAsString();
|
||||
content = '''
|
||||
$content
|
||||
|
||||
class $dartPluginClass {
|
||||
static void registerWith() {}
|
||||
}
|
||||
''';
|
||||
await dartCode.writeAsString(content, flush: true);
|
||||
|
||||
// Remove the native plugin code.
|
||||
await Directory(path.join(pluginDir, 'ios')).delete(recursive: true);
|
||||
}
|
||||
|
||||
@@ -16,5 +16,7 @@ Future<void> main() async {
|
||||
<String, String>{'ENABLE_ANDROID_EMBEDDING_V2': 'true'}),
|
||||
PluginTest('apk', <String>['-a', 'kotlin', '--platforms=android'], pluginCreateEnvironment:
|
||||
<String, String>{'ENABLE_ANDROID_EMBEDDING_V2': 'true'}),
|
||||
// Test that Dart-only plugins are supported.
|
||||
PluginTest('apk', <String>['--platforms=android'], dartOnlyPlugin: true),
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ Future<void> main() async {
|
||||
PluginTest('ios', <String>['-i', 'objc', '--platforms=ios']),
|
||||
PluginTest('ios', <String>['-i', 'swift', '--platforms=ios']),
|
||||
PluginTest('macos', <String>['--platforms=macos']),
|
||||
// Test that Dart-only plugins are supported.
|
||||
PluginTest('ios', <String>['--platforms=ios'], dartOnlyPlugin: true),
|
||||
PluginTest('macos', <String>['--platforms=macos'], dartOnlyPlugin: true),
|
||||
]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user