Skip to content

Commit d3a16ed

Browse files
nathanlynchtyreld
authored andcommitted
add tools/generate-abi-defs script for ABI maintenance
This tool is invoked manually outside of the build system to generate ABI definitions using the libabigail project's abidw tool: https://sourceware.org/libabigail/manual/libabigail-overview.html ABI definitions are generated in a Debian stable/bookworm container for each of the PowerPC targets that the project has supported over its life. About half of the script is code generated by the argbash utility for handling command line arguments. https://argbash.readthedocs.io/en/latest/ Signed-off-by: Nathan Lynch <[email protected]> Signed-off-by: Tyrel Datwyler <[email protected]>
1 parent 83ff23b commit d3a16ed

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

tools/generate-abi-defs

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
#!/bin/bash
2+
3+
# Created by argbash-init v2.10.0
4+
# ARG_POSITIONAL_SINGLE([ref],[Git commit, tag, or branch],[HEAD])
5+
# ARGBASH_SET_DELIM([ ])
6+
# ARG_OPTION_STACKING([getopt])
7+
# ARG_RESTRICT_VALUES([none])
8+
# ARG_DEFAULTS_POS([])
9+
# ARG_HELP([Update librtas and librtasevent ABI definitions.],[Generates ABI definitions as of the given Git commit. Uses Podman \nand a temporary Git worktree. Harmful ABI changes can be detected\nusing the 'abi-check' build target.])
10+
# ARGBASH_GO()
11+
# needed because of Argbash --> m4_ignore([
12+
### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
13+
# Argbash is a bash code generator used to get arguments parsing right.
14+
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
15+
16+
17+
die()
18+
{
19+
local _ret="${2:-1}"
20+
test "${_PRINT_HELP:-no}" = yes && print_help >&2
21+
echo "$1" >&2
22+
exit "${_ret}"
23+
}
24+
25+
26+
begins_with_short_option()
27+
{
28+
local first_option all_short_options='h'
29+
first_option="${1:0:1}"
30+
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
31+
}
32+
33+
# THE DEFAULTS INITIALIZATION - POSITIONALS
34+
_positionals=()
35+
_arg_ref="HEAD"
36+
# THE DEFAULTS INITIALIZATION - OPTIONALS
37+
38+
39+
print_help()
40+
{
41+
printf '%s\n' "Update librtas and librtasevent ABI definitions."
42+
printf 'Usage: %s [-h|--help] [<ref>]\n' "$0"
43+
printf '\t%s\n' "<ref>: Git commit, tag, or branch (default: 'HEAD')"
44+
printf '\t%s\n' "-h, --help: Prints help"
45+
printf '\n%s\n' "Generates ABI definitions as of the given Git commit. Uses Podman
46+
and a temporary Git worktree. Harmful ABI changes can be detected
47+
using the 'abi-check' build target."
48+
}
49+
50+
51+
parse_commandline()
52+
{
53+
_positionals_count=0
54+
while test $# -gt 0
55+
do
56+
_key="$1"
57+
case "$_key" in
58+
-h|--help)
59+
print_help
60+
exit 0
61+
;;
62+
-h*)
63+
print_help
64+
exit 0
65+
;;
66+
*)
67+
_last_positional="$1"
68+
_positionals+=("$_last_positional")
69+
_positionals_count=$((_positionals_count + 1))
70+
;;
71+
esac
72+
shift
73+
done
74+
}
75+
76+
77+
handle_passed_args_count()
78+
{
79+
test "${_positionals_count}" -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect between 0 and 1, but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
80+
}
81+
82+
83+
assign_positional_args()
84+
{
85+
local _positional_name _shift_for=$1
86+
_positional_names="_arg_ref "
87+
88+
shift "$_shift_for"
89+
for _positional_name in ${_positional_names}
90+
do
91+
test $# -gt 0 || break
92+
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
93+
shift
94+
done
95+
}
96+
97+
parse_commandline "$@"
98+
handle_passed_args_count
99+
assign_positional_args 1 "${_positionals[@]}"
100+
101+
# OTHER STUFF GENERATED BY Argbash
102+
103+
### END OF CODE GENERATED BY Argbash (sortof) ### ])
104+
# [ <-- needed because of Argbash
105+
106+
107+
# vvv PLACE YOUR CODE HERE vvv
108+
# For example:
109+
set -eu
110+
set -o pipefail
111+
112+
worktree_dir="$(mktemp -t --directory librtas-abi.XXXXXX)"
113+
orig_dir="$PWD"
114+
abi_dir="data/abixml"
115+
116+
cleanup() {
117+
set +e
118+
echo "Cleaning up worktree ${worktree_dir}"
119+
test -d "$worktree_dir" && cd "$worktree_dir" && git clean -xdf
120+
cd "$orig_dir" && git worktree remove "$worktree_dir"
121+
test -d "$worktree_dir" && rm -r "$worktree_dir"
122+
}
123+
124+
trap cleanup EXIT
125+
126+
git worktree add --detach --checkout "$worktree_dir" "$_arg_ref"
127+
128+
declare -a runc_opts
129+
runc_opts=(
130+
--interactive
131+
--log-driver none
132+
--rm
133+
--security-opt label=disable
134+
--volume "${worktree_dir}":/source:rw
135+
--workdir /source
136+
)
137+
138+
cat <<"EOF" |
139+
set -eux
140+
141+
declare -a pkgs
142+
pkgs=(
143+
abigail-tools
144+
autoconf
145+
automake
146+
gcc-powerpc-linux-gnu
147+
gcc-powerpc64-linux-gnu
148+
gcc-powerpc64le-linux-gnu
149+
libc6-dev-powerpc-cross
150+
libc6-dev-ppc64-cross
151+
libc6-dev-ppc64el-cross
152+
libtool
153+
make
154+
)
155+
156+
apt-get update
157+
apt-get -y --purge dist-upgrade
158+
apt-get install -y --no-install-recommends "${pkgs[@]}"
159+
160+
abi_dir="data/abixml"
161+
162+
./autogen.sh
163+
164+
for cc in \
165+
powerpc-linux-gnu-gcc \
166+
powerpc64-linux-gnu-gcc \
167+
powerpc64le-linux-gnu-gcc \
168+
; do
169+
170+
declare -a cflags
171+
cflags=(
172+
-O2
173+
-Wall
174+
-gdwarf-5
175+
-std=gnu99
176+
)
177+
host="$($cc -dumpmachine)"
178+
179+
./configure --host="${host}" CC="$cc" CFLAGS='-O2 -g -std=gnu99'
180+
make -j "$(nproc)" V=1
181+
182+
for lib in librtas librtasevent ; do
183+
mkdir -p "${abi_dir}/${lib}"
184+
declare -a abidw_opts
185+
abidw_opts=(
186+
--annotate
187+
--drop-private-types
188+
--drop-undefined-syms
189+
--no-corpus-path
190+
--no-show-locs
191+
--type-id-style hash
192+
)
193+
case "$lib" in
194+
librtas)
195+
abidw_opts+=(
196+
--header-file librtas_src/librtas.h
197+
)
198+
;;
199+
librtasevent)
200+
abidw_opts+=(
201+
--header-file librtasevent_src/librtasevent.h
202+
--header-file librtasevent_src/librtasevent_v4.h
203+
--header-file librtasevent_src/librtasevent_v6.h
204+
)
205+
;;
206+
esac
207+
abidw "${abidw_opts[@]}" --out-file "${abi_dir}/${lib}/${host}.xml" ".libs/${lib}.so"
208+
done
209+
make distclean
210+
done
211+
EOF
212+
podman run "${runc_opts[@]}" debian:bookworm
213+
214+
cp -r "${worktree_dir}/${abi_dir}"/librtas/ "$abi_dir"/
215+
cp -r "${worktree_dir}/${abi_dir}"/librtasevent/ "$abi_dir"/
216+
if git diff --quiet -- "$abi_dir"; then
217+
echo "ABI definitions unchanged."
218+
else
219+
echo "ABI definitions changed, please review:"
220+
git diff --stat -- "$abi_dir"
221+
fi
222+
223+
# ^^^ TERMINATE YOUR CODE BEFORE THE BOTTOM ARGBASH MARKER ^^^
224+
225+
# ] <-- needed because of Argbash

0 commit comments

Comments
 (0)