From 4a79b07c0fb48780741ec118d57b9cab84c1b349 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 14 May 2022 11:11:23 +0900 Subject: [PATCH] Update for flutter 3.0.0 (#95) * Update for flutter 3.0.0 Signed-off-by: Hidenori.Matsubayashi --- bin/internal/engine.version | 2 +- bin/internal/flutter.version | 2 +- lib/elinux_plugins.dart | 117 +++++++++++++---------------------- 3 files changed, 46 insertions(+), 75 deletions(-) diff --git a/bin/internal/engine.version b/bin/internal/engine.version index 8bde045..12ae6df 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -bd539267b42051b0da3d16ffa8f48949dce8aa8f +d1b9a6938ad77326ac3a94d92bbc77933ed829ed diff --git a/bin/internal/flutter.version b/bin/internal/flutter.version index 5a7e768..db8d310 100644 --- a/bin/internal/flutter.version +++ b/bin/internal/flutter.version @@ -1 +1 @@ -7e9793dee1b85a243edd0e06cb1658e98b077561 +ee4e09cce01d6f2d7f4baebd247fde02e5008851 diff --git a/lib/elinux_plugins.dart b/lib/elinux_plugins.dart index 679d52c..17567c1 100644 --- a/lib/elinux_plugins.dart +++ b/lib/elinux_plugins.dart @@ -30,13 +30,6 @@ import 'package:yaml/yaml.dart'; import 'elinux_cmake_project.dart'; -/// Contains the parameters to template a elinux plugin. -/// -/// The [name] of the plugin is required. Either [dartPluginClass] or -/// [pluginClass] are required. [pluginClass] will be the entry point to the -/// plugin's native code. If [pluginClass] is not empty, the [fileName] -/// containing the plugin's code is required. -/// /// Source: [LinuxPlugin] in `platform_plugins.dart` class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { ELinuxPlugin({ @@ -44,34 +37,40 @@ class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { @required this.directory, this.pluginClass, this.dartPluginClass, - this.fileName, + this.ffiPlugin, + this.defaultPackage, this.dependencies, - }) : assert(pluginClass != null || dartPluginClass != null); + }) : assert(pluginClass != null || + dartPluginClass != null || + (ffiPlugin ?? false) || + defaultPackage != null); factory ELinuxPlugin.fromYaml(String name, Directory directory, YamlMap yaml, List dependencies) { assert(validate(yaml)); + // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. + String pluginClass = yaml[kPluginClass] as String; + if (pluginClass == 'none') { + pluginClass = null; + } return ELinuxPlugin( name: name, directory: directory, pluginClass: yaml[kPluginClass] as String, dartPluginClass: yaml[kDartPluginClass] as String, - fileName: _filenameForCppClass(yaml[kPluginClass] as String), + ffiPlugin: yaml[kFfiPlugin] as bool, + defaultPackage: yaml[kDefaultPackage] as String, dependencies: dependencies); } - /// See: [_filenameForCppClass] in `platform_plugins.dart` - static final RegExp _internalCapitalLetterRegex = RegExp(r'(?=(?!^)[A-Z])'); - static String _filenameForCppClass(String className) { - return className.splitMapJoin(_internalCapitalLetterRegex, - onMatch: (_) => '_', onNonMatch: (String n) => n.toLowerCase()); - } - static bool validate(YamlMap yaml) { if (yaml == null) { return false; } - return yaml[kPluginClass] is String || yaml[kDartPluginClass] is String; + return yaml[kPluginClass] is String || + yaml[kDartPluginClass] is String || + yaml[kFfiPlugin] == true || + yaml[kDefaultPackage] is String; } static const String kConfigKey = 'elinux'; @@ -80,72 +79,41 @@ class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { final Directory directory; final String pluginClass; final String dartPluginClass; - final String fileName; final List dependencies; + final bool ffiPlugin; + final String defaultPackage; @override - bool isNative() => pluginClass != null; + bool hasMethodChannel() => pluginClass != null; + + @override + bool hasFfi() => ffiPlugin != null; + + @override + bool hasDart() => dartPluginClass != null; @override Map toMap() { return { 'name': name, if (pluginClass != null) 'class': pluginClass, + if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass), if (dartPluginClass != null) 'dartPluginClass': dartPluginClass, - 'filename': fileName, + if (ffiPlugin != null && ffiPlugin) kFfiPlugin: true, + if (defaultPackage != null) kDefaultPackage: defaultPackage, }; } String get path => directory.parent.path; - - File get projectFile => directory.childFile('project_def.prop'); - - final RegExp _propertyFormat = RegExp(r'(\S+)\s*\+?=(.*)'); - - Map _properties; - - String getProperty(String key) { - if (_properties == null) { - if (!projectFile.existsSync()) { - return null; - } - _properties = {}; - - for (final String line in projectFile.readAsLinesSync()) { - final Match match = _propertyFormat.firstMatch(line); - if (match == null) { - continue; - } - final String key = match.group(1); - final String value = match.group(2).trim(); - _properties[key] = value; - } - } - return _properties.containsKey(key) ? _properties[key] : null; - } - - List getPropertyAsAbsolutePaths(String key) { - final String property = getProperty(key); - if (property == null) { - return []; - } - - final List paths = []; - for (final String element in property.split(' ')) { - if (globals.fs.path.isAbsolute(element)) { - paths.add(element); - } else { - paths.add(globals.fs.path - .normalize(globals.fs.path.join(directory.path, element))); - } - } - return paths; - } } -/// Any [FlutterCommand] that invokes [usesPubOption] or [targetFile] should -/// depend on this mixin to ensure plugins are correctly configured for eLinux. -/// +/// Source: [_internalCapitalLetterRegex] in `platform_plugins.dart` (exact copy) +final RegExp _internalCapitalLetterRegex = RegExp(r'(?=(?!^)[A-Z])'); +String _filenameForCppClass(String className) { + return className.splitMapJoin(_internalCapitalLetterRegex, + onMatch: (_) => '_', onNonMatch: (String n) => n.toLowerCase()); +} + /// See: [FlutterCommand.verifyThenRunCommand] in `flutter_command.dart` mixin ELinuxExtension on FlutterCommand { String _entrypoint; @@ -260,22 +228,24 @@ Future ensureReadyForELinuxTooling(FlutterProject project) async { await injectELinuxPlugins(project); } -/// See: [refreshPluginsList] in `plugins.dart` +/// See: [refreshPluginsList] in `flutter_plugins.dart` Future refreshELinuxPluginsList(FlutterProject project) async { final List plugins = await findELinuxPlugins(project); // Sort the plugins by name to keep ordering stable in generated files. plugins.sort((ELinuxPlugin left, ELinuxPlugin right) => left.name.compareTo(right.name)); - + // TODO(franciscojma): Remove once migration is complete. + // Write the legacy plugin files to avoid breaking existing apps. final bool legacyChanged = _writeELinuxFlutterPluginsListLegacy(project, plugins); + final bool changed = await _writeELinuxFlutterPluginsList(project, plugins); if (changed || legacyChanged) { createPluginSymlinks(project, force: true); } } -/// See: [_writeFlutterPluginsListLegacy] in `plugins.dart` +/// See: [_writeFlutterPluginsListLegacy] in `flutter_plugins.dart` bool _writeELinuxFlutterPluginsListLegacy( FlutterProject project, List plugins) { final File pluginsFile = project.flutterPluginsFile; @@ -304,7 +274,7 @@ const String _kFlutterPluginsNameKey = 'name'; const String _kFlutterPluginsPathKey = 'path'; const String _kFlutterPluginsDependenciesKey = 'dependencies'; -/// See: [_writeFlutterPluginsList] in `plugins.dart` +/// See: [_writeFlutterPluginsList] in `flutter_plugins.dart` Future _writeELinuxFlutterPluginsList( FlutterProject project, List plugins) async { final File pluginsFile = project.flutterPluginsDependenciesFile; @@ -398,11 +368,12 @@ List> _filterELinuxPluginsByPlatform( return pluginInfo; } -/// See: [_createPluginLegacyDependencyGraph] in `plugins.dart` +/// See: [_createPluginLegacyDependencyGraph] in `flutter_plugins.dart` List _createPluginLegacyDependencyGraph(List plugins) { final List directAppDependencies = []; final Set pluginNames = plugins.map((ELinuxPlugin plugin) => plugin.name).toSet(); + for (final ELinuxPlugin plugin in plugins) { directAppDependencies.add({ 'name': plugin.name,