Skip to content
Snippets Groups Projects
Commit 1e8c35d7 authored by Philippe Canal's avatar Philippe Canal
Browse files

Separate testing and applying clang-format.

Use ./scripts/clang-format-apply.sh to apply the recommended change. Running clang-format-test.sh
will report if changes are needed but will leave the source unchanged.
parent b331f64c
No related branches found
No related tags found
1 merge request!244Clang format test improvement
Pipeline #
#!/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 --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 -i -e linkdef | grep -v -e nudy -e cmsToyGV -e examples/physics/Geant4`
# 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 | grep "modified"`
# 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)";
for f in $notcorrectlist; do
echo $f
git diff $f
done
fi
exit 1
......@@ -6,83 +6,12 @@
# the result of 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 --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 -i -e linkdef | grep -v -e nudy -e cmsToyGV -e examples/physics/Geant4`
# 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
./scripts/clang-format-apply.sh
res=$?
# 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 | grep "modified"`
# 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)";
for f in $notcorrectlist; do
echo $f
git diff $f
done
if [ $res -eq 0 ] ; then
# cleanup changes in git
echo git reset HEAD --hard
fi
# cleanup changes in git
git reset HEAD --hard
exit 1
exit $res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment