INVALID_EXIT=0
function pushd () {
- command pushd "$@" > /dev/null
+ command pushd "$@" > /dev/null
}
function popd () {
- command popd "$@" > /dev/null
+ command popd "$@" > /dev/null
}
function command_exists() {
}
function check_newline() {
- # 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
- FILES_TO_FIX=($(echo "$CRCHECK" | grep "with CRLF line" | cut -d':' -f1))
- for f in ${FILES_TO_FIX[@]}; do
- tr -d '\r' < $f > $f.fixed && cat $f.fixed > $f && rm $f.fixed
- done
- FILES_TO_FIX=($(echo "${CRCHECK}" | grep "with CR line" | cut -d':' -f1))
- for f in ${FILES_TO_FIX[@]}; do
- tr '\r' '\n' < $f > $f.fixed && cat $f.fixed > $f && rm $f.fixed
- done
+ # 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
+ FILES_TO_FIX=($(echo "$CRCHECK" | grep "with CRLF line" | cut -d':' -f1))
+ for f in ${FILES_TO_FIX[@]}; do
+ tr -d '\r' < $f > $f.fixed && cat $f.fixed > $f && rm $f.fixed
+ done
+ FILES_TO_FIX=($(echo "${CRCHECK}" | grep "with CR line" | cut -d':' -f1))
+ for f in ${FILES_TO_FIX[@]}; do
+ tr '\r' '\n' < $f > $f.fixed && cat $f.fixed > $f && rm $f.fixed
+ done
}
function check_permission() {
- # Check all files except script
- FILES_TO_CHECK=()
- for NON_SCRIPT_FILE in $(git ls-files -- . ':!:nnas' ':!:nnfw' ':!:nncc' ':!:*.sh' ':!:*.py' ':!:scripts/standalone'); do
- FILES_TO_CHECK+=("${NON_SCRIPT_FILE}")
- done
-
- if [[ ${#FILES_TO_CHECK} -eq 0 ]]; then
- return
+ # Check all files except script
+ FILES_TO_CHECK=()
+ for NON_SCRIPT_FILE in $(git ls-files -- . ':!:nnas' ':!:nnfw' ':!:nncc' ':!:*.sh' ':!:*.py' ':!:scripts/standalone'); do
+ FILES_TO_CHECK+=("${NON_SCRIPT_FILE}")
+ done
+
+ if [[ ${#FILES_TO_CHECK} -eq 0 ]]; then
+ return
+ fi
+ for FILE_TO_CHECK in ${FILES_TO_CHECK[@]}; do
+ RESULT=$(stat -c '%A' ${FILE_TO_CHECK} | grep 'x')
+ if [ "${RESULT}" != "" ]; then
+ chmod a-x ${FILE_TO_CHECK}
fi
- for FILE_TO_CHECK in ${FILES_TO_CHECK[@]}; do
- RESULT=$(stat -c '%A' ${FILE_TO_CHECK} | grep 'x')
- if [ "${RESULT}" != "" ]; then
- chmod a-x ${FILE_TO_CHECK}
- fi
- done
+ done
}
function check_cpp_files() {
- if [[ ${__Check_CPP} -ne 0 ]]; then
- return
- fi
-
- CLANG_FORMAT_CANDIDATES=()
- CLANG_FORMAT_CANDIDATES+=("clang-format")
- CLANG_FORMAT_CANDIDATES+=("clang-format-3.9")
-
- for CLANG_FORMAT_CANDIDATE in ${CLANG_FORMAT_CANDIDATES[@]}; do
- if command_exists ${CLANG_FORMAT_CANDIDATE} ; then
- CLANG_FORMAT="${CLANG_FORMAT_CANDIDATE}"
- fi
- done
+ if [[ ${__Check_CPP} -ne 0 ]]; then
+ return
+ fi
- if [[ -z ${CLANG_FORMAT} ]]; then
- echo "[ERROR] clang-format is unavailable"
- echo
- echo "Please install clang-format before running format check"
- exit 1
- fi
+ CLANG_FORMAT_CANDIDATES=()
+ CLANG_FORMAT_CANDIDATES+=("clang-format")
+ CLANG_FORMAT_CANDIDATES+=("clang-format-3.9")
- DIRECTORIES_NOT_TO_BE_TESTED=$1
-
- # Check c++ files
- CPP_FILES_TO_CHECK=$(git ls-files '*.h' '*.cpp' '*.cc' '*.c' '*.cl' ':!:runtimes/include/NeuralNetworks.h' ':!:compiler/*')
- ARR=(${CPP_FILES_TO_CHECK})
- for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
- skip=${s#'.'/}/
- ARR=(${ARR[*]//$skip*/})
- done
- CPP_FILES_TO_CHECK=${ARR[*]}
- if [[ ${#CPP_FILES_TO_CHECK} -ne 0 ]]; then
- clang-format-3.9 -i ${CPP_FILES_TO_CHECK}
- EXIT_CODE=$?
- if [[ ${EXIT_CODE} -ne 0 ]]; then
- INVALID_EXIT=${EXIT_CODE}
- fi
+ for CLANG_FORMAT_CANDIDATE in ${CLANG_FORMAT_CANDIDATES[@]}; do
+ if command_exists ${CLANG_FORMAT_CANDIDATE} ; then
+ CLANG_FORMAT="${CLANG_FORMAT_CANDIDATE}"
fi
+ done
+
+ if [[ -z ${CLANG_FORMAT} ]]; then
+ echo "[ERROR] clang-format is unavailable"
+ echo
+ echo "Please install clang-format before running format check"
+ exit 1
+ fi
+
+ DIRECTORIES_NOT_TO_BE_TESTED=$1
+
+ # Check c++ files
+ CPP_FILES_TO_CHECK=$(git ls-files '*.h' '*.cpp' '*.cc' '*.c' '*.cl' ':!:runtimes/include/NeuralNetworks.h' ':!:compiler/*')
+ ARR=(${CPP_FILES_TO_CHECK})
+ for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
+ skip=${s#'.'/}/
+ ARR=(${ARR[*]//$skip*/})
+ done
+ CPP_FILES_TO_CHECK=${ARR[*]}
+ if [[ ${#CPP_FILES_TO_CHECK} -ne 0 ]]; then
+ clang-format-3.9 -i ${CPP_FILES_TO_CHECK}
+ EXIT_CODE=$?
+ if [[ ${EXIT_CODE} -ne 0 ]]; then
+ INVALID_EXIT=${EXIT_CODE}
+ fi
+ fi
}
function check_python_files() {
- if [[ ${__Check_PYTHON} -ne 0 ]]; then
- return
- fi
-
- if ! command_exists yapf; then
- echo "[ERROR] yapf is unavailable"
- echo " Please install yapf."
- exit 1
- fi
-
- DIRECTORIES_NOT_TO_BE_TESTED=$1
-
- # Check python files
- PYTHON_FILES_TO_CHECK=$(git ls-files '*.py' ':!:compiler/*')
- ARR=(${PYTHON_FILES_TO_CHECK})
- for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
- skip=${s#'.'/}/
- ARR=(${ARR[*]//$skip*/})
- 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}
- EXIT_CODE=$?
- if [[ ${EXIT_CODE} -ne 0 ]]; then
- INVALID_EXIT=${EXIT_CODE}
- fi
+ if [[ ${__Check_PYTHON} -ne 0 ]]; then
+ return
+ fi
+
+ if ! command_exists yapf; then
+ echo "[ERROR] yapf is unavailable"
+ echo " Please install yapf."
+ exit 1
+ fi
+
+ DIRECTORIES_NOT_TO_BE_TESTED=$1
+
+ # Check python files
+ PYTHON_FILES_TO_CHECK=$(git ls-files '*.py' ':!:compiler/*')
+ ARR=(${PYTHON_FILES_TO_CHECK})
+ for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
+ skip=${s#'.'/}/
+ ARR=(${ARR[*]//$skip*/})
+ 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}
+ EXIT_CODE=$?
+ if [[ ${EXIT_CODE} -ne 0 ]]; then
+ INVALID_EXIT=${EXIT_CODE}
fi
+ fi
}
pushd ${NNAS_PROJECT_PATH}
DIRECTORIES_NOT_TO_BE_TESTED=()
for DIR_NOT_TO_BE_TESTED in $(find -name '.FORMATDENY' -exec dirname {} \;); do
- DIRECTORIES_NOT_TO_BE_TESTED+=("${DIR_NOT_TO_BE_TESTED}")
+ DIRECTORIES_NOT_TO_BE_TESTED+=("${DIR_NOT_TO_BE_TESTED}")
done
check_newline
popd
if [[ -z "${CRCHECK}" ]] && [[ ! -n "${DIFF}" ]] && [[ ${INVALID_EXIT} -eq 0 ]]; then
- echo "[PASSED] Format checker succeed."
- return
+ echo "[PASSED] Format checker succeed."
+ return
fi
# Something went wrong
if [[ ! -z "${CRCHECK}" ]]; then
- echo "[FAILED] Please use LF for newline for following files."
- echo "${CRCHECK}"
+ 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"
+ echo "[FAILED] Format checker failed and update code to follow convention."
+ echo " You can find changes in format.patch"
fi
if [[ ${INVALID_EXIT} -ne 0 ]]; then
- echo "[[FAILED] Invalid format checker exit."
+ echo "[[FAILED] Invalid format checker exit."
fi
exit 1