#!/bin/bash
-newline_check_result=""
-
function pushd () {
command pushd "$@" > /dev/null
}
fi
}
-function check_newline_crlf() {
- FILE_TO_CHECK=$1
- CRLFCHECK=$(find $FILE_TO_CHECK -not -type d -exec file "{}" ";" | grep CRLF)
- if [[ ! -z "${CRLFCHECK}" ]]; then
- newline_check_result+=" CRLF FOUND in ${FILE_TO_CHECK}"
- newline_check_result+=$'\n'
+function check_newline_cr() {
+
+ # Check all files (CMakeLists.txt, *.cl, ... not only for C++, Python)
+ FILES_TO_CHECK=$(git ls-files)
+ if [[ ${#FILES_TO_CHECK} -ne 0 ]]; then
+ CRCHECK=$(file $FILES_TO_CHECK | grep 'with CR')
fi
}
CPP_FILES_TO_CHECK=${ARR[*]}
if [[ ${#CPP_FILES_TO_CHECK} -ne 0 ]]; then
clang-format-3.9 -i $CPP_FILES_TO_CHECK
- check_newline_crlf $CPP_FILES_TO_CHECK
fi
popd
done
PYTHON_FILES_TO_CHECK=${ARR[*]}
if [[ ${#PYTHON_FILES_TO_CHECK} -ne 0 ]]; then
yapf -i --style='{based_on_style: pep8, column_limit: 90}' $PYTHON_FILES_TO_CHECK
- check_newline_crlf $PYTHON_FILES_TO_CHECK
fi
popd
done
exit 0
fi
+check_newline_cr
+
if [[ $__Check_CPP -ne 0 ]]; then
check_cpp_tool
check_cpp_files $DIRECTORIES_TO_BE_TESTED $DIRECTORIES_NOT_TO_BE_TESTED
git diff --ignore-submodules > format.patch
PATCHFILE_SIZE=$(stat -c%s format.patch)
-if [[ $PATCHFILE_SIZE -ne 0 ]]; then
- echo "[FAILED] Format checker failed and update code to follow convention."
- echo " You can find changes in format.patch"
- exit 1
-else
- if [ -n "$newline_check_result" ]; then
- echo "[FAILED] Please use LF for newline instead of CRLF."
- echo "$newline_check_result"
- exit 1
- fi
+
+if [[ -z "${CRCHECK}" ]] && [[ $PATCHFILE_SIZE -eq 0 ]]; then
echo "[PASSED] Format checker succeed."
exit 0
fi
-echo "Error: Something went wrong."
+# Something went wrong
+
+if [[ ! -z "${CRCHECK}" ]]; then
+ echo "[FAILED] Please use LF for newline for following files."
+ echo $CRCHECK
+fi
+
+if [[ $PATCHFILE_SIZE -ne 0 ]]; then
+ echo "[FAILED] Format checker failed and update code to follow convention."
+ echo " You can find changes in format.patch"
+fi
exit 1