#!/bin/bash
INVALID_EXIT=0
+FILES_TO_CHECK=()
+DIRECTORIES_NOT_TO_BE_TESTED=()
function pushd () {
command pushd "$@" > /dev/null
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
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}")
+ FILES_TO_CHECK_PERMISSION=()
+ for f in ${FILES_TO_CHECK[@]}; do
+ # Manually ignore permission checking
+ if [[ ${f} == !(nnas|nnfw|nncc|*.sh|*.py|scripts/standalone) ]]; then
+ FILES_TO_CHECK_PERMISSION+=("${f}")
+ fi
done
- if [[ ${#FILES_TO_CHECK} -eq 0 ]]; then
+ if [[ ${#FILES_TO_CHECK_PERMISSION} -eq 0 ]]; then
return
fi
- for FILE_TO_CHECK in ${FILES_TO_CHECK[@]}; do
+ for FILE_TO_CHECK in ${FILES_TO_CHECK_PERMISSION[@]}; do
RESULT=$(stat -c '%A' ${FILE_TO_CHECK} | grep 'x')
if [ "${RESULT}" != "" ]; then
chmod a-x ${FILE_TO_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' ':!:**/NeuralNetworks.h')
- ARR=(${CPP_FILES_TO_CHECK})
+ FILES_TO_CHECK_CPP=()
+ for f in ${FILES_TO_CHECK[@]}; do
+ # Manually ignore style checking
+ if [[ ${f} == */NeuralNetworks.h ]]; then
+ continue
+ fi
+
+ # File extension to check
+ if [[ ${f} == +(*.h|*.cpp|*.cc|*.c|*.cl) ]]; then
+ FILES_TO_CHECK_CPP+=("${f}")
+ fi
+ done
+
+ # Skip by '.FORMATDENY' file
for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
skip=${s#'.'/}/
- ARR=(${ARR[*]//$skip*/})
+ FILES_TO_CHECK_CPP=(${FILES_TO_CHECK_CPP[*]/$skip*/})
done
- CPP_FILES_TO_CHECK=${ARR[*]}
- if [[ ${#CPP_FILES_TO_CHECK} -ne 0 ]]; then
- clang-format-3.9 -i ${CPP_FILES_TO_CHECK}
+
+ if [[ ${#FILES_TO_CHECK_CPP} -ne 0 ]]; then
+ clang-format-3.9 -i ${FILES_TO_CHECK_CPP[@]}
EXIT_CODE=$?
if [[ ${EXIT_CODE} -ne 0 ]]; then
INVALID_EXIT=${EXIT_CODE}
- fi
+ fi
fi
}
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})
+ FILES_TO_CHECK_PYTHON=()
+ for f in ${FILES_TO_CHECK[@]}; do
+ # Manually ignore style checking
+ if [[ ${f} == compiler/* ]]; then
+ continue
+ fi
+
+ # File extension to check
+ if [[ ${f} == *.py ]]; then
+ FILES_TO_CHECK_PYTHON+=("${f}")
+ fi
+ done
for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do
skip=${s#'.'/}/
- ARR=(${ARR[*]//$skip*/})
+ FILES_TO_CHECK_PYTHON=(${FILES_TO_CHECK_PYTHON[*]/$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}
+
+ if [[ ${#FILES_TO_CHECK_PYTHON} -ne 0 ]]; then
+ yapf -i --style='{based_on_style: pep8, column_limit: 90}' ${FILES_TO_CHECK_PYTHON[@]}
EXIT_CODE=$?
if [[ ${EXIT_CODE} -ne 0 ]]; then
INVALID_EXIT=${EXIT_CODE}
__Check_CPP=${CHECK_CPP:-"1"}
__Check_PYTHON=${CHECK_PYTHON:-"1"}
-DIRECTORIES_NOT_TO_BE_TESTED=()
+FILES_TO_CHECK=$(git ls-files)
+if [[ "${CHECK_DIFF_ONLY}" = "1" ]]; then
+ MASTER_EXIST=$(git rev-parse --verify master)
+ CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2-)
+ if [[ -z "${MASTER_EXIST}" ]]; then
+ echo "Cannot found local master branch"
+ elif [[ "${CURRENT_BRANCH}" = "master" ]]; then
+ echo "Current branch is master"
+ else
+ FILES_TO_CHECK=$(git diff --name-only master)
+ fi
+fi
for DIR_NOT_TO_BE_TESTED in $(find -name '.FORMATDENY' -exec dirname {} \;); do
DIRECTORIES_NOT_TO_BE_TESTED+=("${DIR_NOT_TO_BE_TESTED}")
check_newline
check_permission
-check_cpp_files ${DIRECTORIES_NOT_TO_BE_TESTED}
-check_python_files ${DIRECTORIES_NOT_TO_BE_TESTED}
+check_cpp_files
+check_python_files
DIFF=$(git diff | tee format.patch)