Allow platform variants for Windows plugins (#82816)
Windows plugins are designed to share implementations between Win32 and UWP, but not all plugins will support both. This adds a new 'supportedVariants' key to Windows plugins that allows specifying 'win32' and/or 'uwp' (and potentially others in the future in case that becomes necessary). Plugins without any supported variants will be assumed to be Win32 for backward compatibility. This will allow compiling Windows projects that use Win32-only Windows plugins (which is currently all of them) in UWP mode. The plugins will of course throw missing implementation exceptions at runtime, but tehy won't prevent being able to build as they currently do. Fixes https://github.com/flutter/flutter/issues/82815
This commit is contained in:
@@ -253,6 +253,79 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('Windows allows supported mode lists', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String pluginYamlRaw =
|
||||
'platforms:\n'
|
||||
' windows:\n'
|
||||
' pluginClass: WinSamplePlugin\n'
|
||||
' supportedVariants:\n'
|
||||
' - win32\n'
|
||||
' - uwp\n';
|
||||
|
||||
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
|
||||
final Plugin plugin = Plugin.fromYaml(
|
||||
_kTestPluginName,
|
||||
_kTestPluginPath,
|
||||
pluginYaml,
|
||||
const <String>[],
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
final WindowsPlugin windowsPlugin = plugin.platforms[WindowsPlugin.kConfigKey]! as WindowsPlugin;
|
||||
expect(windowsPlugin.supportedVariants, <PluginPlatformVariant>[
|
||||
PluginPlatformVariant.win32,
|
||||
PluginPlatformVariant.winuwp,
|
||||
]);
|
||||
});
|
||||
|
||||
testWithoutContext('Windows assumes win32 when no variants are given', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String pluginYamlRaw =
|
||||
'platforms:\n'
|
||||
' windows:\n'
|
||||
' pluginClass: WinSamplePlugin\n';
|
||||
|
||||
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
|
||||
final Plugin plugin = Plugin.fromYaml(
|
||||
_kTestPluginName,
|
||||
_kTestPluginPath,
|
||||
pluginYaml,
|
||||
const <String>[],
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
final WindowsPlugin windowsPlugin = plugin.platforms[WindowsPlugin.kConfigKey]! as WindowsPlugin;
|
||||
expect(windowsPlugin.supportedVariants, <PluginPlatformVariant>[
|
||||
PluginPlatformVariant.win32,
|
||||
]);
|
||||
});
|
||||
|
||||
testWithoutContext('Windows ignores unknown variants', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String pluginYamlRaw =
|
||||
'platforms:\n'
|
||||
' windows:\n'
|
||||
' pluginClass: WinSamplePlugin\n'
|
||||
' supportedVariants:\n'
|
||||
' - not_yet_invented_variant\n'
|
||||
' - uwp\n';
|
||||
|
||||
final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap;
|
||||
final Plugin plugin = Plugin.fromYaml(
|
||||
_kTestPluginName,
|
||||
_kTestPluginPath,
|
||||
pluginYaml,
|
||||
const <String>[],
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
final WindowsPlugin windowsPlugin = plugin.platforms[WindowsPlugin.kConfigKey]! as WindowsPlugin;
|
||||
expect(windowsPlugin.supportedVariants, <PluginPlatformVariant>{
|
||||
PluginPlatformVariant.winuwp,
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('Plugin parsing throws a fatal error on an empty plugin', () {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final YamlMap? pluginYaml = loadYaml('') as YamlMap?;
|
||||
|
||||
@@ -35,7 +35,7 @@ const String kPluginDependencies = r'''
|
||||
|
||||
void main() {
|
||||
|
||||
testWithoutContext('injects Win32 plugins', () async {
|
||||
testWithoutContext('Win32 injects Win32 plugins', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
setUpProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
|
||||
@@ -46,7 +46,12 @@ void main() {
|
||||
path: 'foo',
|
||||
defaultPackagePlatforms: const <String, String>{},
|
||||
pluginDartClassPlatforms: const <String, String>{},
|
||||
platforms: const <String, PluginPlatform>{WindowsPlugin.kConfigKey: WindowsPlugin(name: 'test', pluginClass: 'Foo')},
|
||||
platforms: const <String, PluginPlatform>{
|
||||
WindowsPlugin.kConfigKey: WindowsPlugin(
|
||||
name: 'test',
|
||||
pluginClass: 'Foo',
|
||||
variants: <PluginPlatformVariant>{PluginPlatformVariant.win32},
|
||||
)},
|
||||
dependencies: <String>[],
|
||||
isDirectDependency: true,
|
||||
),
|
||||
@@ -61,7 +66,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('UWP injects Win32 plugins', () async {
|
||||
testWithoutContext('UWP injects plugins marked as UWP-compatible', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
setUpProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
|
||||
@@ -72,7 +77,12 @@ void main() {
|
||||
path: 'foo',
|
||||
defaultPackagePlatforms: const <String, String>{},
|
||||
pluginDartClassPlatforms: const <String, String>{},
|
||||
platforms: const <String, PluginPlatform>{WindowsPlugin.kConfigKey: WindowsPlugin(name: 'test', pluginClass: 'Foo')},
|
||||
platforms: const <String, PluginPlatform>{
|
||||
WindowsPlugin.kConfigKey: WindowsPlugin(
|
||||
name: 'test',
|
||||
pluginClass: 'Foo',
|
||||
variants: <PluginPlatformVariant>{PluginPlatformVariant.winuwp},
|
||||
)},
|
||||
dependencies: <String>[],
|
||||
isDirectDependency: true,
|
||||
),
|
||||
@@ -87,6 +97,37 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('UWP does not inject Win32-only plugins', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
setUpProject(fileSystem);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
|
||||
|
||||
await writeWindowsUwpPluginFiles(flutterProject, <Plugin>[
|
||||
Plugin(
|
||||
name: 'test',
|
||||
path: 'foo',
|
||||
defaultPackagePlatforms: const <String, String>{},
|
||||
pluginDartClassPlatforms: const <String, String>{},
|
||||
platforms: const <String, PluginPlatform>{
|
||||
WindowsPlugin.kConfigKey: WindowsPlugin(
|
||||
name: 'test',
|
||||
pluginClass: 'Foo',
|
||||
variants: <PluginPlatformVariant>{PluginPlatformVariant.win32},
|
||||
)},
|
||||
dependencies: <String>[],
|
||||
isDirectDependency: true,
|
||||
),
|
||||
], renderer);
|
||||
|
||||
final Directory managed = flutterProject.windowsUwp.managedDirectory;
|
||||
expect(flutterProject.windowsUwp.generatedPluginCmakeFile, exists);
|
||||
expect(managed.childFile('generated_plugin_registrant.h'), exists);
|
||||
expect(
|
||||
managed.childFile('generated_plugin_registrant.cc').readAsStringSync(),
|
||||
isNot(contains('#include <test/foo.h>')),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Symlink injection treats UWP as Win32', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
setUpProject(fileSystem);
|
||||
|
||||
Reference in New Issue
Block a user