Skip to content

Commit ac80051

Browse files
authored
Only mark package swiftpm incompatible when pluginClass is present. (#1420)
1 parent 40c578b commit ac80051

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

lib/src/tag/tagger.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ class Tagger {
350350
}
351351
}
352352

353+
/// Tag if iOS/macOS plugin has migrated to Swift Package Manager (swiftpm).
354+
///
355+
/// A plugin only needs to be swiftpm enabled if it has a native component, we
356+
/// detect that if it has the `flutter.plugin.platforms.<os>.pluginClass` key
357+
/// present in the pubspec.
358+
///
359+
/// A plugin can share code and package-manager manifest between iOS and
360+
/// macOS by specifying `flutter.plugin.platforms.<os>.sharedDarwinSource`.
361+
///
362+
/// See https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
353363
void swiftPackageManagerPluginTag(
354364
List<String> tags, List<Explanation> explanations) {
355365
if (!_usesFlutter) return;
@@ -369,8 +379,8 @@ class Tagger {
369379
var swiftPmSupport = true;
370380

371381
for (final darwinOs in ['macos', 'ios']) {
372-
if (pathExists(
373-
pubspec.originalYaml, ['flutter', 'plugin', 'platforms', darwinOs])) {
382+
if (pathExists(pubspec.originalYaml,
383+
['flutter', 'plugin', 'platforms', darwinOs, 'pluginClass'])) {
374384
isDarwinPlugin = true;
375385
final osDir = pubspec.originalYaml['flutter']?['plugin']?['platforms']
376386
?[darwinOs]?['sharedDarwinSource'] ==

test/goldens/end2end/url_launcher-6.3.1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
"title": "Platform support",
144144
"grantedPoints": 20,
145145
"maxPoints": 20,
146-
"status": "failed",
147-
"summary": "### [*] 20/20 points: Supports 6 of 6 possible platforms (**iOS**, **Android**, **Web**, **Windows**, **macOS**, **Linux**)\n\n* ✓ Android\n\n* ✓ iOS\n\n* ✓ Windows\n\n* ✓ Linux\n\n* ✓ macOS\n\n* ✓ Web\n\n### [*] 0/0 points: WASM compatibility\n\nThis package is compatible with runtime `wasm`, and will be rewarded additional points in a future version of the scoring model.\n\nSee https://dart.dev/web/wasm for details.\n\n### [x] 0/0 points: Swift Package Manager support\n\n<details>\n<summary>\nPackage does not support the Swift Package Manager on macOS\n</summary>\n\nIt does not contain `macos/url_launcher/Package.swift`.\n\n</details>\n\nThis package for iOS or macOS does not support the Swift Package Manager. It will not receive full points in a future version of the scoring model.\n\nSee https://docs.flutter.dev/to/spm for details.\n"
146+
"status": "passed",
147+
"summary": "### [*] 20/20 points: Supports 6 of 6 possible platforms (**iOS**, **Android**, **Web**, **Windows**, **macOS**, **Linux**)\n\n* ✓ Android\n\n* ✓ iOS\n\n* ✓ Windows\n\n* ✓ Linux\n\n* ✓ macOS\n\n* ✓ Web\n\n### [*] 0/0 points: WASM compatibility\n\nThis package is compatible with runtime `wasm`, and will be rewarded additional points in a future version of the scoring model.\n\nSee https://dart.dev/web/wasm for details.\n"
148148
},
149149
{
150150
"id": "analysis",

test/goldens/end2end/url_launcher-6.3.1.json_report.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ This package is compatible with runtime `wasm`, and will be rewarded additional
5252

5353
See https://dart.dev/web/wasm for details.
5454

55-
### [x] 0/0 points: Swift Package Manager support
56-
57-
<details>
58-
<summary>
59-
Package does not support the Swift Package Manager on macOS
60-
</summary>
61-
62-
It does not contain `macos/url_launcher/Package.swift`.
63-
64-
</details>
65-
66-
This package for iOS or macOS does not support the Swift Package Manager. It will not receive full points in a future version of the scoring model.
67-
68-
See https://docs.flutter.dev/to/spm for details.
69-
7055

7156
## 40/50 Pass static analysis
7257

test/tag/tag_end2end_test.dart

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ name: my_package
584584
packageWithPathDeps('my_package', pubspecExtras: {
585585
'flutter': {
586586
'plugin': {
587-
'platforms': {'ios': <String, dynamic>{}}
587+
'platforms': {
588+
'ios': <String, dynamic>{'pluginClass': ''}
589+
}
588590
}
589591
}
590592
}, extraFiles: [
@@ -605,8 +607,14 @@ name: my_package
605607
'flutter': {
606608
'plugin': {
607609
'platforms': {
608-
'ios': <String, dynamic>{'sharedDarwinSource': true},
609-
'macos': <String, dynamic>{'sharedDarwinSource': true}
610+
'ios': <String, dynamic>{
611+
'sharedDarwinSource': true,
612+
'pluginClass': ''
613+
},
614+
'macos': <String, dynamic>{
615+
'sharedDarwinSource': true,
616+
'pluginClass': ''
617+
}
610618
}
611619
}
612620
}
@@ -622,12 +630,41 @@ name: my_package
622630
tags: contains('is:swiftpm-plugin'));
623631
});
624632

633+
test('Doesn\'t analyze when there is no pluginClass', () async {
634+
final descriptor = d.dir('cache', [
635+
packageWithPathDeps('my_package', pubspecExtras: {
636+
'flutter': {
637+
'plugin': {
638+
'platforms': {
639+
'ios': <String, dynamic>{
640+
'sharedDarwinSource': true,
641+
'pluginClass': ''
642+
},
643+
'macos': <String, dynamic>{
644+
'sharedDarwinSource': true,
645+
}
646+
}
647+
}
648+
}
649+
}, extraFiles: [
650+
d.dir('darwin', [
651+
d.dir('my_package'),
652+
]),
653+
])
654+
]);
655+
await descriptor.create();
656+
final tagger = Tagger('${descriptor.io.path}/my_package');
657+
_expectTagging(tagger.swiftPackageManagerPluginTag, tags: isEmpty);
658+
});
659+
625660
test('Fails with the wrong os/package_name/Package.swift', () async {
626661
final descriptor = d.dir('cache', [
627662
packageWithPathDeps('my_package', pubspecExtras: {
628663
'flutter': {
629664
'plugin': {
630-
'platforms': {'macos': <String, dynamic>{}}
665+
'platforms': {
666+
'macos': <String, dynamic>{'pluginClass': ''}
667+
}
631668
}
632669
}
633670
}, extraFiles: [

0 commit comments

Comments
 (0)