diff --git a/script/tool/lib/src/podspec_check_command.dart b/script/tool/lib/src/podspec_check_command.dart index b0982b7ee69..aa3448b0af0 100644 --- a/script/tool/lib/src/podspec_check_command.dart +++ b/script/tool/lib/src/podspec_check_command.dart @@ -161,8 +161,14 @@ 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 { + final String iosSwiftPackageManifestPath = package + .platformDirectory(FlutterPlatform.ios) + .childDirectory(package.directory.basename) + .childFile('Package.swift') + .path; return getFilesForPackage(package).any((File entity) { final String relativePath = getRelativePosixPath(entity, from: package.directory); @@ -171,7 +177,8 @@ class PodspecCheckCommand extends PackageLoopingCommand { return false; } final String filePath = entity.path; - return path.extension(filePath) == '.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 09841df74e7..bfd12cac577 100644 --- a/script/tool/test/license_check_command_test.dart +++ b/script/tool/test/license_check_command_test.dart @@ -544,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 6745f18b6d4..cf5938a4ae4 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/plugin1/Package.swift', + ], + ); _writeFakePodspec(plugin, 'ios'); Error? commandError; @@ -378,6 +384,27 @@ void main() { )); }); + test('does not require the search paths workaround for iOS Package.swift', + () async { + final RepositoryPackage plugin = createFakePlugin( + 'plugin1', + packagesDir, + extraFiles: ['ios/plugin1/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,