-
Notifications
You must be signed in to change notification settings - Fork 295
Provision SwiftLint via SwiftPM instead of CocoaPods #1712
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Here only to satisfy SwiftPM requirement. | ||
// See https://github.com/nicklockwood/SwiftFormat#1-create-a-buildtools-folder-and-packageswift |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swift-tools-version:6.0 | ||
import Foundation | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "BuildTools", | ||
platforms: [.macOS(.v10_13)], | ||
dependencies: [ | ||
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: loadSwiftLintVersion()), | ||
], | ||
targets: [.target(name: "BuildTools", path: "")] | ||
) | ||
|
||
func loadSwiftLintVersion() -> Version { | ||
let swiftLintConfigURL = URL(fileURLWithPath: #filePath) | ||
.deletingLastPathComponent() | ||
.appendingPathComponent("..") | ||
.appendingPathComponent(".swiftlint.yml") | ||
|
||
guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else { | ||
fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).") | ||
} | ||
|
||
guard let versionLine = yamlString.components(separatedBy: .newlines) | ||
.first(where: { $0.contains("swiftlint_version") }) else { | ||
fatalError("SwiftLint version not found in YAML file.") | ||
} | ||
|
||
// Assumes the format `swiftlint_version: <version>` | ||
guard let version = Version(versionLine.components(separatedBy: ":") | ||
.last? | ||
.trimmingCharacters(in: .whitespaces) ?? "") else { | ||
fatalError("Failed to extract SwiftLint version.") | ||
} | ||
|
||
return version | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I was wary of if running
rake
from an Xcode build phase would work as expected, given that:$PATH
and whererake
is installed)/bin/sh
, while macOS users are usingzsh
, so all their customization and setup of their shell is in.zshrc
and not.bashrc
. So again, any custom$PATH
orrbenv
andbundle
-related config etc might be set up properly in.zshrc
but not in.bashrc
for the/bin/sh
shell to pick up, which could lead to thisrake lint
command to failrake lint
, notbundle exec rake lint
. Which means one might accidentally run this command with a different version ofrake
than the one in theGemfile.lock
bundle of this repo. Probably not a big deal (the most important thing is forswiftlint
to be using the right version, andrake
doesn't have that many updates anyway, and if it does, nothing likely breaking anything) but still inconsistent.It still worked when I tested building the project with Xcode on my Mac:

But I think that might be a happy coincidence in how my Mac is set up, and that might not be the case for every developer? I wonder if switching to
shellPath = /bin/zsh;
and usingbundle exec rake lint
wouldn't be better (maybe with a need tosource ~/.zshrc
explicitly first, in case Xcode running this shell in non-interactive mode would prevent that from loading… not sure, always confused with the rc files and when they're loaded wrt to interactive vs non-interactive shells etc)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.
I remember looking into this with Jeremy a while back and coming to the conclusion that calling
rake
from Xcode works because of a number of happy coincidences in how Apple set up Ruby in macOS.In the long run, consistently with our goal of removing Ruby from day-to-day DX, I think we'd be better off using
make
which we know would be consistent without depending on Ruby setup.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.
Moved this discussion internally to paaHJt-8yZ-p2