Skip to content

Commit

Permalink
Temporarily allow pluginClass: none on desktop (#57498)
Browse files Browse the repository at this point in the history
Treats 'pluginClass: none' as equivalent to having no 'pluginClass'
entry on the desktop platforms, to satisy stable channel plugin
validation of Dart-only desktop plugin implementations. See
issue for full details.

Part of #57497
  • Loading branch information
stuartmorgan committed May 18, 2020
1 parent 5a3104b commit 30d405c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/flutter_tools/lib/src/platform_plugins.dart
Expand Up @@ -214,9 +214,14 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin {

factory MacOSPlugin.fromYaml(String name, YamlMap 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 MacOSPlugin(
name: name,
pluginClass: yaml[kPluginClass] as String,
pluginClass: pluginClass,
dartPluginClass: yaml[kDartPluginClass] as String,
);
}
Expand Down Expand Up @@ -260,9 +265,14 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{

factory WindowsPlugin.fromYaml(String name, YamlMap 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 WindowsPlugin(
name: name,
pluginClass: yaml[kPluginClass] as String,
pluginClass: pluginClass,
dartPluginClass: yaml[kDartPluginClass] as String,
);
}
Expand Down Expand Up @@ -307,9 +317,14 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {

factory LinuxPlugin.fromYaml(String name, YamlMap 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 LinuxPlugin(
name: name,
pluginClass: yaml[kPluginClass] as String,
pluginClass: pluginClass,
dartPluginClass: yaml[kDartPluginClass] as String,
);
}
Expand Down
90 changes: 90 additions & 0 deletions packages/flutter_tools/test/general.shard/plugins_test.dart
Expand Up @@ -914,6 +914,35 @@ flutter:
FeatureFlags: () => featureFlags,
});

testUsingContext('pluginClass: none doesn\'t trigger registrant entry on macOS', () async {
when(macosProject.existsSync()).thenReturn(true);
when(featureFlags.isMacOSEnabled).thenReturn(true);
when(flutterProject.isModule).thenReturn(true);
// Create a plugin without a pluginClass.
dummyPackageDirectory.parent.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:
plugin:
platforms:
macos:
pluginClass: none
dartPluginClass: SomePlugin
''');

await injectPlugins(flutterProject, checkProjects: true);

final File registrantFile = macosProject.managedDirectory.childFile('GeneratedPluginRegistrant.swift');

expect(registrantFile, exists);
expect(registrantFile, isNot(contains('SomePlugin')));
expect(registrantFile, isNot(contains('none')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});

testUsingContext('Injecting creates generated Linux registrant', () async {
when(linuxProject.existsSync()).thenReturn(true);
when(featureFlags.isLinuxEnabled).thenReturn(true);
Expand Down Expand Up @@ -961,6 +990,35 @@ flutter:
FeatureFlags: () => featureFlags,
});

testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Linux', () async {
when(linuxProject.existsSync()).thenReturn(true);
when(featureFlags.isLinuxEnabled).thenReturn(true);
when(flutterProject.isModule).thenReturn(false);
// Create a plugin without a pluginClass.
dummyPackageDirectory.parent.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:
plugin:
platforms:
linux:
pluginClass: none
dartPluginClass: SomePlugin
''');

await injectPlugins(flutterProject, checkProjects: true);

final File registrantImpl = linuxProject.managedDirectory.childFile('generated_plugin_registrant.cc');

expect(registrantImpl, exists);
expect(registrantImpl, isNot(contains('SomePlugin')));
expect(registrantImpl, isNot(contains('none')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});

testUsingContext('Injecting creates generated Linux plugin Cmake file', () async {
when(linuxProject.existsSync()).thenReturn(true);
when(featureFlags.isLinuxEnabled).thenReturn(true);
Expand Down Expand Up @@ -1034,6 +1092,38 @@ flutter:
FeatureFlags: () => featureFlags,
});

testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Windows', () async {
when(windowsProject.existsSync()).thenReturn(true);
when(featureFlags.isWindowsEnabled).thenReturn(true);
when(flutterProject.isModule).thenReturn(false);
// Create a plugin without a pluginClass.
dummyPackageDirectory.parent.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:
plugin:
platforms:
windows:
pluginClass: none
dartPluginClass: SomePlugin
''');

createDummyWindowsSolutionFile();
createDummyPluginWindowsProjectFile();

await injectPlugins(flutterProject, checkProjects: true);

final File registrantImpl = windowsProject.managedDirectory.childFile('generated_plugin_registrant.cc');

expect(registrantImpl, exists);
expect(registrantImpl, isNot(contains('SomePlugin')));
expect(registrantImpl, isNot(contains('none')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});

testUsingContext('Injecting creates generated Windows plugin properties', () async {
when(windowsProject.existsSync()).thenReturn(true);
when(featureFlags.isWindowsEnabled).thenReturn(true);
Expand Down

0 comments on commit 30d405c

Please sign in to comment.