1#!/bin/bash 2#VERSION=1 3 4SELFNAME=$0 5 6function printUsage() { 7 echo " $SELFNAME check coding style for HEAD in this git repository" 8 echo " $SELFNAME -h show this message" 9} 10 11function main() { 12 test "$1" == "-h" && printUsage && exit 13 test "$ANDROID_BUILD_TOP" == "" && echo "please run env setup" && exit 14 GITROOTDIR=`git rev-parse --show-toplevel` 15 test "$GITROOTDIR" == "" && echo "not inside a git repository" && exit 16 MODIFIED=`git status -s --untracked-files=no | wc -l` 17 test $MODIFIED -ne 0 && echo "please commit first" && exit 18 19 cd $GITROOTDIR 20 21 #basic check 22 local PARAMS=" --config_xml $ANDROID_BUILD_TOP/prebuilts/checkstyle/android-style.xml" 23 $ANDROID_BUILD_TOP/prebuilts/checkstyle/checkstyle.py $PARAMS 24 25 #C++ check, no-op if no C, C++ files. 26 $ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/clang-stable/bin/git-clang-format \ 27 --commit HEAD^ --style file --extensions c,h,cc,cpp 28 29 #commit message equal or less then 65 char for each line (suggested by lorenzo@20180625) 30 local MSG=`git rev-list --format=%B --max-count=1 HEAD` 31 local i=1 32 while read -r line; do 33 test `echo $line | wc -c` -gt 65 && echo "FAILED: Line $i exceed 65 chars limit: $line" 34 i=$((i+1)) 35 done < <(echo "$MSG") 36 37 cd - 38} 39 40main $* 41