-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Parse common SwiftPM errors and only fetch Swift packages when project is using SwiftPM #185218
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
fbf2831
0f633dc
552cf55
abaed9b
54c62da
1164c3d
532a164
b3cb95e
6c5c75b
de045a6
8ea6be9
906b817
d49164b
97a9ad4
05e6127
037399e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,4 +403,51 @@ class SwiftPackageManager { | |
| manifestContents.replaceFirst(oldSupportedPlatform, newSupportedPlatform), | ||
| ); | ||
| } | ||
|
|
||
| static final List<_SwiftPMPluginErrorMatcher> _errorMatchers = <_SwiftPMPluginErrorMatcher>[ | ||
| _SwiftPMPluginErrorMatcher( | ||
| // Example: target 'plugin_a' in package 'plugin_a' is outside the package root | ||
| pattern: RegExp(r"target '([^']+)' in package '[^']+' is outside the package root"), | ||
| message: (RegExpMatch match) => | ||
| 'Flutter plugin "${match.group(1)}" has an incorrectly configured Package.swift file.\n' | ||
| 'Please contact the plugin maintainers for assistance.', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also provide the details in error mesage? (same for the other matchers below)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put the onus or printing the actual error on whatever call this method. For example in if (swiftPackageManagerError != null) {
_logger.printError(stderrString);
throwToolExit(swiftPackageManagerError);
} |
||
| ), | ||
| _SwiftPMPluginErrorMatcher( | ||
| // Example: /path/to/plugin_a/Package.swift:25:17: error: expected ',' separator | ||
| pattern: RegExp(r'([^\/]+)\/Package\.swift:\d+:\d+: error:'), | ||
|
vashworth marked this conversation as resolved.
|
||
| message: (RegExpMatch match) => | ||
| 'Flutter plugin "${match.group(1)}" has an incorrectly configured Package.swift file.\n' | ||
| 'Please contact the plugin maintainers for assistance.', | ||
| ), | ||
| _SwiftPMPluginErrorMatcher( | ||
| // Example: unknown package 'some-package' in dependencies of target 'plugin_a' | ||
| pattern: RegExp(r"unknown package '[^']+' in dependencies of target '([^']+)'"), | ||
| message: (RegExpMatch match) => | ||
| 'Flutter plugin "${match.group(1)}" has an incorrectly configured Package.swift file.\n' | ||
| 'Please contact the plugin maintainers for assistance.', | ||
| ), | ||
| ]; | ||
|
|
||
| /// Parses a Swift Package Manager error message and returns a guided error | ||
| /// message if the error matches a known pattern. | ||
| static String? parsePluginError(String? message, {required List<String> pluginNames}) { | ||
| if (message == null || message.isEmpty) { | ||
| return null; | ||
| } | ||
| for (final _SwiftPMPluginErrorMatcher matcher in _errorMatchers) { | ||
| for (final RegExpMatch match in matcher.pattern.allMatches(message)) { | ||
| final String? packageName = match.group(1); | ||
| if (packageName != null && pluginNames.contains(packageName)) { | ||
|
vashworth marked this conversation as resolved.
|
||
| return matcher.message(match); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| class _SwiftPMPluginErrorMatcher { | ||
| const _SwiftPMPluginErrorMatcher({required this.pattern, required this.message}); | ||
| final RegExp pattern; | ||
| final String Function(RegExpMatch match) message; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was moved to
XcodeBasedProjectso that the process could be per project (ios and macos).