Skip to content

Commit d7c14b6

Browse files
committed
Add API compatibility check tool
1 parent 1880693 commit d7c14b6

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

test/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ test : test.cc include_httplib.cc ../httplib.h Makefile cert.pem
4242
test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
4343
$(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS)
4444

45+
check_abi:
46+
@./check-shared-library-abi-compatibility.sh
47+
4548
test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
4649
$(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS)
4750

test/check-abi-compatibility.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
if [ "$#" -ne 2 ]; then
3+
echo "Usage: $0 old_library.so new_library.so"
4+
exit 1
5+
fi
6+
7+
OLD_LIB=$1
8+
NEW_LIB=$2
9+
10+
OLD_FUNCS=_old_funcs.txt
11+
NEW_FUNCS=_new_funcs.txt
12+
OLD_VARS=_old_vars.txt
13+
NEW_VARS=_new_vars.txt
14+
15+
# Extract function symbols from the old and new libraries
16+
nm -C --defined-only $OLD_LIB | c++filt | awk '$2 ~ /[TW]/ {print substr($0, index($0,$3))}' | sort > $OLD_FUNCS
17+
nm -C --defined-only $NEW_LIB | c++filt | awk '$2 ~ /[TW]/ {print substr($0, index($0,$3))}' | sort > $NEW_FUNCS
18+
19+
# Extract variable symbols from the old and new libraries
20+
nm -C --defined-only $OLD_LIB | c++filt | awk '$2 ~ /[BDG]/ {print substr($0, index($0,$3))}' | sort > $OLD_VARS
21+
nm -C --defined-only $NEW_LIB | c++filt | awk '$2 ~ /[BDG]/ {print substr($0, index($0,$3))}' | sort > $NEW_VARS
22+
23+
# Initialize error flag and message
24+
error_flag=0
25+
error_message=""
26+
27+
# Check for removed function symbols
28+
removed_funcs=$(comm -23 $OLD_FUNCS $NEW_FUNCS)
29+
if [ -n "$removed_funcs" ]; then
30+
error_flag=1
31+
error_message+="[Removed Functions]\n$removed_funcs\n"
32+
fi
33+
34+
# Check for removed variable symbols
35+
removed_vars=$(comm -23 $OLD_VARS $NEW_VARS)
36+
if [ -n "$removed_vars" ]; then
37+
error_flag=1
38+
error_message+="[Removed Variables]\n$removed_vars\n"
39+
fi
40+
41+
# Check for added variable symbols
42+
added_vars=$(comm -13 $OLD_VARS $NEW_VARS)
43+
if [ -n "$added_vars" ]; then
44+
error_flag=1
45+
error_message+="[Added Variables]\n$added_vars\n"
46+
fi
47+
48+
# Remove temporary files
49+
rm -f $NEW_FUNCS $OLD_FUNCS $OLD_VARS $NEW_VARS
50+
51+
# Display error messages if any
52+
if [ "$error_flag" -eq 1 ]; then
53+
echo -e "$error_message"
54+
echo "ABI compatibility check failed."
55+
exit 1
56+
fi
57+
58+
echo "ABI compatibility check passed: No variable symbols were removed or added, and no function symbols were removed."
59+
exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
CURRENT_COMMIT=$(git rev-parse HEAD)
3+
PREVIOUS_VERSION=$(git describe --tags --abbrev=0 $CURRENT_COMMIT)
4+
5+
BUILD_DIR=_build_for_is_abi_compatible
6+
7+
# Make the build directory
8+
rm -rf $BUILD_DIR
9+
mkdir -p $BUILD_DIR/new
10+
mkdir -p $BUILD_DIR/old
11+
12+
cd $BUILD_DIR
13+
14+
# Build the current commit
15+
cd new
16+
17+
cmake \
18+
-DCMAKE_BUILD_TYPE=Debug \
19+
-DCMAKE_CXX_FLAGS="-g -Og" \
20+
-DBUILD_SHARED_LIBS=ON \
21+
-DHTTPLIB_COMPILE=ON \
22+
-DCMAKE_INSTALL_PREFIX=./out \
23+
../../.. > /dev/null
24+
25+
cmake --build . --target install > /dev/null
26+
cmake --build . --target clean > /dev/null
27+
28+
cd ..
29+
30+
# Build the nearest vesion
31+
cd old
32+
cmake \
33+
-DCMAKE_BUILD_TYPE=Debug \
34+
-DCMAKE_CXX_FLAGS="-g -Og" \
35+
-DBUILD_SHARED_LIBS=ON \
36+
-DHTTPLIB_COMPILE=ON \
37+
-DCMAKE_INSTALL_PREFIX=./out \
38+
../../.. > /dev/null
39+
40+
git checkout -q "${PREVIOUS_VERSION}"
41+
cmake --build . --target install > /dev/null
42+
cmake --build . --target clean > /dev/null
43+
44+
cd ..
45+
46+
# Checkout the original commit
47+
if [ "$CURRENT_COMMIT" = "$(git rev-parse master)" ]; then
48+
git checkout -q master
49+
else
50+
git checkout -q "${CURRENT_COMMIT}"
51+
fi
52+
53+
# ABI compatibility check
54+
../check-abi-compatibility.sh ./old/out/lib/libcpp-httplib.so ./new/out/lib/libcpp-httplib.so
55+
56+
# Clean the build directory
57+
cd ..
58+
rm -rf $BUILD_DIR

0 commit comments

Comments
 (0)