Skip to content

Commit aea93d2

Browse files
authored
Skip podspec Swift Search Path validation if only swift file is Package.swift (#6627)
Usually when an iOS plugin uses Swift files, it requires a workaround in the podspec to add Swift to the search paths. Part of the `podspec-check` command is validating this workaround is found. However, when the only Swift file is the `Package.swift` (Swift Package Manager manifest), skip this validation since having this file does not indicate the plugin uses Swift files. Fixes flutter/flutter#147548.
1 parent d520519 commit aea93d2

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

script/tool/lib/src/podspec_check_command.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ class PodspecCheckCommand extends PackageLoopingCommand {
161161
}
162162

163163
/// Returns true if there is any iOS plugin implementation code written in
164-
/// Swift.
164+
/// Swift. Skips files named "Package.swift", which is a Swift Pacakge Manager
165+
/// manifest file and does not mean the plugin is written in Swift.
165166
Future<bool> _hasIOSSwiftCode(RepositoryPackage package) async {
167+
final String iosSwiftPackageManifestPath = package
168+
.platformDirectory(FlutterPlatform.ios)
169+
.childDirectory(package.directory.basename)
170+
.childFile('Package.swift')
171+
.path;
166172
return getFilesForPackage(package).any((File entity) {
167173
final String relativePath =
168174
getRelativePosixPath(entity, from: package.directory);
@@ -171,7 +177,8 @@ class PodspecCheckCommand extends PackageLoopingCommand {
171177
return false;
172178
}
173179
final String filePath = entity.path;
174-
return path.extension(filePath) == '.swift';
180+
return filePath != iosSwiftPackageManifestPath &&
181+
path.extension(filePath) == '.swift';
175182
});
176183
}
177184

script/tool/test/license_check_command_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,23 @@ void main() {
544544
contains(' third_party/bad.cc'),
545545
]));
546546
});
547+
548+
test('passes if Package.swift has license blocks', () async {
549+
final File checked = root.childFile('Package.swift');
550+
checked.createSync();
551+
writeLicense(checked, prefix: '// swift-tools-version: 5.9\n');
552+
553+
final List<String> output =
554+
await runCapturingPrint(runner, <String>['license-check']);
555+
556+
// Sanity check that the test did actually check a file.
557+
expect(
558+
output,
559+
containsAllInOrder(<Matcher>[
560+
contains('Checking Package.swift'),
561+
contains('All files passed validation!'),
562+
]));
563+
});
547564
});
548565
}
549566

script/tool/test/podspec_check_command_test.dart

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,14 @@ void main() {
319319

320320
test('fails if an iOS Swift plugin is missing the search paths workaround',
321321
() async {
322-
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
323-
extraFiles: <String>['ios/Classes/SomeSwift.swift']);
322+
final RepositoryPackage plugin = createFakePlugin(
323+
'plugin1',
324+
packagesDir,
325+
extraFiles: <String>[
326+
'ios/Classes/SomeSwift.swift',
327+
'ios/plugin1/Package.swift',
328+
],
329+
);
324330
_writeFakePodspec(plugin, 'ios');
325331

326332
Error? commandError;
@@ -378,6 +384,27 @@ void main() {
378384
));
379385
});
380386

387+
test('does not require the search paths workaround for iOS Package.swift',
388+
() async {
389+
final RepositoryPackage plugin = createFakePlugin(
390+
'plugin1',
391+
packagesDir,
392+
extraFiles: <String>['ios/plugin1/Package.swift'],
393+
);
394+
_writeFakePodspec(plugin, 'ios');
395+
396+
final List<String> output =
397+
await runCapturingPrint(runner, <String>['podspec-check']);
398+
399+
expect(
400+
output,
401+
containsAllInOrder(
402+
<Matcher>[
403+
contains('Ran for 1 package(s)'),
404+
],
405+
));
406+
});
407+
381408
test('does not require the search paths workaround for macOS plugins',
382409
() async {
383410
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,

0 commit comments

Comments
 (0)