From ac80051da2b60ce8b6b96ae5bfae600d098087dc Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Tue, 3 Dec 2024 10:31:09 +0100 Subject: [PATCH] Only mark package swiftpm incompatible when pluginClass is present. (#1420) --- lib/src/tag/tagger.dart | 14 +++++- test/goldens/end2end/url_launcher-6.3.1.json | 4 +- .../end2end/url_launcher-6.3.1.json_report.md | 15 ------- test/tag/tag_end2end_test.dart | 45 +++++++++++++++++-- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/lib/src/tag/tagger.dart b/lib/src/tag/tagger.dart index 6f2e6c29..e3e87a57 100644 --- a/lib/src/tag/tagger.dart +++ b/lib/src/tag/tagger.dart @@ -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..pluginClass` key + /// present in the pubspec. + /// + /// A plugin can share code and package-manager manifest between iOS and + /// macOS by specifying `flutter.plugin.platforms..sharedDarwinSource`. + /// + /// See https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors void swiftPackageManagerPluginTag( List tags, List explanations) { if (!_usesFlutter) return; @@ -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'] == diff --git a/test/goldens/end2end/url_launcher-6.3.1.json b/test/goldens/end2end/url_launcher-6.3.1.json index 015d0c4b..d05b428e 100644 --- a/test/goldens/end2end/url_launcher-6.3.1.json +++ b/test/goldens/end2end/url_launcher-6.3.1.json @@ -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
\n\nPackage does not support the Swift Package Manager on macOS\n\n\nIt does not contain `macos/url_launcher/Package.swift`.\n\n
\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", diff --git a/test/goldens/end2end/url_launcher-6.3.1.json_report.md b/test/goldens/end2end/url_launcher-6.3.1.json_report.md index e1f85c83..1874a854 100644 --- a/test/goldens/end2end/url_launcher-6.3.1.json_report.md +++ b/test/goldens/end2end/url_launcher-6.3.1.json_report.md @@ -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 - -
- -Package does not support the Swift Package Manager on macOS - - -It does not contain `macos/url_launcher/Package.swift`. - -
- -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 diff --git a/test/tag/tag_end2end_test.dart b/test/tag/tag_end2end_test.dart index a23a157d..4c9586a9 100644 --- a/test/tag/tag_end2end_test.dart +++ b/test/tag/tag_end2end_test.dart @@ -584,7 +584,9 @@ name: my_package packageWithPathDeps('my_package', pubspecExtras: { 'flutter': { 'plugin': { - 'platforms': {'ios': {}} + 'platforms': { + 'ios': {'pluginClass': ''} + } } } }, extraFiles: [ @@ -605,8 +607,14 @@ name: my_package 'flutter': { 'plugin': { 'platforms': { - 'ios': {'sharedDarwinSource': true}, - 'macos': {'sharedDarwinSource': true} + 'ios': { + 'sharedDarwinSource': true, + 'pluginClass': '' + }, + 'macos': { + 'sharedDarwinSource': true, + 'pluginClass': '' + } } } } @@ -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': { + 'sharedDarwinSource': true, + 'pluginClass': '' + }, + 'macos': { + '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': {}} + 'platforms': { + 'macos': {'pluginClass': ''} + } } } }, extraFiles: [