Skip to content

Only mark package swiftpm incompatible when pluginClass is present. #1420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/src/tag/tagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ class Tagger {
}
}

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

for (final darwinOs in ['macos', 'ios']) {
if (pathExists(
pubspec.originalYaml, ['flutter', 'plugin', 'platforms', darwinOs])) {
if (pathExists(pubspec.originalYaml,
['flutter', 'plugin', 'platforms', darwinOs, 'pluginClass'])) {
isDarwinPlugin = true;
final osDir = pubspec.originalYaml['flutter']?['plugin']?['platforms']
?[darwinOs]?['sharedDarwinSource'] ==
Expand Down
4 changes: 2 additions & 2 deletions test/goldens/end2end/url_launcher-6.3.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
"title": "Platform support",
"grantedPoints": 20,
"maxPoints": 20,
"status": "failed",
"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"
"status": "passed",
"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"
},
{
"id": "analysis",
Expand Down
15 changes: 0 additions & 15 deletions test/goldens/end2end/url_launcher-6.3.1.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ This package is compatible with runtime `wasm`, and will be rewarded additional

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

### [x] 0/0 points: Swift Package Manager support

<details>
<summary>
Package does not support the Swift Package Manager on macOS
</summary>

It does not contain `macos/url_launcher/Package.swift`.

</details>

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.

See https://docs.flutter.dev/to/spm for details.


## 40/50 Pass static analysis

Expand Down
45 changes: 41 additions & 4 deletions test/tag/tag_end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ name: my_package
packageWithPathDeps('my_package', pubspecExtras: {
'flutter': {
'plugin': {
'platforms': {'ios': <String, dynamic>{}}
'platforms': {
'ios': <String, dynamic>{'pluginClass': ''}
}
}
}
}, extraFiles: [
Expand All @@ -605,8 +607,14 @@ name: my_package
'flutter': {
'plugin': {
'platforms': {
'ios': <String, dynamic>{'sharedDarwinSource': true},
'macos': <String, dynamic>{'sharedDarwinSource': true}
'ios': <String, dynamic>{
'sharedDarwinSource': true,
'pluginClass': ''
},
'macos': <String, dynamic>{
'sharedDarwinSource': true,
'pluginClass': ''
}
}
}
}
Expand All @@ -622,12 +630,41 @@ name: my_package
tags: contains('is:swiftpm-plugin'));
});

test('Doesn\'t analyze when there is no pluginClass', () async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', pubspecExtras: {
'flutter': {
'plugin': {
'platforms': {
'ios': <String, dynamic>{
'sharedDarwinSource': true,
'pluginClass': ''
},
'macos': <String, dynamic>{
'sharedDarwinSource': true,
}
}
}
}
}, extraFiles: [
d.dir('darwin', [
d.dir('my_package'),
]),
])
]);
await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.swiftPackageManagerPluginTag, tags: isEmpty);
});

test('Fails with the wrong os/package_name/Package.swift', () async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', pubspecExtras: {
'flutter': {
'plugin': {
'platforms': {'macos': <String, dynamic>{}}
'platforms': {
'macos': <String, dynamic>{'pluginClass': ''}
}
}
}
}, extraFiles: [
Expand Down