set -e
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CPPLINT="$ROOT/../../scripts/cpplint.py"
if [ ! -x "$CPPLINT" ]; then
CPPLINT="$ROOT/cpplint.py"
fi
PYTHON=$(which python || true)
if [ -z "$PYTHON" ]; then
PYTHON=$(which python3 || true)
fi
check_c_enums=
check_go_enums=
logged_python=
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep -E "\.cc$|\.h$|\.c$"` ; do
if [ -z "$PYTHON" ]; then
if [ -z "$logged_python" ]; then
echo "WARNING: Could not find valid Python interpreter to run cpplint, skipping checks..."
logged_python=1
fi
else
"$PYTHON" "$CPPLINT" "$file"
fi
if [ "$file" = "libheif/heif.h" ] ; then
check_c_enums=1
check_go_enums=1
fi
if [ "$file" = "libheif/heif_emscripten.h" ] ; then
check_c_enums=1
fi
done
if [ "$check_c_enums" = "1" ]; then
CHECK_EMSCRIPTEN="$ROOT/../../scripts/check-emscripten-enums.sh"
if [ ! -x "$CHECK_EMSCRIPTEN" ]; then
CHECK_EMSCRIPTEN="$ROOT/check-emscripten-enums.sh"
fi
"$CHECK_EMSCRIPTEN"
fi
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.go$"` ; do
nf=`git checkout-index --temp ${file} | cut -f 1`
newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
gofmt ${nf} > "${newfile}" 2>> /dev/null
set +e
diff -u -p --label "$file" "${nf}" --label "$file (formatted)" "${newfile}"
r=$?
set -e
rm "${newfile}"
rm "${nf}"
if [ $r != 0 ] ; then
echo "================================================================================================="
echo " Code format error in: $file "
echo " "
echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
echo " If the whole file is to be committed, this should work (run from the top-level directory): "
echo " "
echo " go fmt $file; git add $file; git commit"
echo " "
echo "================================================================================================="
exit 1
fi
if [ "$file" = "go/heif/heif.go" ] ; then
check_go_enums=1
fi
done
if [ "$check_go_enums" = "1" ]; then
CHECK_GO="$ROOT/../../scripts/check-go-enums.sh"
if [ ! -x "$CHECK_GO" ]; then
CHECK_GO="$ROOT/check-go-enums.sh"
fi
"$CHECK_GO"
fi