File: check_style.sh

package info (click to toggle)
android-platform-tools 35.0.2-1~exp6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 211,716 kB
  • sloc: cpp: 995,749; java: 290,495; ansic: 145,647; xml: 58,531; python: 39,608; sh: 14,500; javascript: 5,198; asm: 4,866; makefile: 3,115; yacc: 769; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (40 lines) | stat: -rwxr-xr-x 1,332 bytes parent folder | download | duplicates (5)
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 $*