#!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$DIR/../../" tmpfile="$DIR/cppcheck_and_clang_format.tmp" errfile="$DIR/cppcheck_and_clang_format.txt" mode=${1:-diff} threads=$( cat /proc/cpuinfo | grep processor | wc -l ) if [ "$mode" == diff ]; then files=$( git diff --name-only HEAD~1 HEAD | egrep '^(src|tests|poc)' | egrep '\.(hpp|h|cpp)$' ) flags="" else files=src/ flags="-j$threads -Isrc" fi cat > .cppcheck_suppressions <"$tmpfile" rm .cppcheck_suppressions cat "$tmpfile" | grep -v "(information) Unmatched suppression" > "$errfile" rm $tmpfile cat "$errfile" >&2 len="$( cat "$errfile" | wc -l )" if [ $len -gt 0 ]; then echo -e "==== Cppcheck errors: ====\n\n\`\`\`\n$( cat "$errfile" )\n\`\`\`" > "$errfile" fi # check for clang-format errors format_list="" format_tmp="$DIR/.clang_format" if [ -f "$format_tmp" ]; then rm "$format_tmp" fi for fname in $files; do if [ ! -f "$fname" ]; then continue; fi echo "Checking formatting errors for: $fname" clang-format "$fname" > "$format_tmp" if ! diff "$fname" "$format_tmp" >/dev/null; then format_list+="\n$fname" fi rm "$format_tmp" done 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