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
|
#!/bin/bash
#
# This is apllying clang-format
# by doing a filtering step and then
# applying ./scripts/clang-format-and-fix-macros.sh
#
# check that we are in a clean state in order to prevent accidential
# changes
if [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then
echo "Script must be applied on a clean git state"
exit 1
fi
# Retrieve list of files that were changed in source branch
# with respect to master (target branch)
tb="master"
# we disregard the test/static_analysis directory since this contains LLVM code + headers
filelist=`git diff ${tb}... --name-only | grep -v "test/static_analysis"`
# function to check if C++ file (based on suffix)
# can probably be done much shorter
function checkCPP(){
if [[ $1 == *.cc ]];then
return 0
elif [[ $1 == *.cpp ]];then
return 0
elif [[ $1 == *.cxx ]];then
return 0
elif [[ $1 == *.C ]];then
return 0
elif [[ $1 == *.c++ ]];then
return 0
elif [[ $1 == *.c ]];then
return 0
elif [[ $1 == *.CPP ]];then
return 0
# header files
elif [[ $1 == *.h ]];then
return 0
elif [[ $1 == *.hpp ]];then
return 0
elif [[ $1 == *.hh ]];then
return 0
elif [[ $1 == *.icc ]];then
return 0
fi
return 1
}
echo
echo "Checking formatting using the following clang-format version:"
clang-format --version
echo
# check list of files
for f in $filelist; do
if checkCPP $f; then
echo "CHECKING MATCHING FILE ${f}"
# apply the clang-format script
./scripts/clang-format-and-fix-macros.sh ${f}
fi
done
# check if something was modified
notcorrectlist=`git status --porcelain | grep '^ M' | cut -c4-`
# if nothing changed ok
if [[ -z $notcorrectlist ]]; then
# send a negative message to gitlab
echo "Excellent. **VERY GOOD FORMATTING!** :thumbsup:"
exit 0;
else
echo "The following files have clang-format problems (showing patches)";
git diff $notcorrectlist
fi
exit 1
|