Update for flutter 3.0.0 (#95)
* Update for flutter 3.0.0 Signed-off-by: Hidenori.Matsubayashi <[email protected]>
This commit is contained in:
@@ -1 +1 @@
|
|||||||
bd539267b42051b0da3d16ffa8f48949dce8aa8f
|
d1b9a6938ad77326ac3a94d92bbc77933ed829ed
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
7e9793dee1b85a243edd0e06cb1658e98b077561
|
ee4e09cce01d6f2d7f4baebd247fde02e5008851
|
||||||
|
|||||||
+44
-73
@@ -30,13 +30,6 @@ import 'package:yaml/yaml.dart';
|
|||||||
|
|
||||||
import 'elinux_cmake_project.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`
|
/// Source: [LinuxPlugin] in `platform_plugins.dart`
|
||||||
class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
|
class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
|
||||||
ELinuxPlugin({
|
ELinuxPlugin({
|
||||||
@@ -44,34 +37,40 @@ class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
|
|||||||
@required this.directory,
|
@required this.directory,
|
||||||
this.pluginClass,
|
this.pluginClass,
|
||||||
this.dartPluginClass,
|
this.dartPluginClass,
|
||||||
this.fileName,
|
this.ffiPlugin,
|
||||||
|
this.defaultPackage,
|
||||||
this.dependencies,
|
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,
|
factory ELinuxPlugin.fromYaml(String name, Directory directory, YamlMap yaml,
|
||||||
List<String> dependencies) {
|
List<String> dependencies) {
|
||||||
assert(validate(yaml));
|
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(
|
return ELinuxPlugin(
|
||||||
name: name,
|
name: name,
|
||||||
directory: directory,
|
directory: directory,
|
||||||
pluginClass: yaml[kPluginClass] as String,
|
pluginClass: yaml[kPluginClass] as String,
|
||||||
dartPluginClass: yaml[kDartPluginClass] 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);
|
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) {
|
static bool validate(YamlMap yaml) {
|
||||||
if (yaml == null) {
|
if (yaml == null) {
|
||||||
return false;
|
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';
|
static const String kConfigKey = 'elinux';
|
||||||
@@ -80,72 +79,41 @@ class ELinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
|
|||||||
final Directory directory;
|
final Directory directory;
|
||||||
final String pluginClass;
|
final String pluginClass;
|
||||||
final String dartPluginClass;
|
final String dartPluginClass;
|
||||||
final String fileName;
|
|
||||||
final List<String> dependencies;
|
final List<String> dependencies;
|
||||||
|
final bool ffiPlugin;
|
||||||
|
final String defaultPackage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isNative() => pluginClass != null;
|
bool hasMethodChannel() => pluginClass != null;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hasFfi() => ffiPlugin != null;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hasDart() => dartPluginClass != null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return <String, dynamic>{
|
return <String, dynamic>{
|
||||||
'name': name,
|
'name': name,
|
||||||
if (pluginClass != null) 'class': pluginClass,
|
if (pluginClass != null) 'class': pluginClass,
|
||||||
|
if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass),
|
||||||
if (dartPluginClass != null) 'dartPluginClass': dartPluginClass,
|
if (dartPluginClass != null) 'dartPluginClass': dartPluginClass,
|
||||||
'filename': fileName,
|
if (ffiPlugin != null && ffiPlugin) kFfiPlugin: true,
|
||||||
|
if (defaultPackage != null) kDefaultPackage: defaultPackage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
String get path => directory.parent.path;
|
String get path => directory.parent.path;
|
||||||
|
|
||||||
File get projectFile => directory.childFile('project_def.prop');
|
|
||||||
|
|
||||||
final RegExp _propertyFormat = RegExp(r'(\S+)\s*\+?=(.*)');
|
|
||||||
|
|
||||||
Map<String, String> _properties;
|
|
||||||
|
|
||||||
String getProperty(String key) {
|
|
||||||
if (_properties == null) {
|
|
||||||
if (!projectFile.existsSync()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_properties = <String, String>{};
|
|
||||||
|
|
||||||
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<String> getPropertyAsAbsolutePaths(String key) {
|
|
||||||
final String property = getProperty(key);
|
|
||||||
if (property == null) {
|
|
||||||
return <String>[];
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> paths = <String>[];
|
|
||||||
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
|
/// Source: [_internalCapitalLetterRegex] in `platform_plugins.dart` (exact copy)
|
||||||
/// depend on this mixin to ensure plugins are correctly configured for eLinux.
|
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`
|
/// See: [FlutterCommand.verifyThenRunCommand] in `flutter_command.dart`
|
||||||
mixin ELinuxExtension on FlutterCommand {
|
mixin ELinuxExtension on FlutterCommand {
|
||||||
String _entrypoint;
|
String _entrypoint;
|
||||||
@@ -260,22 +228,24 @@ Future<void> ensureReadyForELinuxTooling(FlutterProject project) async {
|
|||||||
await injectELinuxPlugins(project);
|
await injectELinuxPlugins(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See: [refreshPluginsList] in `plugins.dart`
|
/// See: [refreshPluginsList] in `flutter_plugins.dart`
|
||||||
Future<void> refreshELinuxPluginsList(FlutterProject project) async {
|
Future<void> refreshELinuxPluginsList(FlutterProject project) async {
|
||||||
final List<ELinuxPlugin> plugins = await findELinuxPlugins(project);
|
final List<ELinuxPlugin> plugins = await findELinuxPlugins(project);
|
||||||
// Sort the plugins by name to keep ordering stable in generated files.
|
// Sort the plugins by name to keep ordering stable in generated files.
|
||||||
plugins.sort((ELinuxPlugin left, ELinuxPlugin right) =>
|
plugins.sort((ELinuxPlugin left, ELinuxPlugin right) =>
|
||||||
left.name.compareTo(right.name));
|
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 =
|
final bool legacyChanged =
|
||||||
_writeELinuxFlutterPluginsListLegacy(project, plugins);
|
_writeELinuxFlutterPluginsListLegacy(project, plugins);
|
||||||
|
|
||||||
final bool changed = await _writeELinuxFlutterPluginsList(project, plugins);
|
final bool changed = await _writeELinuxFlutterPluginsList(project, plugins);
|
||||||
if (changed || legacyChanged) {
|
if (changed || legacyChanged) {
|
||||||
createPluginSymlinks(project, force: true);
|
createPluginSymlinks(project, force: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See: [_writeFlutterPluginsListLegacy] in `plugins.dart`
|
/// See: [_writeFlutterPluginsListLegacy] in `flutter_plugins.dart`
|
||||||
bool _writeELinuxFlutterPluginsListLegacy(
|
bool _writeELinuxFlutterPluginsListLegacy(
|
||||||
FlutterProject project, List<ELinuxPlugin> plugins) {
|
FlutterProject project, List<ELinuxPlugin> plugins) {
|
||||||
final File pluginsFile = project.flutterPluginsFile;
|
final File pluginsFile = project.flutterPluginsFile;
|
||||||
@@ -304,7 +274,7 @@ const String _kFlutterPluginsNameKey = 'name';
|
|||||||
const String _kFlutterPluginsPathKey = 'path';
|
const String _kFlutterPluginsPathKey = 'path';
|
||||||
const String _kFlutterPluginsDependenciesKey = 'dependencies';
|
const String _kFlutterPluginsDependenciesKey = 'dependencies';
|
||||||
|
|
||||||
/// See: [_writeFlutterPluginsList] in `plugins.dart`
|
/// See: [_writeFlutterPluginsList] in `flutter_plugins.dart`
|
||||||
Future<bool> _writeELinuxFlutterPluginsList(
|
Future<bool> _writeELinuxFlutterPluginsList(
|
||||||
FlutterProject project, List<ELinuxPlugin> plugins) async {
|
FlutterProject project, List<ELinuxPlugin> plugins) async {
|
||||||
final File pluginsFile = project.flutterPluginsDependenciesFile;
|
final File pluginsFile = project.flutterPluginsDependenciesFile;
|
||||||
@@ -398,11 +368,12 @@ List<Map<String, Object>> _filterELinuxPluginsByPlatform(
|
|||||||
return pluginInfo;
|
return pluginInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See: [_createPluginLegacyDependencyGraph] in `plugins.dart`
|
/// See: [_createPluginLegacyDependencyGraph] in `flutter_plugins.dart`
|
||||||
List<Object> _createPluginLegacyDependencyGraph(List<ELinuxPlugin> plugins) {
|
List<Object> _createPluginLegacyDependencyGraph(List<ELinuxPlugin> plugins) {
|
||||||
final List<Object> directAppDependencies = <Object>[];
|
final List<Object> directAppDependencies = <Object>[];
|
||||||
final Set<String> pluginNames =
|
final Set<String> pluginNames =
|
||||||
plugins.map((ELinuxPlugin plugin) => plugin.name).toSet();
|
plugins.map((ELinuxPlugin plugin) => plugin.name).toSet();
|
||||||
|
|
||||||
for (final ELinuxPlugin plugin in plugins) {
|
for (final ELinuxPlugin plugin in plugins) {
|
||||||
directAppDependencies.add(<String, Object>{
|
directAppDependencies.add(<String, Object>{
|
||||||
'name': plugin.name,
|
'name': plugin.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user