1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#!/bin/bash
. "${0%/*}"/../lib.sh
findfiles() {
find "${top_srcdir}" \
'(' -type d -a '(' -name .git -o -name autotools ')' -prune ')' \
-o '(' '(' -name '*.[ch]' -a ! -name 'config.h' ')' -print0 ')'
}
#
# don't allow obsolete functions
#
findfiles | xargs -0 \
grep -n -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utimes)\>[[:space:]]*\(' \
| sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.obsolete.funcs
testit src.obsolete.funcs
#
# make sure people use our constants
#
findfiles | xargs -0 \
grep -n -E -e '\<PATH_MAX\>' | grep -v __PAX_UTILS_PATH_MAX \
| sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.bad.constants
testit src.bad.constants
#
# don't allow obsolete headers
#
findfiles | xargs -0 \
grep -n -E -e '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' \
| sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.obsolete.headers
testit src.obsolete.headers
#
# make sure people use the x* helper funcs
#
xfuncs=$(printf '%s|' $(sed -n 's:.*x\([^(]*\)(.*:\1:p' "${top_srcdir}"/xfuncs.h))
xfuncs=${xfuncs:0:${#xfuncs}-1}
findfiles | xargs -0 \
grep -n -E -e "\<(${xfuncs})[[:space:]]*\(" \
| grep -v xfuncs.c \
| sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.use.xfuncs
testit src.use.xfuncs
#
# check for style
#
findfiles | xargs -0 \
grep -n -E \
-e '\<(for|if|switch|while)\(' \
-e '\<(for|if|switch|while) \( ' \
-e ' ;' \
-e '[[:space:]]$' \
-e '\){' \
-e '(^|[^:])//' \
| sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.style
testit src.style
#
# Auto clean up the space issues
#
while read -d'\0' x; do
case ${x} in
*/elf.h) continue ;; # Not our files
esac
./space "${x}" > "${builddir}/${x}~"
if ! diff -u "${x}" "${builddir}/${x}~" ; then
echo "New file: ${x}~"
else
rm -f "${builddir}/${x}~"
fi
done > "${builddir}"/src.space < <(findfiles)
testit src.space
#
# Make sure we don't keep re-importing stuff into elf.h that
# breaks non-GNU systems. #507470
#
grep -E "features.h|_DECLS" "${top_srcdir}"/elf.h > "${builddir}"/src.elf.h
testit src.elf.h
#
# Python checks
#
if pyflakes </dev/null 2>/dev/null; then
find "${top_srcdir}" \
'!' -ipath '*/tests/*' \
-name '*.py' \
-exec pyflakes {} + > "${builddir}"/src.pyflakes
testit src.pyflakes
fi
exit ${ret}
|