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