Generate a Property Sheet for Windows plugins (#50740)
Generates a Property Sheet for Windows builds containing link and include path
information for any included plugins. This allows automating part of the process
of integrating plugins into the build that is currently manual.
To support this change, refactored msbuild_utils into a PropertySheet class so that
it can be used to make different property sheets.
diff --git a/packages/flutter_tools/test/general.shard/plugins_test.dart b/packages/flutter_tools/test/general.shard/plugins_test.dart
index f3b669e..63f25b7 100644
--- a/packages/flutter_tools/test/general.shard/plugins_test.dart
+++ b/packages/flutter_tools/test/general.shard/plugins_test.dart
@@ -73,7 +73,11 @@
windowsProject = MockWindowsProject();
when(flutterProject.windows).thenReturn(windowsProject);
when(windowsProject.pluginConfigKey).thenReturn('windows');
- when(windowsProject.pluginSymlinkDirectory).thenReturn(flutterProject.directory.childDirectory('windows').childDirectory('symlinks'));
+ final Directory windowsManagedDirectory = flutterProject.directory.childDirectory('windows').childDirectory('flutter');
+ when(windowsProject.managedDirectory).thenReturn(windowsManagedDirectory);
+ when(windowsProject.vcprojFile).thenReturn(windowsManagedDirectory.parent.childFile('Runner.vcxproj'));
+ when(windowsProject.pluginSymlinkDirectory).thenReturn(windowsManagedDirectory.childDirectory('ephemeral').childDirectory('.plugin_symlinks'));
+ when(windowsProject.generatedPluginPropertySheetFile).thenReturn(windowsManagedDirectory.childFile('GeneratedPlugins.props'));
when(windowsProject.existsSync()).thenReturn(false);
linuxProject = MockLinuxProject();
when(flutterProject.linux).thenReturn(linuxProject);
@@ -106,9 +110,9 @@
macos:
pluginClass: FLESomePlugin
windows:
- pluginClass: FLESomePlugin
+ pluginClass: SomePlugin
linux:
- pluginClass: FLESomePlugin
+ pluginClass: SomePlugin
web:
pluginClass: SomePlugin
fileName: lib/SomeFile.dart
@@ -827,6 +831,46 @@
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => featureFlags,
});
+
+ testUsingContext('Injecting creates generated Windows registrant', () async {
+ when(windowsProject.existsSync()).thenReturn(true);
+ when(featureFlags.isWindowsEnabled).thenReturn(true);
+ when(flutterProject.isModule).thenReturn(false);
+ configureDummyPackageAsPlugin();
+
+ await injectPlugins(flutterProject, checkProjects: true);
+
+ final File registrantHeader = windowsProject.managedDirectory.childFile('generated_plugin_registrant.h');
+ final File registrantImpl = windowsProject.managedDirectory.childFile('generated_plugin_registrant.cc');
+
+ expect(registrantHeader.existsSync(), isTrue);
+ expect(registrantImpl.existsSync(), isTrue);
+ expect(registrantImpl.readAsStringSync(), contains('SomePluginRegisterWithRegistrar'));
+ }, 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);
+ when(flutterProject.isModule).thenReturn(false);
+ configureDummyPackageAsPlugin();
+
+ await injectPlugins(flutterProject, checkProjects: true);
+
+ final File properties = windowsProject.generatedPluginPropertySheetFile;
+ final String includePath = fs.path.join('flutter', 'ephemeral', '.plugin_symlinks', 'apackage', 'windows');
+
+ expect(properties.existsSync(), isTrue);
+ expect(properties.readAsStringSync(), contains('apackage_plugin.lib'));
+ expect(properties.readAsStringSync(), contains('>$includePath;'));
+ }, overrides: <Type, Generator>{
+ FileSystem: () => fs,
+ ProcessManager: () => FakeProcessManager.any(),
+ FeatureFlags: () => featureFlags,
+ });
});
group('createPluginSymlinks', () {