Skip to content

Commit bf29b60

Browse files
authored
[iOS][add2app] Skip building SwiftPM plugins when generating CocoaPods artifacts (flutter#190736)
When using "flutter build swift-packages" using a Flutter module, the command to build the CocoaPods frameworks also builds plugins that support SwiftPM. They are then later excluded. This exclusion, however, neglected to handle transitive dependencies. This PR changes it so that the command no longer builds them in the first place. Fixes flutter#184590. Fixes flutter#189443. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 4bdb8c6 commit bf29b60

6 files changed

Lines changed: 237 additions & 224 deletions

File tree

‎packages/flutter_tools/lib/src/commands/build_swift_package.dart‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ class BuildSwiftPackage extends BuildSubCommand {
399399
xcframeworkOutput: xcframeworkOutput,
400400
codesignIdentity: codesignIdentity,
401401
codesignIdentityFile: codesignIdentityFile,
402-
pluginSwiftDependencies: pluginSwiftDependencies,
403402
);
404403
}
405404

@@ -1510,7 +1509,6 @@ class CocoaPodPluginDependencies {
15101509
required bool buildStatic,
15111510
required String? codesignIdentity,
15121511
required File codesignIdentityFile,
1513-
required FlutterPluginSwiftDependencies pluginSwiftDependencies,
15141512
}) async {
15151513
final String xcodeBuildConfiguration = buildInfo.mode.uppercaseName;
15161514
if (!_xcodeProject.podfile.existsSync()) {
@@ -1541,6 +1539,22 @@ class CocoaPodPluginDependencies {
15411539
ErrorHandlingFileSystem.deleteIfExists(cocoapodXCFrameworkOutput, recursive: true);
15421540
}
15431541

1542+
if (_utils.project.isModule) {
1543+
// Flutter modules generate a FlutterPluginRegistrant framework, but "flutter build
1544+
// swift-package" uses a Swift package for the FlutterPluginRegistrant instead. Since
1545+
// SwiftPM compatible pods are skipped, overwrite the FlutterPluginRegistrant.podspec to
1546+
// have no dependencies to avoid build failures due to missing dependencies (that are now
1547+
// SwiftPM). FlutterPluginRegistrant will be skipped in [_findFrameworks] anyway.
1548+
//
1549+
// TODO(vashworth): Find a way to prevent CocoaPods from building FlutterPluginRegistrant
1550+
// during this command when using a module in the first place.
1551+
await writeIOSPluginRegistrant(
1552+
_utils.project,
1553+
[],
1554+
templateRenderer: _utils.templateRenderer,
1555+
);
1556+
}
1557+
15441558
await processPods(_xcodeProject, buildInfo);
15451559
// Pods directory may not exist until after `processPods` is called.
15461560
final Directory podsDirectory = _xcodeProject.hostAppRoot.childDirectory('Pods');
@@ -1560,7 +1574,6 @@ class CocoaPodPluginDependencies {
15601574
buildStatic: buildStatic,
15611575
outputBuildDirectory: outputBuildDirectory,
15621576
podsDirectory: podsDirectory,
1563-
pluginSwiftDependencies: pluginSwiftDependencies,
15641577
);
15651578
sdkSpecificFrameworks.forEach((String name, List<Directory> frameworks) {
15661579
frameworksPerPod.putIfAbsent(name, () => <Directory>[]).addAll(frameworks);
@@ -1597,7 +1610,18 @@ class CocoaPodPluginDependencies {
15971610
@visibleForTesting
15981611
/// Wrap [processPodsIfNeeded] in a method to be overwritten in tests.
15991612
Future<void> processPods(XcodeBasedProject xcodeProject, BuildInfo buildInfo) async {
1600-
await processPodsIfNeeded(xcodeProject, _targetPlatform.buildDirectory(), buildInfo.mode);
1613+
await processPodsIfNeeded(
1614+
xcodeProject,
1615+
_targetPlatform.buildDirectory(),
1616+
buildInfo.mode,
1617+
// Normal module builds (like when running "flutter build ios" with a module), do not support
1618+
// SwiftPM. Since "flutter build swift-package" builds Swift packages and CocoaPods
1619+
// separately, we need to force SwiftPM to be enabled so that CocoaPods will skip processing
1620+
// plugins that support SwiftPM. Forcing SwiftPM to be enabled here causes
1621+
// `swift_package_manager_enabled` to be set to true in .flutter-plugins-dependencies, which
1622+
// podhelper.rb then uses to skip processing SwiftPM-compatible pods.
1623+
forceSwiftPM: true,
1624+
);
16011625
}
16021626

16031627
/// Builds CocoaPod plugins into frameworks for the given [xcodeBuildConfiguration], [platform],
@@ -1612,7 +1636,6 @@ class CocoaPodPluginDependencies {
16121636
required bool buildStatic,
16131637
required Directory outputBuildDirectory,
16141638
required Directory podsDirectory,
1615-
required FlutterPluginSwiftDependencies pluginSwiftDependencies,
16161639
}) async {
16171640
final String configuration = _configurationForSdkType(sdk, xcodeBuildConfiguration);
16181641
final ProcessResult buildPluginsResult = await _utils.processManager.run(<String>[
@@ -1641,7 +1664,7 @@ class CocoaPodPluginDependencies {
16411664
'$configuration-${sdk.platformName}',
16421665
);
16431666
}
1644-
return _findFrameworks(configurationBuildDir, pluginSwiftDependencies);
1667+
return _findFrameworks(configurationBuildDir);
16451668
}
16461669

16471670
/// Iterates through the build files and find .frameworks
@@ -1652,10 +1675,7 @@ class CocoaPodPluginDependencies {
16521675
/// > plugin_a
16531676
/// > plugin_a.framework
16541677
/// ```
1655-
Future<Map<String, List<Directory>>> _findFrameworks(
1656-
Directory configurationBuildDir,
1657-
FlutterPluginSwiftDependencies pluginSwiftDependencies,
1658-
) async {
1678+
Future<Map<String, List<Directory>>> _findFrameworks(Directory configurationBuildDir) async {
16591679
final frameworks = <String, List<Directory>>{};
16601680

16611681
final Iterable<Directory> products = configurationBuildDir
@@ -1669,18 +1689,10 @@ class CocoaPodPluginDependencies {
16691689
continue;
16701690
}
16711691
final String binaryName = _utils.fileSystem.path.basenameWithoutExtension(podFrameworkName);
1672-
if (_utils.project.isModule &&
1673-
(binaryName == 'FlutterPluginRegistrant' ||
1674-
pluginSwiftDependencies.copiedPlugins.any((record) => record.name == binaryName))) {
1675-
// Flutter modules don't support SwiftPM and force all plugins to be built as CocoaPods.
1676-
// Since SwiftPM supported plugins are used as Swift packages in this command, they should
1677-
// be skipped and not included as CocoaPod framework dependencies.
1678-
// In addition, modules generate a FlutterPluginRegistrant framework. Since the
1679-
// FlutterPluginRegistrant is also being used as a Swift Package in this command, it should
1680-
// also be skipped.
1681-
// TODO(vashworth): Find a way to prevent CocoaPods from building SwiftPM plugins and
1682-
// FlutterPluginRegistrant when using a module in the first place.
1683-
// See https://github.com/flutter/flutter/issues/184590.
1692+
if (_utils.project.isModule && (binaryName == 'FlutterPluginRegistrant')) {
1693+
// Flutter modules generate a FlutterPluginRegistrant framework. Since the
1694+
// FlutterPluginRegistrant is being used as a Swift Package in this command, it should
1695+
// be skipped.
16841696
continue;
16851697
}
16861698
frameworks.putIfAbsent(binaryName, () => <Directory>[]).add(podProduct);

‎packages/flutter_tools/lib/src/flutter_plugins.dart‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@ Future<void> refreshPluginsList(
12991299
bool iosPlatform = false,
13001300
bool macOSPlatform = false,
13011301
bool forceCocoaPodsOnly = false,
1302+
bool forceSwiftPM = false,
13021303
PubspecCache? pubspecCache,
13031304
PackageGraph? packageGraph,
13041305
PackageConfig? packageConfig,
@@ -1314,7 +1315,10 @@ Future<void> refreshPluginsList(
13141315

13151316
var swiftPackageManagerEnabledIos = false;
13161317
var swiftPackageManagerEnabledMacos = false;
1317-
if (!forceCocoaPodsOnly) {
1318+
if (forceSwiftPM) {
1319+
swiftPackageManagerEnabledIos = true;
1320+
swiftPackageManagerEnabledMacos = true;
1321+
} else if (!forceCocoaPodsOnly) {
13181322
if (iosPlatform) {
13191323
swiftPackageManagerEnabledIos = project.ios.usesSwiftPackageManager;
13201324
}

‎packages/flutter_tools/lib/src/macos/cocoapod_utils.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Future<void> processPodsIfNeeded(
1919
String buildDirectory,
2020
BuildMode buildMode, {
2121
bool forceCocoaPodsOnly = false,
22+
bool forceSwiftPM = false,
2223
}) async {
2324
final FlutterProject project = xcodeProject.parent;
2425

@@ -35,6 +36,7 @@ Future<void> processPodsIfNeeded(
3536
iosPlatform: project.ios.existsSync(),
3637
macOSPlatform: project.macos.existsSync(),
3738
forceCocoaPodsOnly: forceCocoaPodsOnly,
39+
forceSwiftPM: forceSwiftPM,
3840
);
3941

4042
// If there are no plugins and if the project is a not module with an existing

0 commit comments

Comments
 (0)