From 69ac39edb20d814469bc2d85091112a08b632fbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=EC=83=81=EA=B7=9C/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Principal=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 18 Oct 2018 11:01:11 +0900 Subject: [PATCH] Apply CRLF check for all regular files (#3179) All regular files under git-control are CRLF checked. Signed-off-by: Sanggyu Lee --- scripts/command/format-checker.sh | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/command/format-checker.sh b/scripts/command/format-checker.sh index 8b48920..7c2b477 100755 --- a/scripts/command/format-checker.sh +++ b/scripts/command/format-checker.sh @@ -1,7 +1,5 @@ #!/bin/bash -newline_check_result="" - function pushd () { command pushd "$@" > /dev/null } @@ -28,12 +26,12 @@ function check_python_tool() { 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 } @@ -55,7 +53,6 @@ function check_cpp_files() { 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 @@ -79,7 +76,6 @@ function check_python_files() { 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 @@ -106,6 +102,8 @@ if [[ ${#DIRECTORIES_TO_BE_TESTED[@]} -eq 0 ]]; then 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 @@ -118,19 +116,21 @@ fi 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 -- 2.7.4