2015-09-23 15:52:44 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
readonly BASEDIR=$(readlink -f $(dirname $0))/..
|
|
|
|
cd $BASEDIR
|
|
|
|
|
|
|
|
# exit on errors
|
|
|
|
set -e
|
|
|
|
|
2016-10-18 16:56:25 +00:00
|
|
|
rc=0
|
|
|
|
|
2015-09-23 15:52:44 +00:00
|
|
|
if hash astyle; then
|
|
|
|
echo -n "Checking coding style..."
|
|
|
|
rm -f astyle.log
|
|
|
|
touch astyle.log
|
2017-03-02 14:12:20 +00:00
|
|
|
# Exclude rte_vhost code imported from DPDK - we want to keep the original code
|
|
|
|
# as-is to enable ongoing work to synch with a generic upstream DPDK vhost library,
|
|
|
|
# rather than making diffs more complicated by a lot of changes to follow SPDK
|
|
|
|
# coding standards.
|
2017-05-30 21:13:50 +00:00
|
|
|
git ls-files '*.[ch]' '*.cpp' '*.cc' '*.cxx' '*.hh' '*.hpp' | \
|
2017-10-18 17:06:51 +00:00
|
|
|
grep -v rte_vhost | grep -v cpp_headers | \
|
2017-04-26 23:31:44 +00:00
|
|
|
xargs astyle --options=.astylerc >> astyle.log
|
2015-09-23 15:52:44 +00:00
|
|
|
if grep -q "^Formatted" astyle.log; then
|
|
|
|
echo " errors detected"
|
2016-01-14 16:56:42 +00:00
|
|
|
git diff
|
2015-09-23 15:52:44 +00:00
|
|
|
sed -i -e 's/ / /g' astyle.log
|
|
|
|
grep --color=auto "^Formatted.*" astyle.log
|
|
|
|
echo "Incorrect code style detected in one or more files."
|
|
|
|
echo "The files have been automatically formatted."
|
|
|
|
echo "Remember to add the files to your commit."
|
2016-10-18 16:56:25 +00:00
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
2015-09-23 15:52:44 +00:00
|
|
|
fi
|
|
|
|
rm -f astyle.log
|
|
|
|
else
|
|
|
|
echo "You do not have astyle installed so your code style is not being checked!"
|
|
|
|
fi
|
|
|
|
|
2017-04-24 18:14:41 +00:00
|
|
|
echo -n "Checking comment style..."
|
|
|
|
|
2017-04-25 17:35:22 +00:00
|
|
|
git grep --line-number -e '/[*][^ *-]' -- '*.[ch]' > comment.log || true
|
2017-10-18 17:06:51 +00:00
|
|
|
git grep --line-number -e '[^ ][*]/' -- '*.[ch]' ':!lib/vhost/rte_vhost*/*' >> comment.log || true
|
2017-04-25 17:35:22 +00:00
|
|
|
git grep --line-number -e '^[*]' -- '*.[ch]' >> comment.log || true
|
2017-04-24 18:14:41 +00:00
|
|
|
|
|
|
|
if [ -s comment.log ]; then
|
|
|
|
echo " Incorrect comment formatting detected"
|
|
|
|
cat comment.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f comment.log
|
|
|
|
|
2018-03-02 19:49:36 +00:00
|
|
|
echo -n "Checking for spaces before tabs..."
|
|
|
|
git grep --line-number $' \t' -- > whitespace.log || true
|
|
|
|
if [ -s whitespace.log ]; then
|
|
|
|
echo " Spaces before tabs detected"
|
|
|
|
cat whitespace.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f whitespace.log
|
|
|
|
|
2018-01-29 23:43:37 +00:00
|
|
|
echo -n "Checking trailing whitespace in output strings..."
|
|
|
|
|
|
|
|
git grep --line-number -e ' \\n"' -- '*.[ch]' > whitespace.log || true
|
|
|
|
|
|
|
|
if [ -s whitespace.log ]; then
|
|
|
|
echo " Incorrect trailing whitespace detected"
|
|
|
|
cat whitespace.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f whitespace.log
|
|
|
|
|
2017-12-08 00:18:21 +00:00
|
|
|
echo -n "Checking for use of forbidden library functions..."
|
|
|
|
|
2018-04-09 23:10:43 +00:00
|
|
|
git grep --line-number -w '\(strncpy\|strcpy\|sprintf\|vsprintf\)' -- './*.c' ':!lib/vhost/rte_vhost*/**' > badfunc.log || true
|
2017-12-08 00:18:21 +00:00
|
|
|
if [ -s badfunc.log ]; then
|
|
|
|
echo " Forbidden library functions detected"
|
|
|
|
cat badfunc.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f badfunc.log
|
|
|
|
|
2016-10-18 16:56:25 +00:00
|
|
|
echo -n "Checking blank lines at end of file..."
|
|
|
|
|
|
|
|
if ! git grep -I -l -e . -z | \
|
|
|
|
xargs -0 -P8 -n1 scripts/eofnl > eofnl.log; then
|
|
|
|
echo " Incorrect end-of-file formatting detected"
|
|
|
|
cat eofnl.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f eofnl.log
|
|
|
|
|
2017-05-08 19:46:11 +00:00
|
|
|
echo -n "Checking for POSIX includes..."
|
2017-11-20 15:31:58 +00:00
|
|
|
git grep -I -i -f scripts/posix.txt -- './*' ':!include/spdk/stdinc.h' ':!include/linux/**' ':!lib/vhost/rte_vhost*/**' ':!scripts/posix.txt' > scripts/posix.log || true
|
2017-05-08 19:46:11 +00:00
|
|
|
if [ -s scripts/posix.log ]; then
|
|
|
|
echo "POSIX includes detected. Please include spdk/stdinc.h instead."
|
|
|
|
cat scripts/posix.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f scripts/posix.log
|
|
|
|
|
2016-10-18 16:56:25 +00:00
|
|
|
if hash pep8; then
|
|
|
|
echo -n "Checking Python style..."
|
|
|
|
|
|
|
|
PEP8_ARGS+=" --max-line-length=140"
|
|
|
|
|
|
|
|
error=0
|
|
|
|
git ls-files '*.py' | xargs -n1 pep8 $PEP8_ARGS > pep8.log || error=1
|
|
|
|
if [ $error -ne 0 ]; then
|
|
|
|
echo " Python formatting errors detected"
|
|
|
|
cat pep8.log
|
|
|
|
rc=1
|
|
|
|
else
|
|
|
|
echo " OK"
|
|
|
|
fi
|
|
|
|
rm -f pep8.log
|
|
|
|
fi
|
2016-03-16 22:00:28 +00:00
|
|
|
|
2017-08-03 18:27:53 +00:00
|
|
|
# Check if any of the public interfaces were modified by this patch.
|
|
|
|
# Warn the user to consider updating the changelog any changes
|
|
|
|
# are detected.
|
|
|
|
echo -n "Checking whether CHANGELOG.md should be updated..."
|
|
|
|
staged=$(git diff --name-only --cached .)
|
|
|
|
working=$(git status -s --porcelain | grep -iv "??" | awk '{print $2}')
|
|
|
|
files="$staged $working"
|
|
|
|
if [[ "$files" = " " ]]; then
|
|
|
|
files=$(git diff-tree --no-commit-id --name-only -r HEAD)
|
|
|
|
fi
|
|
|
|
|
|
|
|
has_changelog=0
|
|
|
|
for f in $files; do
|
|
|
|
if [[ $f == CHANGELOG.md ]]; then
|
|
|
|
# The user has a changelog entry, so exit.
|
|
|
|
has_changelog=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
needs_changelog=0
|
|
|
|
if [ $has_changelog -eq 0 ]; then
|
|
|
|
for f in $files; do
|
|
|
|
if [[ $f == include/spdk/* ]] || [[ $f == scripts/rpc.py ]] || [[ $f == etc/* ]]; then
|
|
|
|
echo ""
|
|
|
|
echo -n "$f was modified. Consider updating CHANGELOG.md."
|
|
|
|
needs_changelog=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $needs_changelog -eq 0 ]; then
|
|
|
|
echo " OK"
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
2016-10-18 16:56:25 +00:00
|
|
|
exit $rc
|