Skip to content

Commit b1e4f19

Browse files
authoredMar 28, 2022
Use SPM API diff checker (#572)
### Motivation: SPM has built in functionality to check the API of modules against a target git treeish. We can use this to simplify our `check_no_api_breakages.sh` script. Closes apple/swift-nio#1239 ### Modifications: This PR, exchanges the direct calls to Swift's API checker with the new SPM `diagnose-api-breaking-changes` tool. This allows us to get rid of the manual module parsing, build invocations and result comparisons. ### Result: We are now using SPMs `diagnose-api-breaking-changes` to check for breaking changes.
1 parent 42b0637 commit b1e4f19

File tree

1 file changed

+6
-74
lines changed

1 file changed

+6
-74
lines changed
 

‎scripts/check_no_api_breakages.sh

+6-74
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,15 @@
2929

3030
set -eu
3131

32-
# repodir
33-
function all_modules() {
34-
local repodir="$1"
35-
(
36-
set -eu
37-
cd "$repodir"
38-
swift package dump-package | jq '.products |
39-
map(select(.type | has("library") )) |
40-
map(.name) | .[]' | tr -d '"'
41-
)
42-
}
43-
44-
# repodir tag output
45-
function build_and_do() {
46-
local repodir=$1
47-
local tag=$2
48-
local output=$3
49-
50-
(
51-
cd "$repodir"
52-
git checkout -q "$tag"
53-
swift build
54-
while read -r module; do
55-
swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \
56-
-o "$output/$module.json" -I "$repodir/.build/debug"
57-
done < <(all_modules "$repodir")
58-
)
59-
}
60-
6132
function usage() {
6233
echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..."
6334
echo >&2
64-
echo >&2 "This script requires a Swift 5.1+ toolchain."
35+
echo >&2 "This script requires a Swift 5.2+ toolchain."
6536
echo >&2
6637
echo >&2 "Examples:"
6738
echo >&2
68-
echo >&2 "Check between master and tag 2.1.1 of swift-nio:"
69-
echo >&2 " $0 https://github.com/apple/swift-nio master 2.1.1"
39+
echo >&2 "Check between main and tag 2.1.1 of swift-nio:"
40+
echo >&2 " $0 https://github.com/apple/swift-nio main 2.1.1"
7041
echo >&2
7142
echo >&2 "Check between HEAD and commit 64cf63d7 using the provided toolchain:"
7243
echo >&2 " xcrun --toolchain org.swift.5120190702a $0 ../some-local-repo HEAD 64cf63d7"
@@ -77,12 +48,6 @@ if [[ $# -lt 3 ]]; then
7748
exit 1
7849
fi
7950

80-
sdk=/
81-
if [[ "$(uname -s)" == Darwin ]]; then
82-
sdk=$(xcrun --show-sdk-path)
83-
fi
84-
85-
hash jq 2> /dev/null || { echo >&2 "ERROR: jq must be installed"; exit 1; }
8651
tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX)
8752
repo_url=$1
8853
new_tag=$2
@@ -91,46 +56,13 @@ shift 2
9156
repodir="$tmpdir/repo"
9257
git clone "$repo_url" "$repodir"
9358
git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*'
94-
errors=0
59+
cd "$repodir"
60+
git checkout -q "$new_tag"
9561

9662
for old_tag in "$@"; do
97-
mkdir "$tmpdir/api-old"
98-
mkdir "$tmpdir/api-new"
99-
10063
echo "Checking public API breakages from $old_tag to $new_tag"
10164

102-
build_and_do "$repodir" "$new_tag" "$tmpdir/api-new/"
103-
build_and_do "$repodir" "$old_tag" "$tmpdir/api-old/"
104-
105-
for f in "$tmpdir/api-new"/*; do
106-
f=$(basename "$f")
107-
report="$tmpdir/$f.report"
108-
if [[ ! -f "$tmpdir/api-old/$f" ]]; then
109-
echo "NOTICE: NEW MODULE $f"
110-
continue
111-
fi
112-
113-
echo -n "Checking $f... "
114-
swift api-digester -sdk "$sdk" -diagnose-sdk \
115-
--input-paths "$tmpdir/api-old/$f" -input-paths "$tmpdir/api-new/$f" 2>&1 \
116-
> "$report" 2>&1
117-
118-
if ! shasum "$report" | grep -q afd2a1b542b33273920d65821deddc653063c700; then
119-
echo ERROR
120-
echo >&2 "=============================="
121-
echo >&2 "ERROR: public API change in $f"
122-
echo >&2 "=============================="
123-
cat >&2 "$report"
124-
errors=$(( errors + 1 ))
125-
else
126-
echo OK
127-
fi
128-
done
129-
rm -rf "$tmpdir/api-new" "$tmpdir/api-old"
65+
swift package diagnose-api-breaking-changes "$old_tag"
13066
done
13167

132-
if [[ "$errors" == 0 ]]; then
133-
echo "OK, all seems good"
134-
fi
13568
echo done
136-
exit "$errors"

0 commit comments

Comments
 (0)
Please sign in to comment.