2017-07-29 19:28:09 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
cd "$DIR/../../"
|
|
|
|
|
2020-09-21 18:22:40 +08:00
|
|
|
tmpfile="$DIR/cppcheck_and_clang_format.tmp"
|
|
|
|
errfile="$DIR/cppcheck_and_clang_format.txt"
|
2017-07-29 19:28:09 +08:00
|
|
|
|
2020-09-21 18:22:40 +08:00
|
|
|
mode=${1:-diff}
|
|
|
|
threads=$( cat /proc/cpuinfo | grep processor | wc -l )
|
2017-07-30 16:58:19 +08:00
|
|
|
|
|
|
|
if [ "$mode" == diff ]; then
|
2018-03-27 04:35:55 +08:00
|
|
|
files=$( git diff --name-only HEAD~1 HEAD | egrep '^(src|tests|poc)' | egrep '\.(hpp|h|cpp)$' )
|
2017-07-30 16:58:19 +08:00
|
|
|
flags=""
|
|
|
|
else
|
|
|
|
files=src/
|
2020-09-21 18:22:40 +08:00
|
|
|
flags="-j$threads -Isrc"
|
2017-07-30 16:58:19 +08:00
|
|
|
fi
|
2017-11-09 20:46:37 +08:00
|
|
|
|
2017-12-15 17:33:41 +08:00
|
|
|
cat > .cppcheck_suppressions <<EOF
|
2017-11-09 20:46:37 +08:00
|
|
|
// supress all explicit constructor warnings since we use the implicit conversion all over the codebase
|
|
|
|
noExplicitConstructor:src/storage/property_value.hpp
|
|
|
|
noExplicitConstructor:src/query/typed_value.hpp
|
|
|
|
noExplicitConstructor:src/communication/bolt/v1/decoder/decoded_value.hpp
|
|
|
|
|
|
|
|
// suppress antrl warnings
|
|
|
|
variableScope:src/query/frontend/opencypher/generated/CypherParser.h
|
|
|
|
variableScope:src/query/frontend/opencypher/generated/CypherLexer.h
|
|
|
|
variableScope:src/query/frontend/opencypher/generated/CypherParser.cpp
|
|
|
|
|
|
|
|
// supress all warnings of this type in the codebase
|
|
|
|
missingInclude
|
|
|
|
unusedFunction
|
|
|
|
unusedStructMember
|
2019-04-25 18:02:54 +08:00
|
|
|
useStlAlgorithm
|
2017-11-09 20:46:37 +08:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cppcheck --enable=all --inline-suppr --force --suppressions-list=.cppcheck_suppressions $flags $files 2>"$tmpfile"
|
|
|
|
rm .cppcheck_suppressions
|
2017-11-06 17:05:03 +08:00
|
|
|
|
|
|
|
cat "$tmpfile" | grep -v "(information) Unmatched suppression" > "$errfile"
|
|
|
|
rm $tmpfile
|
2017-07-29 19:28:09 +08:00
|
|
|
|
|
|
|
cat "$errfile" >&2
|
|
|
|
|
|
|
|
len="$( cat "$errfile" | wc -l )"
|
|
|
|
if [ $len -gt 0 ]; then
|
2017-08-24 21:03:21 +08:00
|
|
|
echo -e "==== Cppcheck errors: ====\n\n\`\`\`\n$( cat "$errfile" )\n\`\`\`" > "$errfile"
|
2017-07-29 19:28:09 +08:00
|
|
|
fi
|
2017-12-15 17:33:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
# check for clang-format errors
|
|
|
|
|
|
|
|
format_list=""
|
|
|
|
format_tmp="$DIR/.clang_format"
|
|
|
|
|
2018-01-12 17:19:37 +08:00
|
|
|
if [ -f "$format_tmp" ]; then
|
|
|
|
rm "$format_tmp"
|
|
|
|
fi
|
|
|
|
|
2017-12-15 17:33:41 +08:00
|
|
|
for fname in $files; do
|
|
|
|
if [ ! -f "$fname" ]; then continue; fi
|
2018-01-12 17:19:37 +08:00
|
|
|
echo "Checking formatting errors for: $fname"
|
2017-12-15 17:33:41 +08:00
|
|
|
clang-format "$fname" > "$format_tmp"
|
|
|
|
if ! diff "$fname" "$format_tmp" >/dev/null; then
|
|
|
|
format_list+="\n$fname"
|
|
|
|
fi
|
|
|
|
rm "$format_tmp"
|
2018-01-12 17:19:37 +08:00
|
|
|
done
|
2017-12-15 17:33:41 +08:00
|
|
|
|
|
|
|
if [ "$format_list" != "" ]; then
|
|
|
|
if [ "$( cat "$errfile" | wc -l )" -gt 0 ]; then
|
|
|
|
echo "" >> "$errfile"
|
|
|
|
fi
|
|
|
|
echo -e "==== Clang-format should be applied on: ====\n\n\`\`\`$format_list\n\`\`\`" >> "$errfile"
|
|
|
|
fi
|