Skip to content

Skip podspec Swift Search Path validation if only swift file is Package.swift #6627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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