Skip to content

[tool] Notify app developers of plugins that are incompatible with Swift Package Manager #152038

@loic-sharma

Description

@loic-sharma

Print a warning when using a plugin that does not support SwiftPM and guided message to inform app developer to file an issue with the plugin author.

This is likely a good place to put the warning:

/// Returns count of total number of plugins, number of Swift Package Manager compatible plugins,
/// and number of CocoaPods compatible plugins. A plugin can be both Swift Package Manager and
/// CocoaPods compatible.
///
/// If [hostPlatformIsMacOS], prints warnings when using a plugin incompatible with the available
/// Darwin Dependency Manager (Swift Package Manager or CocoaPods).
///
/// If [hostPlatformIsMacOS], prints message prompting the user to deintegrate CocoaPods if
/// using all Swift Package plugins.
Future<({int totalCount, int swiftPackageCount, int podCount})> _evaluatePluginsAndPrintWarnings({
required FlutterDarwinPlatform platform,
required XcodeBasedProject xcodeProject,
required bool hostPlatformIsMacOS,
}) async {
var pluginCount = 0;
var swiftPackageCount = 0;
var cocoapodCount = 0;
for (final Plugin plugin in _plugins) {
if (plugin.platforms[platform.name] == null) {
continue;
}
final String? swiftPackagePath = plugin.pluginSwiftPackageManifestPath(
_fileSystem,
platform.name,
);
final bool swiftPackageManagerCompatible =
swiftPackagePath != null && _fileSystem.file(swiftPackagePath).existsSync();
final String? podspecPath = plugin.pluginPodspecPath(_fileSystem, platform.name);
final bool cocoaPodsCompatible =
podspecPath != null && _fileSystem.file(podspecPath).existsSync();
// If a plugin is missing both a Package.swift and Podspec, it won't be
// included by either Swift Package Manager or Cocoapods. This can happen
// when a plugin doesn't have native platform code.
// For example, image_picker_macos only uses dart code.
if (!swiftPackageManagerCompatible && !cocoaPodsCompatible) {
continue;
}
pluginCount += 1;
if (swiftPackageManagerCompatible) {
swiftPackageCount += 1;
}
if (cocoaPodsCompatible) {
cocoapodCount += 1;
}
// If not using Swift Package Manager and plugin does not have podspec
// but does have a Package.swift, throw an error. Otherwise, it'll error
// when it builds.
if (hostPlatformIsMacOS &&
!xcodeProject.usesSwiftPackageManager &&
!cocoaPodsCompatible &&
swiftPackageManagerCompatible) {
throwToolExit(
'Plugin ${plugin.name} is only Swift Package Manager compatible. Try '
'enabling Swift Package Manager by running '
'"flutter config --enable-swift-package-manager" or remove the '
'plugin as a dependency.',
);
}
}
// Only show warnings to remove CocoaPods if the project is using Swift
// Package Manager, has already been migrated to have SPM integration, and
// all plugins are Swift Packages.
if (xcodeProject.usesSwiftPackageManager &&
xcodeProject.flutterPluginSwiftPackageInProjectSettings &&
pluginCount == swiftPackageCount &&
swiftPackageCount != 0) {
final bool podfileExists = xcodeProject.podfile.existsSync();
if (podfileExists) {
// If all plugins are Swift Packages and the Podfile matches the
// default template, recommend pod deintegration.
final File podfileTemplate = await _cocoapods.getPodfileTemplate(
xcodeProject,
xcodeProject.xcodeProject,
);
final configWarning =
'${_podIncludeInConfigWarning(xcodeProject, 'Debug')}'
'${_podIncludeInConfigWarning(xcodeProject, 'Release')}';
if (hostPlatformIsMacOS &&
xcodeProject.podfile.readAsStringSync() == podfileTemplate.readAsStringSync()) {
_logger.printWarning(
'All plugins found for ${platform.name} are Swift Packages, but your '
'project still has CocoaPods integration. To remove CocoaPods '
'integration, complete the following steps:\n'
' * In the ${platform.name}/ directory run "pod deintegrate"\n'
' * Also in the ${platform.name}/ directory, delete the Podfile\n'
'$configWarning\n'
"Removing CocoaPods integration will improve the project's build time.",
);
} else if (hostPlatformIsMacOS) {
// If all plugins are Swift Packages, but the Podfile has custom logic,
// recommend migrating manually.
_logger.printWarning(
'All plugins found for ${platform.name} are Swift Packages, but your '
'project still has CocoaPods integration. Your project uses a '
'non-standard Podfile and will need to be migrated to Swift Package '
'Manager manually. Some steps you may need to complete include:\n'
' * In the ${platform.name}/ directory run "pod deintegrate"\n'
' * Transition any Pod dependencies to Swift Package equivalents. '
'See https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app\n'
' * Transition any custom logic\n'
'$configWarning\n'
"Removing CocoaPods integration will improve the project's build time.",
);
}
}
}
return (totalCount: pluginCount, swiftPackageCount: swiftPackageCount, podCount: cocoapodCount);
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listplatform-iosiOS applications specificallyplatform-macBuilding on or for macOS specificallyteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions