Skip to content

Commit c897189

Browse files
authored
Use SPM API diff checker (#334)
### 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 50c25c1 commit c897189

File tree

1 file changed

+4
-72
lines changed

1 file changed

+4
-72
lines changed

scripts/check_no_api_breakages.sh

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,10 @@
1515

1616
set -eu
1717

18-
# repodir
19-
function all_modules() {
20-
local repodir="$1"
21-
(
22-
set -eu
23-
cd "$repodir"
24-
swift package dump-package | jq '.products |
25-
map(select(.type | has("library") )) |
26-
map(.name) | .[]' | tr -d '"'
27-
)
28-
}
29-
30-
# repodir tag output
31-
function build_and_do() {
32-
local repodir=$1
33-
local tag=$2
34-
local output=$3
35-
36-
(
37-
cd "$repodir"
38-
git checkout -q "$tag"
39-
swift build
40-
while read -r module; do
41-
swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \
42-
-o "$output/$module.json" -I "$repodir/.build/debug"
43-
done < <(all_modules "$repodir")
44-
)
45-
}
46-
4718
function usage() {
4819
echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..."
4920
echo >&2
50-
echo >&2 "This script requires a Swift 5.1+ toolchain."
21+
echo >&2 "This script requires a Swift 5.2+ toolchain."
5122
echo >&2
5223
echo >&2 "Examples:"
5324
echo >&2
@@ -63,12 +34,6 @@ if [[ $# -lt 3 ]]; then
6334
exit 1
6435
fi
6536

66-
sdk=/
67-
if [[ "$(uname -s)" == Darwin ]]; then
68-
sdk=$(xcrun --show-sdk-path)
69-
fi
70-
71-
hash jq 2> /dev/null || { echo >&2 "ERROR: jq must be installed"; exit 1; }
7237
tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX)
7338
repo_url=$1
7439
new_tag=$2
@@ -77,46 +42,13 @@ shift 2
7742
repodir="$tmpdir/repo"
7843
git clone "$repo_url" "$repodir"
7944
git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*'
80-
errors=0
45+
cd "$repodir"
46+
git checkout -q "$new_tag"
8147

8248
for old_tag in "$@"; do
83-
mkdir "$tmpdir/api-old"
84-
mkdir "$tmpdir/api-new"
85-
8649
echo "Checking public API breakages from $old_tag to $new_tag"
8750

88-
build_and_do "$repodir" "$new_tag" "$tmpdir/api-new/"
89-
build_and_do "$repodir" "$old_tag" "$tmpdir/api-old/"
90-
91-
for f in "$tmpdir/api-new"/*; do
92-
f=$(basename "$f")
93-
report="$tmpdir/$f.report"
94-
if [[ ! -f "$tmpdir/api-old/$f" ]]; then
95-
echo "NOTICE: NEW MODULE $f"
96-
continue
97-
fi
98-
99-
echo -n "Checking $f... "
100-
swift api-digester -sdk "$sdk" -diagnose-sdk \
101-
--input-paths "$tmpdir/api-old/$f" -input-paths "$tmpdir/api-new/$f" 2>&1 \
102-
> "$report" 2>&1
103-
104-
if ! shasum "$report" | grep -q afd2a1b542b33273920d65821deddc653063c700; then
105-
echo ERROR
106-
echo >&2 "=============================="
107-
echo >&2 "ERROR: public API change in $f"
108-
echo >&2 "=============================="
109-
cat >&2 "$report"
110-
errors=$(( errors + 1 ))
111-
else
112-
echo OK
113-
fi
114-
done
115-
rm -rf "$tmpdir/api-new" "$tmpdir/api-old"
51+
swift package diagnose-api-breaking-changes "$old_tag"
11652
done
11753

118-
if [[ "$errors" == 0 ]]; then
119-
echo "OK, all seems good"
120-
fi
12154
echo done
122-
exit "$errors"

0 commit comments

Comments
 (0)