diff options
| author | N.E.C <beholdnec@gmail.com> | 2017-08-06 18:19:15 -0700 |
|---|---|---|
| committer | N.E.C <beholdnec@gmail.com> | 2017-08-16 22:28:02 -0700 |
| commit | f9b83651904e40341bdfba5b889f57a0b6bf6e96 (patch) | |
| tree | d9fe4bb495961b8d452dc1c8a3797a891aed819d /Tools | |
| parent | 918b0375e4e80ffd2f019a29789919f7cb0b27f3 (diff) | |
Tools: Check for git and clang-format version 3.8.* in lint.sh
Diffstat (limited to 'Tools')
| -rwxr-xr-x | Tools/lint.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Tools/lint.sh b/Tools/lint.sh index c7ce3ed5b5..4f0fbe2e2f 100755 --- a/Tools/lint.sh +++ b/Tools/lint.sh @@ -4,6 +4,43 @@ set -euo pipefail +if ! [ -x "$(command -v git)" ]; then + echo >&2 "error: git is not installed" + exit 1 +fi + +REQUIRED_CLANG_FORMAT_MAJOR=3 +REQUIRED_CLANG_FORMAT_MINOR=8 + +if ! [ -x "$(command -v clang-format)" ]; then + echo >&2 "error: clang-format is not installed" + echo >&2 "Install clang-format version ${REQUIRED_CLANG_FORMAT_MAJOR}.${REQUIRED_CLANG_FORMAT_MINOR}.*" + exit 1 +fi + +FORCE=0 + +if [ $# -gt 0 ]; then + case "$1" in + -f|--force) + FORCE=1 + shift + ;; + esac +fi + +if [ $FORCE -eq 0 ]; then + CLANG_FORMAT_VERSION=$(clang-format -version | cut -d' ' -f3) + CLANG_FORMAT_MAJOR=$(echo $CLANG_FORMAT_VERSION | cut -d'.' -f1) + CLANG_FORMAT_MINOR=$(echo $CLANG_FORMAT_VERSION | cut -d'.' -f2) + + if [ $CLANG_FORMAT_MAJOR != $REQUIRED_CLANG_FORMAT_MAJOR ] || [ $CLANG_FORMAT_MINOR != $REQUIRED_CLANG_FORMAT_MINOR ]; then + echo >&2 "error: clang-format is the wrong version (${CLANG_FORMAT_VERSION})" + echo >&2 "Install clang-format version ${REQUIRED_CLANG_FORMAT_MAJOR}.${REQUIRED_CLANG_FORMAT_MINOR}.* or use --force to ignore" + exit 1 + fi +fi + fail=0 # Default to staged files, unless a commit was passed. |
