[flutter_plugin_tool] Add support for building UWP plugins (#4047)

This allows building UWP plugin examples with `build-examples --winuwp`. As with previous pre-stable-template desktop support, this avoids the issue of unstable app templates by running `flutter create` on the fly before trying to build, so a template that will bitrot doesn't need to be checked in.

Also adds no-op "support" for `drive-examples --winuwp`, with warnings about it not doing anything. This is to handle the fact that the LUCI recipe is shared between Win32 and UWP, and didn't conditionalize `drive`. Rather than change that, then change it back later, this just adds the no-op support now (since changing the tooling is much easier than changing LUCI recipes currently).

This required some supporting tool changes:
- Adds the ability to check for the new platform variants in a pubspec
- Adds the ability to write test pubspecs that include variants, for testing

Part of https://github.com/flutter/flutter/issues/82817
This commit is contained in:
stuartmorgan
2021-08-26 15:07:33 -04:00
committed by GitHub
parent e7ef3168bf
commit dcf97f741f
14 changed files with 590 additions and 245 deletions

View File

@ -4,6 +4,7 @@
- Added a new `android-lint` command to lint Android plugin native code.
- Pubspec validation now checks for `implements` in implementation packages.
- Pubspec valitation now checks the full relative path of `repository` entries.
- `build-examples` now supports UWP plugins via a `--winuwp` flag.
## 0.5.0

View File

@ -16,7 +16,16 @@ import 'common/repository_package.dart';
/// Key for APK.
const String _platformFlagApk = 'apk';
const int _exitNoPlatformFlags = 2;
const int _exitNoPlatformFlags = 3;
// Flutter build types. These are the values passed to `flutter build <foo>`.
const String _flutterBuildTypeAndroid = 'apk';
const String _flutterBuildTypeIos = 'ios';
const String _flutterBuildTypeLinux = 'linux';
const String _flutterBuildTypeMacOS = 'macos';
const String _flutterBuildTypeWeb = 'web';
const String _flutterBuildTypeWin32 = 'windows';
const String _flutterBuildTypeWinUwp = 'winuwp';
/// A command to build the example applications for packages.
class BuildExamplesCommand extends PackageLoopingCommand {
@ -30,6 +39,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
argParser.addFlag(kPlatformMacos);
argParser.addFlag(kPlatformWeb);
argParser.addFlag(kPlatformWindows);
argParser.addFlag(kPlatformWinUwp);
argParser.addFlag(kPlatformIos);
argParser.addFlag(_platformFlagApk);
argParser.addOption(
@ -46,33 +56,40 @@ class BuildExamplesCommand extends PackageLoopingCommand {
_platformFlagApk: const _PlatformDetails(
'Android',
pluginPlatform: kPlatformAndroid,
flutterBuildType: 'apk',
flutterBuildType: _flutterBuildTypeAndroid,
),
kPlatformIos: const _PlatformDetails(
'iOS',
pluginPlatform: kPlatformIos,
flutterBuildType: 'ios',
flutterBuildType: _flutterBuildTypeIos,
extraBuildFlags: <String>['--no-codesign'],
),
kPlatformLinux: const _PlatformDetails(
'Linux',
pluginPlatform: kPlatformLinux,
flutterBuildType: 'linux',
flutterBuildType: _flutterBuildTypeLinux,
),
kPlatformMacos: const _PlatformDetails(
'macOS',
pluginPlatform: kPlatformMacos,
flutterBuildType: 'macos',
flutterBuildType: _flutterBuildTypeMacOS,
),
kPlatformWeb: const _PlatformDetails(
'web',
pluginPlatform: kPlatformWeb,
flutterBuildType: 'web',
flutterBuildType: _flutterBuildTypeWeb,
),
kPlatformWindows: const _PlatformDetails(
'Windows',
'Win32',
pluginPlatform: kPlatformWindows,
flutterBuildType: 'windows',
pluginPlatformVariant: platformVariantWin32,
flutterBuildType: _flutterBuildTypeWin32,
),
kPlatformWinUwp: const _PlatformDetails(
'UWP',
pluginPlatform: kPlatformWindows,
pluginPlatformVariant: platformVariantWinUwp,
flutterBuildType: _flutterBuildTypeWinUwp,
),
};
@ -107,7 +124,8 @@ class BuildExamplesCommand extends PackageLoopingCommand {
final Set<_PlatformDetails> buildPlatforms = <_PlatformDetails>{};
final Set<_PlatformDetails> unsupportedPlatforms = <_PlatformDetails>{};
for (final _PlatformDetails platform in requestedPlatforms) {
if (pluginSupportsPlatform(platform.pluginPlatform, package)) {
if (pluginSupportsPlatform(platform.pluginPlatform, package,
variant: platform.pluginPlatformVariant)) {
buildPlatforms.add(platform);
} else {
unsupportedPlatforms.add(platform);
@ -156,6 +174,22 @@ class BuildExamplesCommand extends PackageLoopingCommand {
}) async {
final String enableExperiment = getStringArg(kEnableExperiment);
// The UWP template is not yet stable, so the UWP directory
// needs to be created on the fly with 'flutter create .'
Directory? temporaryPlatformDirectory;
if (flutterBuildType == _flutterBuildTypeWinUwp) {
final Directory uwpDirectory = example.directory.childDirectory('winuwp');
if (!uwpDirectory.existsSync()) {
print('Creating temporary winuwp folder');
final int exitCode = await processRunner.runAndStream(flutterCommand,
<String>['create', '--platforms=$kPlatformWinUwp', '.'],
workingDir: example.directory);
if (exitCode == 0) {
temporaryPlatformDirectory = uwpDirectory;
}
}
}
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
@ -167,6 +201,13 @@ class BuildExamplesCommand extends PackageLoopingCommand {
],
workingDir: example.directory,
);
if (temporaryPlatformDirectory != null &&
temporaryPlatformDirectory.existsSync()) {
print('Cleaning up ${temporaryPlatformDirectory.path}');
temporaryPlatformDirectory.deleteSync(recursive: true);
}
return exitCode == 0;
}
}
@ -176,6 +217,7 @@ class _PlatformDetails {
const _PlatformDetails(
this.label, {
required this.pluginPlatform,
this.pluginPlatformVariant,
required this.flutterBuildType,
this.extraBuildFlags = const <String>[],
});
@ -186,6 +228,10 @@ class _PlatformDetails {
/// The key in a pubspec's platform: entry.
final String pluginPlatform;
/// The supportedVariants key under a plugin's [pluginPlatform] entry, if
/// applicable.
final String? pluginPlatformVariant;
/// The `flutter build` build type.
final String flutterBuildType;

View File

@ -10,24 +10,43 @@ import 'package:yaml/yaml.dart';
/// print destination.
typedef Print = void Function(Object? object);
/// Key for windows platform.
const String kPlatformWindows = 'windows';
/// Key for macos platform.
const String kPlatformMacos = 'macos';
/// Key for linux platform.
const String kPlatformLinux = 'linux';
/// Key for APK (Android) platform.
const String kPlatformAndroid = 'android';
/// Key for IPA (iOS) platform.
const String kPlatformIos = 'ios';
/// Key for APK (Android) platform.
const String kPlatformAndroid = 'android';
/// Key for linux platform.
const String kPlatformLinux = 'linux';
/// Key for macos platform.
const String kPlatformMacos = 'macos';
/// Key for Web platform.
const String kPlatformWeb = 'web';
/// Key for windows platform.
///
/// Note that this corresponds to the Win32 variant for flutter commands like
/// `build` and `run`, but is a general platform containing all Windows
/// variants for purposes of the `platform` section of a plugin pubspec).
const String kPlatformWindows = 'windows';
/// Key for WinUWP platform.
///
/// Note that UWP is a platform for the purposes of flutter commands like
/// `build` and `run`, but a variant of the `windows` platform for the purposes
/// of plugin pubspecs).
const String kPlatformWinUwp = 'winuwp';
/// Key for Win32 variant of the Windows platform.
const String platformVariantWin32 = 'win32';
/// Key for UWP variant of the Windows platform.
///
/// See the note on [kPlatformWinUwp].
const String platformVariantWinUwp = 'uwp';
/// Key for enable experiment.
const String kEnableExperiment = 'enable-experiment';

View File

@ -28,8 +28,12 @@ enum PlatformSupport {
///
/// If [requiredMode] is provided, the plugin must have the given type of
/// implementation in order to return true.
bool pluginSupportsPlatform(String platform, RepositoryPackage package,
{PlatformSupport? requiredMode}) {
bool pluginSupportsPlatform(
String platform,
RepositoryPackage package, {
PlatformSupport? requiredMode,
String? variant,
}) {
assert(platform == kPlatformIos ||
platform == kPlatformAndroid ||
platform == kPlatformWeb ||
@ -65,9 +69,34 @@ bool pluginSupportsPlatform(String platform, RepositoryPackage package,
}
// If the platform entry is present, then it supports the platform. Check
// for required mode if specified.
if (requiredMode != null) {
final bool federated = platformEntry.containsKey('default_package');
return requiredMode == null ||
federated == (requiredMode == PlatformSupport.federated);
if (federated != (requiredMode == PlatformSupport.federated)) {
return false;
}
}
// If a variant is specified, check for that variant.
if (variant != null) {
const String variantsKey = 'supportedVariants';
if (platformEntry.containsKey(variantsKey)) {
if (!(platformEntry['supportedVariants']! as YamlList)
.contains(variant)) {
return false;
}
} else {
// Platforms with variants have a default variant when unspecified for
// backward compatibility. Must match the flutter tool logic.
const Map<String, String> defaultVariants = <String, String>{
kPlatformWindows: platformVariantWin32,
};
if (variant != defaultVariants[platform]) {
return false;
}
}
}
return true;
} on FileSystemException {
return false;
} on YamlException {

View File

@ -36,7 +36,10 @@ class DriveExamplesCommand extends PackageLoopingCommand {
argParser.addFlag(kPlatformWeb,
help: 'Runs the web implementation of the examples');
argParser.addFlag(kPlatformWindows,
help: 'Runs the Windows implementation of the examples');
help: 'Runs the Windows (Win32) implementation of the examples');
argParser.addFlag(kPlatformWinUwp,
help:
'Runs the UWP implementation of the examples [currently a no-op]');
argParser.addOption(
kEnableExperiment,
defaultsTo: '',
@ -67,6 +70,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
kPlatformMacos,
kPlatformWeb,
kPlatformWindows,
kPlatformWinUwp,
];
final int platformCount = platformSwitches
.where((String platform) => getBoolArg(platform))
@ -81,6 +85,10 @@ class DriveExamplesCommand extends PackageLoopingCommand {
throw ToolExit(_exitNoPlatformFlags);
}
if (getBoolArg(kPlatformWinUwp)) {
logWarning('Driving UWP applications is not yet supported');
}
String? androidDevice;
if (getBoolArg(kPlatformAndroid)) {
final List<String> devices = await _getDevicesForPlatform('android');
@ -116,6 +124,10 @@ class DriveExamplesCommand extends PackageLoopingCommand {
],
if (getBoolArg(kPlatformWindows))
kPlatformWindows: <String>['-d', 'windows'],
// TODO(stuartmorgan): Check these flags once drive supports UWP:
// https://github.com/flutter/flutter/issues/82821
if (getBoolArg(kPlatformWinUwp))
kPlatformWinUwp: <String>['-d', 'winuwp'],
};
}
@ -132,7 +144,17 @@ class DriveExamplesCommand extends PackageLoopingCommand {
final List<String> deviceFlags = <String>[];
for (final MapEntry<String, List<String>> entry
in _targetDeviceFlags.entries) {
if (pluginSupportsPlatform(entry.key, package)) {
final String platform = entry.key;
String? variant;
if (platform == kPlatformWindows) {
variant = platformVariantWin32;
} else if (platform == kPlatformWinUwp) {
variant = platformVariantWinUwp;
// TODO(stuartmorgan): Remove this once drive supports UWP.
// https://github.com/flutter/flutter/issues/82821
return PackageResult.skip('Drive does not yet support UWP');
}
if (pluginSupportsPlatform(platform, package, variant: variant)) {
deviceFlags.addAll(entry.value);
} else {
print('Skipping unsupported platform ${entry.key}...');

View File

@ -56,8 +56,8 @@ void main() {
test('fails if building fails', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
});
processRunner
@ -106,8 +106,8 @@ void main() {
test('building for iOS', () async {
mockPlatform.isMacOS = true;
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -163,8 +163,8 @@ void main() {
test('building for Linux', () async {
mockPlatform.isLinux = true;
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformLinux: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -212,8 +212,8 @@ void main() {
test('building for macOS', () async {
mockPlatform.isMacOS = true;
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -258,8 +258,8 @@ void main() {
test('building for web', () async {
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -284,7 +284,7 @@ void main() {
});
test(
'building for Windows when plugin is not set up for Windows results in no-op',
'building for win32 when plugin is not set up for Windows results in no-op',
() async {
mockPlatform.isWindows = true;
createFakePlugin('plugin', packagesDir);
@ -296,7 +296,7 @@ void main() {
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin'),
contains('Windows is not supported by this plugin'),
contains('Win32 is not supported by this plugin'),
]),
);
@ -305,11 +305,11 @@ void main() {
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
});
test('building for Windows', () async {
test('building for win32', () async {
mockPlatform.isWindows = true;
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformWindows: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -321,7 +321,7 @@ void main() {
expect(
output,
containsAllInOrder(<String>[
'\nBUILDING plugin/example for Windows',
'\nBUILDING plugin/example for Win32 (windows)',
]),
);
@ -335,6 +335,91 @@ void main() {
]));
});
test('building for UWP when plugin does not support UWP is a no-op',
() async {
createFakePlugin('plugin', packagesDir);
final List<String> output = await runCapturingPrint(
runner, <String>['build-examples', '--winuwp']);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin'),
contains('UWP is not supported by this plugin'),
]),
);
print(processRunner.recordedCalls);
// Output should be empty since running build-examples --macos with no macos
// implementation is a no-op.
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
});
test('building for UWP', () async {
final Directory pluginDirectory =
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
'example/test',
], platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.federated,
variants: <String>[platformVariantWinUwp]),
});
final Directory pluginExampleDirectory =
pluginDirectory.childDirectory('example');
final List<String> output = await runCapturingPrint(
runner, <String>['build-examples', '--winuwp']);
expect(
output,
containsAllInOrder(<Matcher>[
contains('BUILDING plugin/example for UWP (winuwp)'),
]),
);
print(processRunner.recordedCalls);
expect(
processRunner.recordedCalls,
containsAll(<ProcessCall>[
ProcessCall(getFlutterCommand(mockPlatform),
const <String>['build', 'winuwp'], pluginExampleDirectory.path),
]));
});
test('building for UWP creates a folder if necessary', () async {
final Directory pluginDirectory =
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
'example/test',
], platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.federated,
variants: <String>[platformVariantWinUwp]),
});
final Directory pluginExampleDirectory =
pluginDirectory.childDirectory('example');
final List<String> output = await runCapturingPrint(
runner, <String>['build-examples', '--winuwp']);
expect(
output,
contains('Creating temporary winuwp folder'),
);
print(processRunner.recordedCalls);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>['create', '--platforms=winuwp', '.'],
pluginExampleDirectory.path),
ProcessCall(getFlutterCommand(mockPlatform),
const <String>['build', 'winuwp'], pluginExampleDirectory.path),
]));
});
test(
'building for Android when plugin is not set up for Android results in no-op',
() async {
@ -358,8 +443,8 @@ void main() {
test('building for Android', () async {
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -387,8 +472,8 @@ void main() {
test('enable-experiment flag for Android', () async {
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -409,8 +494,8 @@ void main() {
test('enable-experiment flag for ios', () async {
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =

View File

@ -36,13 +36,13 @@ void main() {
test('all platforms', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
kPlatformWindows: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
kPlatformWindows: const PlatformDetails(PlatformSupport.inline),
}));
expect(pluginSupportsPlatform(kPlatformAndroid, plugin), isTrue);
@ -55,14 +55,12 @@ void main() {
test('some platforms', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
},
));
'plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
}));
expect(pluginSupportsPlatform(kPlatformAndroid, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformIos, plugin), isFalse);
@ -74,17 +72,15 @@ void main() {
test('inline plugins are only detected as inline', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
kPlatformWindows: PlatformSupport.inline,
},
));
'plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
kPlatformWindows: const PlatformDetails(PlatformSupport.inline),
}));
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
@ -137,19 +133,16 @@ void main() {
});
test('federated plugins are only detected as federated', () async {
const String pluginName = 'plugin';
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
pluginName,
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.federated,
kPlatformIos: PlatformSupport.federated,
kPlatformLinux: PlatformSupport.federated,
kPlatformMacos: PlatformSupport.federated,
kPlatformWeb: PlatformSupport.federated,
kPlatformWindows: PlatformSupport.federated,
},
));
'plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.federated),
kPlatformIos: const PlatformDetails(PlatformSupport.federated),
kPlatformLinux: const PlatformDetails(PlatformSupport.federated),
kPlatformMacos: const PlatformDetails(PlatformSupport.federated),
kPlatformWeb: const PlatformDetails(PlatformSupport.federated),
kPlatformWindows: const PlatformDetails(PlatformSupport.federated),
}));
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
@ -200,5 +193,84 @@ void main() {
requiredMode: PlatformSupport.inline),
isFalse);
});
test('windows without variants is only win32', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.inline),
},
));
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWin32),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWinUwp),
isFalse);
});
test('windows with both variants matches win32 and winuwp', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(
PlatformSupport.federated,
variants: <String>[platformVariantWin32, platformVariantWinUwp],
),
}));
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWin32),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWinUwp),
isTrue);
});
test('win32 plugin is only win32', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(
PlatformSupport.federated,
variants: <String>[platformVariantWin32],
),
}));
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWin32),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWinUwp),
isFalse);
});
test('winup plugin is only winuwp', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.federated,
variants: <String>[platformVariantWinUwp]),
},
));
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWin32),
isFalse);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
variant: platformVariantWinUwp),
isTrue);
});
});
}

View File

@ -21,7 +21,7 @@ void main() {
setUp(() {
// Since the core of this command is a call to 'flutter create', the test
// has to use the real filesystem. Put everything possible in a unique
// temporary to minimize affect on the host system.
// temporary to minimize effect on the host system.
fileSystem = const LocalFileSystem();
testRoot = fileSystem.systemTempDirectory.createTempSync();
packagesDir = testRoot.childDirectory('packages');

View File

@ -127,8 +127,8 @@ void main() {
'example/test_driver/integration_test.dart',
'example/integration_test/foo_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -192,9 +192,9 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -242,9 +242,9 @@ void main() {
extraFiles: <String>[
'example/test_driver/plugin_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -275,9 +275,9 @@ void main() {
extraFiles: <String>[
'example/lib/main.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -311,9 +311,9 @@ void main() {
'example/integration_test/foo_test.dart',
'example/integration_test/ignore_me.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -397,8 +397,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformLinux: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
},
);
@ -470,8 +470,8 @@ void main() {
'example/test_driver/plugin.dart',
'example/macos/macos.swift',
],
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -541,8 +541,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
},
);
@ -615,8 +615,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformWindows: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.inline),
},
);
@ -654,6 +654,40 @@ void main() {
]));
});
test('driving UWP is a no-op', () async {
createFakePlugin(
'plugin',
packagesDir,
extraFiles: <String>[
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformDetails>{
kPlatformWindows: const PlatformDetails(PlatformSupport.inline,
variants: <String>[platformVariantWinUwp]),
},
);
final List<String> output = await runCapturingPrint(runner, <String>[
'drive-examples',
'--winuwp',
]);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Driving UWP applications is not yet supported'),
contains('Running for plugin'),
contains('SKIPPING: Drive does not yet support UWP'),
contains('No issues found!'),
]),
);
// Output should be empty since running drive-examples --windows on a
// non-Windows plugin is a no-op.
expect(processRunner.recordedCalls, <ProcessCall>[]);
});
test('driving on an Android plugin', () async {
final Directory pluginDirectory = createFakePlugin(
'plugin',
@ -662,8 +696,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
},
);
@ -712,8 +746,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -745,8 +779,8 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -800,9 +834,9 @@ void main() {
'example/test_driver/plugin_test.dart',
'example/test_driver/plugin.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -842,8 +876,8 @@ void main() {
'plugin',
packagesDir,
examples: <String>[],
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
},
);
@ -874,8 +908,8 @@ void main() {
'example/integration_test/bar_test.dart',
'example/integration_test/foo_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
},
);
@ -906,8 +940,8 @@ void main() {
extraFiles: <String>[
'example/test_driver/integration_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
},
);
@ -942,8 +976,8 @@ void main() {
'example/integration_test/bar_test.dart',
'example/integration_test/foo_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
},
);

