File: checkpatch.sh

package info (click to toggle)
chirp 1%3A20221106%2Bpy3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,144 kB
  • sloc: python: 119,334; ansic: 296; sh: 184; makefile: 41
file content (72 lines) | stat: -rwxr-xr-x 1,487 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#
# CHIRP coding standards compliance script
#
# To add a test to this file, create a new check_foo() function
# and then add it to the list of TESTS= below
#

TESTS="check_long_lines check_bug_number check_commit_message_line_length"

function check_long_lines() {
    local rev="$1"
    local files="$2"

    # For now, ignore this check on chirp/
    files=$(echo $files | sed -r 's#\bchirp[^ ]*\b##')

    if [ -z "$files" ]; then
        return
    fi

    pep8 --select=E501 $files || \
        error "Please use <80 columns in source files"
}

function check_bug_number() {
    local rev="$1"
    hg log -vr $rev | grep -qE '#[0-9]+' || \
        error "A bug number is required like #123"
}

function _less_than_80() {
    while true; do
        read line
        if [ -z "$line" ]; then
            break
        elif [ $(echo -n "$line" | wc -c) -ge 80 ]; then
            return 1
        fi
    done
}

function check_commit_message_line_length() {
    local rev="$1"
    hg log -vr $rev | (_less_than_80) || \
        error "Please keep commit message lines to <80 columns"
}

# --- END OF TEST FUNCTIONS ---

function error() {
    echo FAIL: $*
    ERROR=1
}

function get_touched_files() {
    local rev="$1"
    hg status -n --change $rev | grep '\.py$'
}

rev=${1:-tip}
files=$(get_touched_files $rev)

for testname in $TESTS; do
    eval "$testname $rev \"$files\""
done

if [ -z "$ERROR" ]; then
    echo "Patch '${rev}' is OK"
else
    exit 1
fi