From 3ed8b9266dd90a6a4c3cb466b34f1d37094e93b1 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Mon, 29 Apr 2024 16:47:45 -0500 Subject: [PATCH 1/4] Skip Swift Search Path validation if only swift file is Package.swift --- .../tool/lib/src/podspec_check_command.dart | 6 ++-- .../tool/test/podspec_check_command_test.dart | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/script/tool/lib/src/podspec_check_command.dart b/script/tool/lib/src/podspec_check_command.dart index b0982b7ee69..80268fe5732 100644 --- a/script/tool/lib/src/podspec_check_command.dart +++ b/script/tool/lib/src/podspec_check_command.dart @@ -161,7 +161,8 @@ class PodspecCheckCommand extends PackageLoopingCommand { } /// Returns true if there is any iOS plugin implementation code written in - /// Swift. + /// Swift. Skips files named "Package.swift", which is a Swift Pacakge Manager + /// manifest file and does not mean the plugin is written in Swift. Future _hasIOSSwiftCode(RepositoryPackage package) async { return getFilesForPackage(package).any((File entity) { final String relativePath = @@ -171,7 +172,8 @@ class PodspecCheckCommand extends PackageLoopingCommand { return false; } final String filePath = entity.path; - return path.extension(filePath) == '.swift'; + return entity.basename != 'Package.swift' && + path.extension(filePath) == '.swift'; }); } diff --git a/script/tool/test/podspec_check_command_test.dart b/script/tool/test/podspec_check_command_test.dart index 6745f18b6d4..6674e876a1f 100644 --- a/script/tool/test/podspec_check_command_test.dart +++ b/script/tool/test/podspec_check_command_test.dart @@ -319,8 +319,14 @@ void main() { test('fails if an iOS Swift plugin is missing the search paths workaround', () async { - final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir, - extraFiles: ['ios/Classes/SomeSwift.swift']); + final RepositoryPackage plugin = createFakePlugin( + 'plugin1', + packagesDir, + extraFiles: [ + 'ios/Classes/SomeSwift.swift', + 'ios/Package.swift', + ], + ); _writeFakePodspec(plugin, 'ios'); Error? commandError; @@ -378,6 +384,27 @@ void main() { )); }); + test('does not require the search paths workaround for Package.swift', + () async { + final RepositoryPackage plugin = createFakePlugin( + 'plugin1', + packagesDir, + extraFiles: ['ios/Package.swift'], + ); + _writeFakePodspec(plugin, 'ios'); + + final List output = + await runCapturingPrint(runner, ['podspec-check']); + + expect( + output, + containsAllInOrder( + [ + contains('Ran for 1 package(s)'), + ], + )); + }); + test('does not require the search paths workaround for macOS plugins', () async { final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir, From d49a090c477e0f7dbc6d0620da3880781f29e3f4 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Mon, 29 Apr 2024 17:06:01 -0500 Subject: [PATCH 2/4] skip license check --- script/tool/lib/src/license_check_command.dart | 1 + script/tool/test/license_check_command_test.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/script/tool/lib/src/license_check_command.dart b/script/tool/lib/src/license_check_command.dart index 5f01cca7b96..e98c06d8142 100644 --- a/script/tool/lib/src/license_check_command.dart +++ b/script/tool/lib/src/license_check_command.dart @@ -40,6 +40,7 @@ const Set _ignoreSuffixList = { // Full basenames of files to ignore. const Set _ignoredFullBasenameList = { 'resource.h', // Generated by VS. + 'Package.swift', // Swift Package Manifest file. }; // Copyright and license regexes for third-party code. diff --git a/script/tool/test/license_check_command_test.dart b/script/tool/test/license_check_command_test.dart index 09841df74e7..fa2b36175f0 100644 --- a/script/tool/test/license_check_command_test.dart +++ b/script/tool/test/license_check_command_test.dart @@ -120,6 +120,7 @@ void main() { 'foo.mocks.dart', // Ignored files. 'resource.h', + 'Package.swift', ]; for (final String name in ignoredFiles) { From 34e5c85c16bb3b9bd71426e3e61a71016cd6d78c Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Tue, 30 Apr 2024 10:19:04 -0500 Subject: [PATCH 3/4] add license check back, make podspec check more specific --- script/tool/lib/src/license_check_command.dart | 1 - script/tool/lib/src/podspec_check_command.dart | 7 ++++++- .../tool/test/license_check_command_test.dart | 18 +++++++++++++++++- .../tool/test/podspec_check_command_test.dart | 6 +++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/script/tool/lib/src/license_check_command.dart b/script/tool/lib/src/license_check_command.dart index e98c06d8142..5f01cca7b96 100644 --- a/script/tool/lib/src/license_check_command.dart +++ b/script/tool/lib/src/license_check_command.dart @@ -40,7 +40,6 @@ const Set _ignoreSuffixList = { // Full basenames of files to ignore. const Set _ignoredFullBasenameList = { 'resource.h', // Generated by VS. - 'Package.swift', // Swift Package Manifest file. }; // Copyright and license regexes for third-party code. diff --git a/script/tool/lib/src/podspec_check_command.dart b/script/tool/lib/src/podspec_check_command.dart index 80268fe5732..348159c2c76 100644 --- a/script/tool/lib/src/podspec_check_command.dart +++ b/script/tool/lib/src/podspec_check_command.dart @@ -164,6 +164,11 @@ class PodspecCheckCommand extends PackageLoopingCommand { /// Swift. Skips files named "Package.swift", which is a Swift Pacakge Manager /// manifest file and does not mean the plugin is written in Swift. Future _hasIOSSwiftCode(RepositoryPackage package) async { + final String iosSwiftPackageManifestPath = package + .platformDirectory(FlutterPlatform.ios) + .childDirectory(package.displayName) + .childFile('Package.swift') + .path; return getFilesForPackage(package).any((File entity) { final String relativePath = getRelativePosixPath(entity, from: package.directory); @@ -172,7 +177,7 @@ class PodspecCheckCommand extends PackageLoopingCommand { return false; } final String filePath = entity.path; - return entity.basename != 'Package.swift' && + return filePath != iosSwiftPackageManifestPath && path.extension(filePath) == '.swift'; }); } diff --git a/script/tool/test/license_check_command_test.dart b/script/tool/test/license_check_command_test.dart index fa2b36175f0..bfd12cac577 100644 --- a/script/tool/test/license_check_command_test.dart +++ b/script/tool/test/license_check_command_test.dart @@ -120,7 +120,6 @@ void main() { 'foo.mocks.dart', // Ignored files. 'resource.h', - 'Package.swift', ]; for (final String name in ignoredFiles) { @@ -545,6 +544,23 @@ void main() { contains(' third_party/bad.cc'), ])); }); + + test('passes if Package.swift has license blocks', () async { + final File checked = root.childFile('Package.swift'); + checked.createSync(); + writeLicense(checked, prefix: '// swift-tools-version: 5.9\n'); + + final List output = + await runCapturingPrint(runner, ['license-check']); + + // Sanity check that the test did actually check a file. + expect( + output, + containsAllInOrder([ + contains('Checking Package.swift'), + contains('All files passed validation!'), + ])); + }); }); } diff --git a/script/tool/test/podspec_check_command_test.dart b/script/tool/test/podspec_check_command_test.dart index 6674e876a1f..cf5938a4ae4 100644 --- a/script/tool/test/podspec_check_command_test.dart +++ b/script/tool/test/podspec_check_command_test.dart @@ -324,7 +324,7 @@ void main() { packagesDir, extraFiles: [ 'ios/Classes/SomeSwift.swift', - 'ios/Package.swift', + 'ios/plugin1/Package.swift', ], ); _writeFakePodspec(plugin, 'ios'); @@ -384,12 +384,12 @@ void main() { )); }); - test('does not require the search paths workaround for Package.swift', + test('does not require the search paths workaround for iOS Package.swift', () async { final RepositoryPackage plugin = createFakePlugin( 'plugin1', packagesDir, - extraFiles: ['ios/Package.swift'], + extraFiles: ['ios/plugin1/Package.swift'], ); _writeFakePodspec(plugin, 'ios'); From c78c695603380bddf70facc48ab0223ac2f32636 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Tue, 30 Apr 2024 11:03:28 -0500 Subject: [PATCH 4/4] fix package name --- script/tool/lib/src/podspec_check_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/lib/src/podspec_check_command.dart b/script/tool/lib/src/podspec_check_command.dart index 348159c2c76..aa3448b0af0 100644 --- a/script/tool/lib/src/podspec_check_command.dart +++ b/script/tool/lib/src/podspec_check_command.dart @@ -166,7 +166,7 @@ class PodspecCheckCommand extends PackageLoopingCommand { Future _hasIOSSwiftCode(RepositoryPackage package) async { final String iosSwiftPackageManifestPath = package .platformDirectory(FlutterPlatform.ios) - .childDirectory(package.displayName) + .childDirectory(package.directory.basename) .childFile('Package.swift') .path; return getFilesForPackage(package).any((File entity) {