Skip to content

Commit

Permalink
Pin SwiftLint using CocoaPods (ReSwift#218)
Browse files Browse the repository at this point in the history
* Centralize SwiftLint logic in Build Phase script

* Add a Podfile to fetch SwiftLint

* Add script with the steps to integrate SwiftLint

The main reason for this is that there's no way to only fetch pods
without touching the project file. For our purposes though the project
file should not be touched, we are only interested in the SwiftLint
binary being fetched. So what we can do is just undo all the changes
made to the project by CocoaPods.

* Move script to install SwiftLint in scripts folder

I didn't notice there was one before looking at GitHub. Also changed the
script name to match the others in the folder.

* Use repo naming convention for script to run SwiftLint

* Use dummy target for SwiftLint integration

This approach is more robust that having to rely on developers to
remembre to run the installation script, and at the same time doesn't
pollute the actual ReSwift targets with unnecessary CocoaPods build
phases and imports.

* Track xcworkspace

See ReSwift#218 (comment)

* Allow spaces in sourceroot directory

Quotes the commands for running swiftlint to allow `$SRCROOT` to contain directories with spaces.

* Update swiftlint warning to refer to cocoapods

Instead of telling user to run install-swiftlint which no longer exists.

* Update swiftlint to latest

We also don't need to pin the version in the `Podfile`, since `Podfile.lock` pins for us on `pod install`. This allows the upgrade process to be just `pod update`, instead of having to manually update the version in the Podfile.

* Add note on SwiftLint + CocoaPods setup in README
  • Loading branch information
mokagio authored Apr 11, 2017
1 parent 3caa5de commit 27f24d2
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 11 deletions.
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ xcuserdata
# Packages/
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# While ReSwift has no dependencies we are still using CocoaPods, but only
# to ensure developers use the same binary version of SwiftLint. Since
# this is just a development dependency it is ok to ignore it, and rely on
# developers to generate it when required.
Pods/

# Carthage
#
Expand Down
11 changes: 11 additions & 0 deletions BuildPhases/run-swiftlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

swiftlint="$SRCROOT/Pods/SwiftLint/swiftlint"

if [ -f "$swiftlint" ]; then
"$swiftlint"
else
echo 'warning: Cannot find SwiftLint in the expected location. If you are developing ReSwift please install it via `pod install`. If you are building ReSwift as a dependency of your project feel free to ignore this.'
fi
8 changes: 8 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CocoaPods is used only to fetch and pin the version of SwiftLint that we want
# to use in the project. The Podfile DSL (at the time of CP 1.2.0) requires
# pods to be defined within a target. To work with that without having to make
# any of the actual ReSwift targets dirty or bloated a dummy target called
# SwiftLintIntegration has been added.
target 'SwiftLintIntegration' do
pod 'SwiftLint'
end
12 changes: 12 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PODS:
- SwiftLint (0.17.0)

DEPENDENCIES:
- SwiftLint

SPEC CHECKSUMS:
SwiftLint: 9fb1dd71d5952d130f8c2fb60ae2e1475cf5d575

PODFILE CHECKSUM: 937d436496e317ef5f238fab841c0529d8f5d201

COCOAPODS: 1.2.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ let package = Package(

# Checking out Source Code

ReSwift no longer has any carthage dependencies for development. Just checkout the project and run.
After checking out the project run `pod install` to get the latest supported version of [SwiftLint](https://github.com/realm/SwiftLint), which we use to ensure a consistent style in the codebase.

# Demo

Expand Down
191 changes: 188 additions & 3 deletions ReSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ReSwift.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions SwiftLintIntegration/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
15 changes: 15 additions & 0 deletions SwiftLintIntegration/SwiftLintIntegration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SwiftLintIntegration.swift
// SwiftLintIntegration
//
// Created by Gio on 17/3/17.
// Copyright © 2017 Benjamin Encz. All rights reserved.
//

//
// SwiftLintIntegration is a dummy target that is present in the project only to enable us to fetch
// SwiftLint via CocoaPods.
//
// Rather than polluting the actual ReSwift targets with extra CP realted BuildPhases and imports,
// we shove all that in this target here.
//

0 comments on commit 27f24d2

Please sign in to comment.