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 83 84 85 86 87 88 89 90 91 92 93
|
#!/bin/bash
#==========================================================================
#
# Copyright Insight Software Consortium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#==========================================================================*/
## the intent of this file is to clean the files, make them KWSTYLE compliant,
## and then make sure that subsequent runs of this script do not modify `
## The goal of this script is to develop a consistent system of auto-formating
## and format testing such that if uncrustify is run, then the code will pass
## the KWStyle format checker
## https://www.itk.org/Wiki/ITKv4_StyleChangeProposal
if [ -f stop ]; then
echo "Quitting because stop function given"
exit -1;
fi
mkdir -p kwstyle
UNCRUSTIFYBIN=$(git config hooks.uncrustify.path) ||
UNCRUSTIFYBIN=$(which uncrustify) ||
die "uncrustify executable was not found.
Please install uncrustify or set the executable location with
git config hooks.uncrustify.path /path/to/uncrustify
See https://github.com/uncrustify/uncrustify"
for file in $@; do
KWERRORS=kwstyle/${file}.txt
touch ${KWERRORS}
while [ -f ${KWERRORS} ]; do
if [ -f stop ]; then
exit -1
fi
if [ ! -f ${KWERRORS}_skip_uncrustify ]; then
### A possible bug in uncrustify breaks complicated macros by adding extra spaces surrounding "##" and "#"
### This is an interaction betweeen the macro directives and indenting of includes and defines.
${UNCRUSTIFYBIN} -c @ITK_SOURCE_DIR@/Utilities/Maintenance/uncrustify_itk.cfg -l CPP -f ${file} | sed 's/ *## */##/g' | sed 's/# */#/g' > ${file}_uncrustify
diff ${file}_uncrustify ${file}
if [ $? -ne 0 ]; then
mv ${file}_uncrustify ${file}
else
rm ${file}_uncrustify
fi
fi
@KWSTYLE_EXECUTABLE@ -xml @ITK_BINARY_DIR@/Utilities/KWStyle/ITK.kws.xml -v -o @ITK_SOURCE_DIR@/Utilities/KWStyle/ITKOverwrite.txt -gcc $file > ${KWERRORS}
find ${KWERRORS} -size 0 -exec rm {} \;
if [ -f ${KWERRORS} ]; then
vim -q ${KWERRORS}
echo "Shall I skip uncrustify step (y/n)? Or ignore KWErrors (U)?"
read skipuncrustify
if [ ${skipuncrustify} == "y" ]; then
${UNCRUSTIFYBIN} -c @ITK_SOURCE_DIR@/Utilities/Maintenance/uncrustify_itk.cfg -l CPP -f ${file} -o ${KWERRORS}_skip_uncrustify
fi
if [ ${skipuncrustify} == "U" ]; then
echo "Ignoring KWErrors"
rm ${KWERRORS}
fi
fi
done
done
|