Add CI steps to test iOS and macOS plugins with both CocoaPods and Swift Package Manager (#6557)

Tests new Swift Package Manager feature added in https://github.com/flutter/flutter/pull/146256.

Fixes https://github.com/flutter/flutter/issues/146901.
This commit is contained in:
Victoria Ashworth
2024-04-24 16:29:04 -05:00
committed by GitHub
parent 2925db2792
commit 1292dc30d8
4 changed files with 198 additions and 2 deletions

View File

@ -38,6 +38,9 @@ const String _flutterBuildTypeWindows = 'windows';
const String _flutterBuildTypeAndroidAlias = 'android';
/// Key for Swift Package Manager.
const String _swiftPackageManagerFlag = 'swift-package-manager';
/// A command to build the example applications for packages.
class BuildExamplesCommand extends PackageLoopingCommand {
/// Creates an instance of the build command.
@ -58,6 +61,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
defaultsTo: '',
help: 'Enables the given Dart SDK experiments.',
);
argParser.addFlag(_swiftPackageManagerFlag);
}
// Maps the switch this command uses to identify a platform to information
@ -111,6 +115,15 @@ class BuildExamplesCommand extends PackageLoopingCommand {
'single key "$_pluginToolsConfigGlobalKey" containing a list of build '
'arguments.';
/// Returns true if `--swift-package-manager` flag was passed along with
/// either `--ios` or `--macos`.
bool get usingSwiftPackageManager {
final List<String> platformFlags = _platforms.keys.toList();
return getBoolArg(_swiftPackageManagerFlag) &&
(platformFlags.contains(platformIOS) ||
platformFlags.contains(platformMacOS));
}
@override
Future<void> initializeRun() async {
final List<String> platformFlags = _platforms.keys.toList();
@ -121,6 +134,17 @@ class BuildExamplesCommand extends PackageLoopingCommand {
'were specified. At least one platform must be provided.');
throw ToolExit(_exitNoPlatformFlags);
}
// TODO(vashworth): Enable on stable once Swift Package Manager feature is
// available on stable.
if (usingSwiftPackageManager &&
platform.environment['CHANNEL'] != 'stable') {
await processRunner.runAndStream(
flutterCommand,
<String>['config', '--enable-swift-package-manager'],
exitOnError: true,
);
}
}
@override