-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[ci] Run Swift formatter and linter during CI formatting #5928
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1071,7 +1071,11 @@ targets: | |
| properties: | ||
| add_recipes_cq: "true" | ||
| version_file: flutter_master.version | ||
| target_file: macos_check_podspecs.yaml | ||
| target_file: macos_repo_checks.yaml | ||
| dependencies: > | ||
| [ | ||
| {"dependency": "swift_format", "version": "build_id:8797338980206841409"} | ||
| ] | ||
|
|
||
| ### macOS desktop tasks ### | ||
| # macos-platform_tests builds all the packages on ARM, so this build is run | ||
|
|
@@ -1143,6 +1147,10 @@ targets: | |
| { | ||
| "CHANNEL": "master" | ||
| } | ||
| dependencies: > | ||
| [ | ||
| {"dependency": "swift_format", "version": "build_id:8797338979890974865"} | ||
|
Member
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. The arm64 and x64 arm: https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/swift-format/mac-arm64/+/RLmOtWwcNQeEUBqiZdpqEtJVh-cdm95Bbcz0W-wC124C |
||
| ] | ||
|
|
||
| - name: Mac_arm64 custom_package_tests stable | ||
| recipe: packages/packages | ||
|
|
@@ -1156,6 +1164,10 @@ targets: | |
| { | ||
| "CHANNEL": "stable" | ||
| } | ||
| dependencies: > | ||
| [ | ||
| {"dependency": "swift_format", "version": "build_id:8797338979890974865"} | ||
| ] | ||
|
|
||
| ### iOS tasks ### | ||
| # ios_platform_tests builds all the packages on ARM, so this build is run | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ class TestViewProvider: NSObject, ViewProvider { | |
| var window: NSWindow? = NSWindow() | ||
| } | ||
|
|
||
| class exampleTests: XCTestCase { | ||
| class ExampleTests: XCTestCase { | ||
|
||
|
|
||
| func testOpenSimple() throws { | ||
| let panelController = TestPanelController() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,8 @@ class FormatCommand extends PackageCommand { | |
| argParser.addFlag(_kotlinArg, | ||
| help: 'Format Kotlin files', defaultsTo: true); | ||
| argParser.addFlag(_javaArg, help: 'Format Java files', defaultsTo: true); | ||
| argParser.addFlag(_swiftArg, help: 'Format Swift files'); | ||
| argParser.addFlag(_swiftArg, | ||
| help: 'Format and lint Swift files', defaultsTo: true); | ||
| argParser.addOption(_clangFormatPathArg, | ||
| defaultsTo: 'clang-format', help: 'Path to "clang-format" executable.'); | ||
| argParser.addOption(_javaPathArg, | ||
|
|
@@ -105,7 +106,7 @@ class FormatCommand extends PackageCommand { | |
| await _formatCppAndObjectiveC(files); | ||
| } | ||
| if (getBoolArg(_swiftArg)) { | ||
| await _formatSwift(files); | ||
| await _formatAndLintSwift(files); | ||
| } | ||
|
|
||
| if (getBoolArg('fail-on-change')) { | ||
|
|
@@ -177,16 +178,32 @@ class FormatCommand extends PackageCommand { | |
| } | ||
| } | ||
|
|
||
| Future<void> _formatSwift(Iterable<String> files) async { | ||
| final String swiftFormat = await _findValidSwiftFormat(); | ||
| final Iterable<String> swiftFiles = | ||
| _getPathsWithExtensions(files, <String>{'.swift'}); | ||
| Future<void> _formatAndLintSwift(Iterable<String> files) async { | ||
| // TODO(jmagman): Remove generated file filter when pigeon Swift generation matches swift-format. | ||
| // https://github.com/flutter/flutter/issues/141799 | ||
| final Iterable<String> swiftFiles = _filterGeneratedFiles( | ||
| _getPathsWithExtensions(files, <String>{'.swift'})); | ||
| if (swiftFiles.isNotEmpty) { | ||
| final String swiftFormat = await _findValidSwiftFormat(); | ||
| print('Formatting .swift files...'); | ||
| final int exitCode = | ||
| final int formatExitCode = | ||
| await _runBatched(swiftFormat, <String>['-i'], files: swiftFiles); | ||
| if (exitCode != 0) { | ||
| printError('Failed to format Swift files: exit code $exitCode.'); | ||
| if (formatExitCode != 0) { | ||
| printError('Failed to format Swift files: exit code $formatExitCode.'); | ||
| throw ToolExit(_exitSwiftFormatFailed); | ||
| } | ||
|
|
||
| print('Linting .swift files...'); | ||
| final int lintExitCode = await _runBatched( | ||
| swiftFormat, | ||
| <String>[ | ||
| 'lint', | ||
| '--parallel', | ||
| '--strict', | ||
| ], | ||
| files: swiftFiles); | ||
| if (lintExitCode != 0) { | ||
| printError('Failed to lint Swift files: exit code $lintExitCode.'); | ||
| throw ToolExit(_exitSwiftFormatFailed); | ||
| } | ||
| } | ||
|
|
@@ -342,6 +359,13 @@ class FormatCommand extends PackageCommand { | |
| (String filePath) => extensions.contains(path.extension(filePath))); | ||
| } | ||
|
|
||
| Iterable<String> _filterGeneratedFiles(Iterable<String> files) { | ||
|
Collaborator
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. Rather than filtering out generated files, we just need Pigeon to do Swift formatting in CI; this code should include Swift formatting. If we changed the default then it'll just work, otherwise we need to add
Collaborator
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. Oh, but that's not going to work on the Linux machine where we run this. Hm, do we have a
Collaborator
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. Maybe it's easier to change the Pigeon validator to check specific languages for changes instead of checking everything for changes, and then run it for different languages on different CI hosts the way we do the
Collaborator
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 think #5944 should make this work.
Member
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 changed my comment about removing it into a TODO. How about I land this, then you rebase #5944 onto ToT and remove the
Collaborator
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. 👍🏻
Collaborator
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.
Oops, now that |
||
| return files.where((String filePath) { | ||
| final String basename = path.basename(filePath); | ||
| return !basename.contains('.gen.') && !basename.contains('.g.'); | ||
| }); | ||
| } | ||
|
|
||
| Future<String> _getJavaFormatterPath() async { | ||
| final String javaFormatterPath = path.join( | ||
| path.dirname(path.fromUri(platform.script)), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.