xref: /dpdk/devtools/check-abi.sh (revision 98180d354f355a9fd1fbc8aaf59b1f3785b00443)
1#!/bin/sh -e
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright (c) 2019 Red Hat, Inc.
4
5if [ $# != 2 ] && [ $# != 3 ]; then
6	echo "Usage: $0 refdir newdir [warnonly]" >&2
7	exit 1
8fi
9
10refdir=$1
11newdir=$2
12warnonly=${3:-}
13ABIDIFF_SUPPRESSIONS=$(dirname $(readlink -f $0))/libabigail.abignore
14ABIDIFF_OPTIONS="--suppr $ABIDIFF_SUPPRESSIONS --no-added-syms"
15
16if [ ! -d $refdir ]; then
17	echo "Error: reference directory '$refdir' does not exist." >&2
18	exit 1
19fi
20incdir=$(find $refdir -type d -a -name include)
21if [ -z "$incdir" ] || [ ! -e "$incdir" ]; then
22	echo "WARNING: could not identify an include directory for $refdir, expect false positives..." >&2
23else
24	ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir1 $incdir"
25fi
26
27if [ ! -d $newdir ]; then
28	echo "Error: directory to check '$newdir' does not exist." >&2
29	exit 1
30fi
31incdir2=$(find $newdir -type d -a -name include)
32if [ -z "$incdir2" ] || [ ! -e "$incdir2" ]; then
33	echo "WARNING: could not identify an include directory for $newdir, expect false positives..." >&2
34else
35	ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
36fi
37
38export newdir ABIDIFF_OPTIONS ABIDIFF_SUPPRESSIONS
39export diff_func='run_diff() {
40	lib=$1
41	name=$(basename $lib)
42	if grep -q "; SKIP_LIBRARY=${name%.so.*}\>" $ABIDIFF_SUPPRESSIONS; then
43		echo "Skipped $name" >&2
44		return 0
45	fi
46	# Look for a library with the same major ABI version
47	lib2=$(find $newdir -name "${name%.*}.*" -a ! -type l)
48	if [ -z "$lib2" ] || [ ! -e "$lib2" ]; then
49		echo "Error: cannot find $name in $newdir" >&2
50		return 1
51	fi
52	abidiff $ABIDIFF_OPTIONS $lib $lib2 || {
53		abiret=$?
54		echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $lib $lib2" >&2
55		if [ $(($abiret & 3)) -ne 0 ]; then
56			echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
57		fi
58		if [ $(($abiret & 4)) -ne 0 ]; then
59			echo "ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged this as a potential issue)." >&2
60		fi
61		if [ $(($abiret & 8)) -ne 0 ]; then
62			echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
63		fi
64		return 1
65	}
66}'
67
68error=
69find $refdir -name "*.so.*" -a ! -type l |
70xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
71error=1
72
73[ -z "$error" ] || [ -n "$warnonly" ]
74