Skip to content

Commit a7ef9e8

Browse files
authored
Integrate SwiftFormat into the swiftly project dependencies (#158)
The SwiftFormat that is run in the CI is a very specific version that is unlikely to be the one a dev has installed with homebrew or discovered for themselves and built from source. Discovering the version involves finding the magic in the lint.dockerfile. SwiftPM provides a mechanism for bringing in product dependencies so that you can simply run using the toolchain. The dependencies can be specified using an exact match on a particular version. Add the SwiftFormat dependency as a package dependency in swiftly at the version that is currently used in the soundness CI checks. Use the the swift command to invoke the 'swiftformat' product from the dependency instead of manually git cloning and building it manually in the dockerfile. Provide a rationale for the dependency in the Package.swift for anyone who is curious about it.
1 parent b0dc1b3 commit a7ef9e8

7 files changed

+14
-25
lines changed

Package.resolved

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"originHash" : "942a1612e8d4b18479d16ed7518859be9ac852972e43afb2a08c65d1037a641f",
23
"pins" : [
34
{
45
"identity" : "async-http-client",
@@ -152,7 +153,16 @@
152153
"revision" : "3b13e439a341bbbfe0f710c7d1be37221745ef1a",
153154
"version" : "0.6.1"
154155
}
156+
},
157+
{
158+
"identity" : "swiftformat",
159+
"kind" : "remoteSourceControl",
160+
"location" : "https://github.com/nicklockwood/SwiftFormat",
161+
"state" : {
162+
"revision" : "c7ddb09c3381cff833106345721fc314dba49e20",
163+
"version" : "0.49.18"
164+
}
155165
}
156166
],
157-
"version" : 2
167+
"version" : 3
158168
}

Package.swift

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ let package = Package(
2222
.package(url: "https://github.com/apple/swift-nio.git", from: "2.64.0"),
2323
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.6.1"),
2424
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
25+
// This dependency provides the correct version of the formatter so that you can run `swift run swiftformat Package.swift Plugins/ Sources/ Tests/`
26+
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.49.18"),
2527
],
2628
targets: [
2729
.executableTarget(

docker/lint.dockerfile

-11
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,3 @@ RUN apt-get update && apt-get install -y locales locales-all
55
ENV LC_ALL en_US.UTF-8
66
ENV LANG en_US.UTF-8
77
ENV LANGUAGE en_US.UTF-8
8-
9-
# tools
10-
RUN mkdir -p $HOME/.tools
11-
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
12-
13-
# swiftformat (until part of the toolchain)
14-
15-
ARG swiftformat_version=0.49.18
16-
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
17-
RUN cd $HOME/.tools/swift-format && swift build -c release
18-
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

docker/test-amazonlinux2.dockerfile

-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ COPY ./scripts/install-libarchive.sh /
1515
RUN /install-libarchive.sh
1616

1717
RUN curl -L https://swift.org/keys/all-keys.asc | gpg --import
18-
19-
# tools
20-
RUN mkdir -p $HOME/.tools
21-
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile

docker/test-ubi9.dockerfile

-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ COPY ./scripts/install-libarchive.sh /
1515
RUN /install-libarchive.sh
1616

1717
RUN curl -L https://swift.org/keys/all-keys.asc | gpg --import
18-
19-
# tools
20-
RUN mkdir -p $HOME/.tools
21-
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile

docker/test.dockerfile

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,3 @@ COPY ./scripts/install-libarchive.sh /
1818
RUN /install-libarchive.sh
1919

2020
RUN curl -L https://swift.org/keys/all-keys.asc | gpg --import
21-
22-
# tools
23-
RUN mkdir -p $HOME/.tools
24-
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile

scripts/check-lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -o errexit
44

5-
swiftformat --lint --dryrun .
5+
swift run swiftformat --lint --dryrun .

0 commit comments

Comments
 (0)