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.
This commit is contained in:
stuartmorgan
2020-02-13 12:53:28 -08:00
committed by GitHub
parent e2554a9202
commit f4177a6dde
7 changed files with 265 additions and 82 deletions

View File

@@ -73,7 +73,11 @@ void main() {
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 @@ void main() {
macos:
pluginClass: FLESomePlugin
windows:
pluginClass: FLESomePlugin
pluginClass: SomePlugin
linux:
pluginClass: FLESomePlugin
pluginClass: SomePlugin
web:
pluginClass: SomePlugin
fileName: lib/SomeFile.dart
@@ -827,6 +831,46 @@ web_plugin_with_nested:${webPluginWithNestedFile.childDirectory('lib').uri.toStr
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', () {

View File

@@ -0,0 +1,49 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/windows/property_sheet.dart';
import '../../src/common.dart';
void main() {
group('Property Sheet', () {
test('Base file matches expected format', () async {
const String baseFile = '''
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets"/>
<PropertyGroup Label="UserMacros"/>
<PropertyGroup/>
<ItemDefinitionGroup/>
<ItemGroup/>
</Project>''';
const PropertySheet sheet = PropertySheet();
expect(sheet.toString(), baseFile);
});
test('Environment variable generate the correct elements', () async {
const Map<String, String> environment = <String, String>{'FOO': 'Bar'};
const PropertySheet sheet = PropertySheet(environmentVariables: environment);
final String propsContent = sheet.toString();
expect(propsContent, contains('<FOO>Bar</FOO>'));
expect(propsContent, contains('''
<BuildMacro Include="FOO">
<Value>\$(FOO)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>'''));
});
test('Include paths generate the correct elements', () async {
const PropertySheet sheet = PropertySheet(includePaths: <String>['foo/bar', 'baz']);
final String propsContent = sheet.toString();
expect(propsContent, contains('<AdditionalIncludeDirectories>foo/bar;baz;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>'));
});
test('Library dependencies generate the correct elements', () async {
const PropertySheet sheet = PropertySheet(libraryDependencies: <String>['foo.lib', 'bar.lib']);
final String propsContent = sheet.toString();
expect(propsContent, contains('<AdditionalDependencies>foo.lib;bar.lib;%(AdditionalDependencies)</AdditionalDependencies>'));
});
});
}