View File

@ -43,8 +43,8 @@ void main() {
final Directory pluginDir =
createFakePlugin('plugin1', packagesDir, extraFiles: <String>[
'example/android/gradlew',
], platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
], platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
final Directory androidDir =
@ -74,8 +74,8 @@ void main() {
test('fails if gradlew is missing', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
Error? commandError;
@ -96,8 +96,8 @@ void main() {
test('fails if linting finds issues', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
processRunner.mockProcessesForExecutable['gradlew'] = <io.Process>[
@ -138,8 +138,8 @@ void main() {
test('skips non-inline plugins', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.federated
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.federated)
});
final List<String> output =

View File

@ -115,8 +115,8 @@ void main() {
test('reports skips with no tests', () async {
final Directory pluginDirectory1 = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -154,8 +154,8 @@ void main() {
group('iOS', () {
test('skip if iOS is not supported', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final List<String> output = await runCapturingPrint(runner,
@ -171,8 +171,8 @@ void main() {
test('skip if iOS is implemented in a federated package', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.federated
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.federated)
});
final List<String> output = await runCapturingPrint(runner,
@ -188,8 +188,8 @@ void main() {
test('running with correct destination', () async {
final Directory pluginDirectory = createFakePlugin(
'plugin', packagesDir, platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
'plugin', packagesDir, platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
final Directory pluginExampleDirectory =
@ -234,8 +234,8 @@ void main() {
test('Not specifying --ios-destination assigns an available simulator',
() async {
final Directory pluginDirectory = createFakePlugin(
'plugin', packagesDir, platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
'plugin', packagesDir, platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
final Directory pluginExampleDirectory =
pluginDirectory.childDirectory('example');
@ -298,8 +298,8 @@ void main() {
test('skip if macOS is implemented in a federated package', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.federated,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.federated),
});
final List<String> output =
@ -317,8 +317,8 @@ void main() {
test('runs for macOS plugin', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -360,8 +360,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -390,8 +390,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -420,8 +420,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -455,8 +455,8 @@ void main() {
createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -480,8 +480,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'android/src/test/example_test.java',
@ -519,8 +519,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'android/src/test/example_test.java',
@ -554,8 +554,8 @@ void main() {
final Directory plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'android/src/test/example_test.java',
@ -586,8 +586,8 @@ void main() {
createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/app/src/test/example_test.java',
@ -618,8 +618,8 @@ void main() {
createFakePlugin(
'plugin1',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -630,8 +630,8 @@ void main() {
createFakePlugin(
'plugin2',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'android/src/test/example_test.java',
@ -657,8 +657,8 @@ void main() {
final Directory pluginDir = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
extraFiles: <String>[
'example/android/gradlew',
@ -716,8 +716,8 @@ void main() {
createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
},
);
@ -739,8 +739,8 @@ void main() {
group('iOS/macOS', () {
test('fails if xcrun fails', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
processRunner.mockProcessesForExecutable['xcrun'] = <io.Process>[
@ -767,8 +767,8 @@ void main() {
test('honors unit-only', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -832,8 +832,8 @@ void main() {
test('honors integration-only', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -897,8 +897,8 @@ void main() {
test('skips when the requested target is not present', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -950,8 +950,8 @@ void main() {
test('fails if unable to check for requested target', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -1007,10 +1007,10 @@ void main() {
'example/android/gradlew',
'android/src/test/example_test.java',
],
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
},
);
@ -1077,8 +1077,8 @@ void main() {
test('runs only macOS for a macOS plugin', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -1121,8 +1121,8 @@ void main() {
test('runs only iOS for a iOS plugin', () async {
final Directory pluginDirectory = createFakePlugin(
'plugin', packagesDir, platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
'plugin', packagesDir, platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
final Directory pluginExampleDirectory =
@ -1193,9 +1193,9 @@ void main() {
final Directory pluginDir = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
extraFiles: <String>[
'example/android/gradlew',
@ -1244,9 +1244,9 @@ void main() {
final Directory pluginDir = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline),
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
},
extraFiles: <String>[
'example/android/gradlew',

View File

@ -180,8 +180,8 @@ void main() {
'plugin',
packagesDir,
extraFiles: <String>['test/empty_test.dart'],
platformSupport: <String, PlatformSupport>{
kPlatformWeb: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformWeb: const PlatformDetails(PlatformSupport.inline),
},
);

View File

@ -41,6 +41,21 @@ Directory createPackagesDirectory(
return packagesDir;
}
/// Details for platform support in a plugin.
@immutable
class PlatformDetails {
const PlatformDetails(
this.type, {
this.variants = const <String>[],
});
/// The type of support for the platform.
final PlatformSupport type;
/// Any 'supportVariants' to list in the pubspec.
final List<String> variants;
}
/// Creates a plugin package with the given [name] in [packagesDirectory].
///
/// [platformSupport] is a map of platform string to the support details for
@ -54,8 +69,8 @@ Directory createFakePlugin(
Directory parentDirectory, {
List<String> examples = const <String>['example'],
List<String> extraFiles = const <String>[],
Map<String, PlatformSupport> platformSupport =
const <String, PlatformSupport>{},
Map<String, PlatformDetails> platformSupport =
const <String, PlatformDetails>{},
String? version = '0.0.1',
}) {
final Directory pluginDirectory = createFakePackage(name, parentDirectory,
@ -143,8 +158,8 @@ void createFakePubspec(
String name = 'fake_package',
bool isFlutter = true,
bool isPlugin = false,
Map<String, PlatformSupport> platformSupport =
const <String, PlatformSupport>{},
Map<String, PlatformDetails> platformSupport =
const <String, PlatformDetails>{},
String publishTo = 'http://no_pub_server.com',
String? version,
}) {
@ -160,12 +175,11 @@ flutter:
plugin:
platforms:
''';
for (final MapEntry<String, PlatformSupport> platform
for (final MapEntry<String, PlatformDetails> platform
in platformSupport.entries) {
yaml += _pluginPlatformSection(platform.key, platform.value, name);
}
}
yaml += '''
dependencies:
flutter:
@ -186,50 +200,73 @@ publish_to: $publishTo # Hardcoded safeguard to prevent this from somehow being
}
String _pluginPlatformSection(
String platform, PlatformSupport type, String packageName) {
if (type == PlatformSupport.federated) {
return '''
String platform, PlatformDetails support, String packageName) {
String entry = '';
// Build the main plugin entry.
if (support.type == PlatformSupport.federated) {
entry = '''
$platform:
default_package: ${packageName}_$platform
''';
}
} else {
switch (platform) {
case kPlatformAndroid:
return '''
entry = '''
android:
package: io.flutter.plugins.fake
pluginClass: FakePlugin
''';
break;
case kPlatformIos:
return '''
entry = '''
ios:
pluginClass: FLTFakePlugin
''';
break;
case kPlatformLinux:
return '''
entry = '''
linux:
pluginClass: FakePlugin
''';
break;
case kPlatformMacos:
return '''
entry = '''
macos:
pluginClass: FakePlugin
''';
break;
case kPlatformWeb:
return '''
entry = '''
web:
pluginClass: FakePlugin
fileName: ${packageName}_web.dart
''';
break;
case kPlatformWindows:
return '''
entry = '''
windows:
pluginClass: FakePlugin
''';
break;
default:
assert(false);
return '';
assert(false, 'Unrecognized platform: $platform');
break;
}
}
// Add any variants.
if (support.variants.isNotEmpty) {
entry += '''
supportedVariants:
''';
for (final String variant in support.variants) {
entry += '''
- $variant
''';
}
}
return entry;
}
typedef _ErrorHandler = void Function(Error error);

View File

@ -57,8 +57,8 @@ void main() {
group('iOS', () {
test('skip if iOS is not supported', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final List<String> output =
@ -70,8 +70,8 @@ void main() {
test('skip if iOS is implemented in a federated package', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.federated
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.federated)
});
final List<String> output =
@ -83,8 +83,8 @@ void main() {
test('runs for iOS plugin', () async {
final Directory pluginDirectory = createFakePlugin(
'plugin', packagesDir, platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
'plugin', packagesDir, platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
final Directory pluginExampleDirectory =
@ -126,8 +126,8 @@ void main() {
test('fails if xcrun fails', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
processRunner.mockProcessesForExecutable['xcrun'] = <io.Process>[
@ -172,8 +172,8 @@ void main() {
test('skip if macOS is implemented in a federated package', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.federated,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.federated),
});
final List<String> output = await runCapturingPrint(
@ -186,8 +186,8 @@ void main() {
test('runs for macOS plugin', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -223,8 +223,8 @@ void main() {
test('fails if xcrun fails', () async {
createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
processRunner.mockProcessesForExecutable['xcrun'] = <io.Process>[
@ -253,9 +253,9 @@ void main() {
test('runs both iOS and macOS when supported', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline),
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -313,8 +313,8 @@ void main() {
test('runs only macOS for a macOS plugin', () async {
final Directory pluginDirectory1 = createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformMacos: PlatformSupport.inline,
platformSupport: <String, PlatformDetails>{
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
});
final Directory pluginExampleDirectory =
@ -354,8 +354,8 @@ void main() {
test('runs only iOS for a iOS plugin', () async {
final Directory pluginDirectory = createFakePlugin(
'plugin', packagesDir, platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline
'plugin', packagesDir, platformSupport: <String, PlatformDetails>{
kPlatformIos: const PlatformDetails(PlatformSupport.inline)
});
final Directory pluginExampleDirectory =