Skip to content

Commit

Permalink
Skip podspec Swift Search Path validation if only swift file is Packa…
Browse files Browse the repository at this point in the history
…ge.swift (flutter#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.
  • Loading branch information
vashworth authored Apr 30, 2024
1 parent d520519 commit aea93d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
11 changes: 9 additions & 2 deletions script/tool/lib/src/podspec_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> _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);
Expand All @@ -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';
});
}

Expand Down
17 changes: 17 additions & 0 deletions script/tool/test/license_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> output =
await runCapturingPrint(runner, <String>['license-check']);

// Sanity check that the test did actually check a file.
expect(
output,
containsAllInOrder(<Matcher>[
contains('Checking Package.swift'),
contains('All files passed validation!'),
]));
});
});
}

Expand Down
31 changes: 29 additions & 2 deletions script/tool/test/podspec_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <String>['ios/Classes/SomeSwift.swift']);
final RepositoryPackage plugin = createFakePlugin(
'plugin1',
packagesDir,
extraFiles: <String>[
'ios/Classes/SomeSwift.swift',
'ios/plugin1/Package.swift',
],
);
_writeFakePodspec(plugin, 'ios');

Error? commandError;
Expand Down Expand Up @@ -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: <String>['ios/plugin1/Package.swift'],
);
_writeFakePodspec(plugin, 'ios');

final List<String> output =
await runCapturingPrint(runner, <String>['podspec-check']);

expect(
output,
containsAllInOrder(
<Matcher>[
contains('Ran for 1 package(s)'),
],
));
});

test('does not require the search paths workaround for macOS plugins',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin1', packagesDir,
Expand Down

0 comments on commit aea93d2

Please sign in to comment.