Skip to content

Commit 74ab0a4

Browse files
vashworthIvoneDjaja
authored andcommitted
Hide SwiftPM warnings on non-mac platforms (flutter#178073)
Fixes flutter#162594. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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]. **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 [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 e3f7acc commit 74ab0a4

File tree

3 files changed

+79
-13
lines changed

3 files changed

+79
-13
lines changed

packages/flutter_tools/lib/src/flutter_plugins.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ Future<void> injectPlugins(
13121312
featureFlags: featureFlags,
13131313
logger: globals.logger,
13141314
analytics: globals.analytics,
1315+
platform: globals.platform,
13151316
);
13161317
if (iosPlatform) {
13171318
await darwinDependencyManagerSetup.setUp(platform: FlutterDarwinPlatform.ios);

packages/flutter_tools/lib/src/macos/darwin_dependency_management.dart

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:unified_analytics/unified_analytics.dart';
77
import '../base/common.dart';
88
import '../base/file_system.dart';
99
import '../base/logger.dart';
10+
import '../base/platform.dart';
1011
import '../darwin/darwin.dart';
1112
import '../features.dart';
1213
import '../plugins.dart';
@@ -28,14 +29,16 @@ class DarwinDependencyManagement {
2829
required FeatureFlags featureFlags,
2930
required Logger logger,
3031
required Analytics analytics,
32+
required Platform platform,
3133
}) : _project = project,
3234
_plugins = plugins,
3335
_cocoapods = cocoapods,
3436
_swiftPackageManager = swiftPackageManager,
3537
_fileSystem = fileSystem,
3638
_featureFlags = featureFlags,
3739
_logger = logger,
38-
_analytics = analytics;
40+
_analytics = analytics,
41+
_hostPlatform = platform;
3942

4043
final FlutterProject _project;
4144
final List<Plugin> _plugins;
@@ -45,6 +48,7 @@ class DarwinDependencyManagement {
4548
final FeatureFlags _featureFlags;
4649
final Logger _logger;
4750
final Analytics _analytics;
51+
final Platform _hostPlatform;
4852

4953
/// Generates/updates required files and project settings for Darwin
5054
/// Dependency Managers (CocoaPods and Swift Package Manager). Projects may
@@ -75,8 +79,15 @@ class DarwinDependencyManagement {
7579
if (_project.isModule) {
7680
return;
7781
}
78-
final (:int totalCount, :int swiftPackageCount, :int podCount) =
79-
await _evaluatePluginsAndPrintWarnings(platform: platform, xcodeProject: xcodeProject);
82+
final (
83+
:int totalCount,
84+
:int swiftPackageCount,
85+
:int podCount,
86+
) = await _evaluatePluginsAndPrintWarnings(
87+
platform: platform,
88+
xcodeProject: xcodeProject,
89+
hostPlatformIsMacOS: _hostPlatform.isMacOS,
90+
);
8091

8192
final bool useCocoapods;
8293
if (xcodeProject.usesSwiftPackageManager) {
@@ -115,18 +126,19 @@ class DarwinDependencyManagement {
115126
_analytics.send(event);
116127
}
117128

118-
/// Returns count of total number of plugins, number of Swift Package Manager
119-
/// compatible plugins, and number of CocoaPods compatible plugins. A plugin
120-
/// can be both Swift Package Manager and CocoaPods compatible.
129+
/// Returns count of total number of plugins, number of Swift Package Manager compatible plugins,
130+
/// and number of CocoaPods compatible plugins. A plugin can be both Swift Package Manager and
131+
/// CocoaPods compatible.
121132
///
122-
/// Prints warnings when using a plugin incompatible with the available Darwin
123-
/// Dependency Manager (Swift Package Manager or CocoaPods).
133+
/// If [hostPlatformIsMacOS], prints warnings when using a plugin incompatible with the available
134+
/// Darwin Dependency Manager (Swift Package Manager or CocoaPods).
124135
///
125-
/// Prints message prompting the user to deintegrate CocoaPods if using all
126-
/// Swift Package plugins.
136+
/// If [hostPlatformIsMacOS], prints message prompting the user to deintegrate CocoaPods if
137+
/// using all Swift Package plugins.
127138
Future<({int totalCount, int swiftPackageCount, int podCount})> _evaluatePluginsAndPrintWarnings({
128139
required FlutterDarwinPlatform platform,
129140
required XcodeBasedProject xcodeProject,
141+
required bool hostPlatformIsMacOS,
130142
}) async {
131143
var pluginCount = 0;
132144
var swiftPackageCount = 0;
@@ -165,7 +177,8 @@ class DarwinDependencyManagement {
165177
// If not using Swift Package Manager and plugin does not have podspec
166178
// but does have a Package.swift, throw an error. Otherwise, it'll error
167179
// when it builds.
168-
if (!xcodeProject.usesSwiftPackageManager &&
180+
if (hostPlatformIsMacOS &&
181+
!xcodeProject.usesSwiftPackageManager &&
169182
!cocoaPodsCompatible &&
170183
swiftPackageManagerCompatible) {
171184
throwToolExit(
@@ -197,7 +210,8 @@ class DarwinDependencyManagement {
197210
'${_podIncludeInConfigWarning(xcodeProject, 'Debug')}'
198211
'${_podIncludeInConfigWarning(xcodeProject, 'Release')}';
199212

200-
if (xcodeProject.podfile.readAsStringSync() == podfileTemplate.readAsStringSync()) {
213+
if (hostPlatformIsMacOS &&
214+
xcodeProject.podfile.readAsStringSync() == podfileTemplate.readAsStringSync()) {
201215
_logger.printWarning(
202216
'All plugins found for ${platform.name} are Swift Packages, but your '
203217
'project still has CocoaPods integration. To remove CocoaPods '
@@ -207,7 +221,7 @@ class DarwinDependencyManagement {
207221
'$configWarning\n'
208222
"Removing CocoaPods integration will improve the project's build time.",
209223
);
210-
} else {
224+
} else if (hostPlatformIsMacOS) {
211225
// If all plugins are Swift Packages, but the Podfile has custom logic,
212226
// recommend migrating manually.
213227
_logger.printWarning(

packages/flutter_tools/test/general.shard/macos/darwin_dependency_management_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:file/file.dart';
66
import 'package:file/memory.dart';
77
import 'package:flutter_tools/src/base/logger.dart';
8+
import 'package:flutter_tools/src/base/platform.dart';
89
import 'package:flutter_tools/src/darwin/darwin.dart';
910
import 'package:flutter_tools/src/macos/cocoapods.dart';
1011
import 'package:flutter_tools/src/macos/darwin_dependency_management.dart';
@@ -61,6 +62,7 @@ void main() {
6162
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
6263
logger: testLogger,
6364
analytics: fakeAnalytics,
65+
platform: FakePlatform(operatingSystem: 'macos'),
6466
);
6567
await dependencyManagement.setUp(platform: platform);
6668
expect(swiftPackageManager.generated, isTrue);
@@ -127,6 +129,7 @@ void main() {
127129
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
128130
logger: testLogger,
129131
analytics: testAnalytics,
132+
platform: FakePlatform(operatingSystem: 'macos'),
130133
);
131134
await dependencyManagement.setUp(platform: platform);
132135
expect(swiftPackageManager.generated, isTrue);
@@ -195,6 +198,7 @@ void main() {
195198
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
196199
logger: testLogger,
197200
analytics: testAnalytics,
201+
platform: FakePlatform(operatingSystem: 'macos'),
198202
);
199203
await dependencyManagement.setUp(platform: platform);
200204
expect(swiftPackageManager.generated, isTrue);
@@ -266,6 +270,7 @@ void main() {
266270
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
267271
logger: testLogger,
268272
analytics: testAnalytics,
273+
platform: FakePlatform(operatingSystem: 'macos'),
269274
);
270275
await dependencyManagement.setUp(platform: platform);
271276
expect(swiftPackageManager.generated, isTrue);
@@ -353,6 +358,7 @@ void main() {
353358
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
354359
logger: testLogger,
355360
analytics: testAnalytics,
361+
platform: FakePlatform(operatingSystem: 'macos'),
356362
);
357363
await dependencyManagement.setUp(platform: platform);
358364
expect(swiftPackageManager.generated, isTrue);
@@ -449,6 +455,7 @@ void main() {
449455
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
450456
logger: testLogger,
451457
analytics: testAnalytics,
458+
platform: FakePlatform(operatingSystem: 'macos'),
452459
);
453460
await dependencyManagement.setUp(platform: platform);
454461
expect(swiftPackageManager.generated, isTrue);
@@ -515,6 +522,7 @@ void main() {
515522
featureFlags: TestFeatureFlags(isSwiftPackageManagerEnabled: true),
516523
logger: testLogger,
517524
analytics: testAnalytics,
525+
platform: FakePlatform(operatingSystem: 'macos'),
518526
);
519527
await dependencyManagement.setUp(platform: platform);
520528
expect(swiftPackageManager.generated, isTrue);
@@ -568,6 +576,7 @@ void main() {
568576
featureFlags: TestFeatureFlags(),
569577
logger: testLogger,
570578
analytics: testAnalytics,
579+
platform: FakePlatform(operatingSystem: 'macos'),
571580
);
572581
await dependencyManagement.setUp(platform: platform);
573582
expect(swiftPackageManager.generated, isFalse);
@@ -621,6 +630,7 @@ void main() {
621630
featureFlags: TestFeatureFlags(),
622631
logger: testLogger,
623632
analytics: testAnalytics,
633+
platform: FakePlatform(operatingSystem: 'macos'),
624634
);
625635
await expectLater(
626636
() => dependencyManagement.setUp(platform: platform),
@@ -637,6 +647,46 @@ void main() {
637647
expect(testAnalytics.sentEvents, isEmpty);
638648
});
639649

650+
testWithoutContext(
651+
'with only Swift Package Manager plugins does not throw error on non-mac',
652+
() async {
653+
final testFileSystem = MemoryFileSystem.test();
654+
final testLogger = BufferLogger.test();
655+
final FakeAnalytics testAnalytics = getInitializedFakeAnalyticsInstance(
656+
fs: testFileSystem,
657+
fakeFlutterVersion: FakeFlutterVersion(),
658+
);
659+
final File swiftPackagePluginPodspec = testFileSystem.file(
660+
'/path/to/cocoapod_plugin_1/darwin/cocoapod_plugin_1/Package.swift',
661+
)..createSync(recursive: true);
662+
final plugins = <Plugin>[
663+
FakePlugin(
664+
name: 'swift_package_plugin_1',
665+
platforms: <String, PluginPlatform>{platform.name: FakePluginPlatform()},
666+
pluginSwiftPackageManifestPath: swiftPackagePluginPodspec.path,
667+
),
668+
];
669+
final swiftPackageManager = FakeSwiftPackageManager(expectedPlugins: plugins);
670+
final cocoaPods = FakeCocoaPods();
671+
672+
final dependencyManagement = DarwinDependencyManagement(
673+
project: FakeFlutterProject(fileSystem: testFileSystem),
674+
plugins: plugins,
675+
cocoapods: cocoaPods,
676+
swiftPackageManager: swiftPackageManager,
677+
fileSystem: testFileSystem,
678+
featureFlags: TestFeatureFlags(),
679+
logger: testLogger,
680+
analytics: testAnalytics,
681+
platform: FakePlatform(operatingSystem: 'windows'),
682+
);
683+
await dependencyManagement.setUp(platform: platform);
684+
expect(swiftPackageManager.generated, isFalse);
685+
expect(cocoaPods.podfileSetup, isTrue);
686+
expect(testAnalytics.sentEvents, isNotEmpty);
687+
},
688+
);
689+
640690
testWithoutContext('when project is a module', () async {
641691
final testFileSystem = MemoryFileSystem.test();
642692
final testLogger = BufferLogger.test();
@@ -666,6 +716,7 @@ void main() {
666716
featureFlags: TestFeatureFlags(),
667717
logger: testLogger,
668718
analytics: testAnalytics,
719+
platform: FakePlatform(operatingSystem: 'macos'),
669720
);
670721
await dependencyManagement.setUp(platform: platform);
671722
expect(swiftPackageManager.generated, isFalse);

0 commit comments

Comments
 (0)