crypto/qat: add device files
[dpdk.git] / devtools / checkpatches.sh
1 #! /bin/sh
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
4
5 # Load config options:
6 # - DPDK_CHECKPATCH_PATH
7 # - DPDK_CHECKPATCH_LINE_LENGTH
8 . $(dirname $(readlink -e $0))/load-devel-config
9
10 length=${DPDK_CHECKPATCH_LINE_LENGTH:-80}
11
12 # override default Linux options
13 options="--no-tree"
14 options="$options --max-line-length=$length"
15 options="$options --show-types"
16 options="$options --ignore=LINUX_VERSION_CODE,\
17 FILE_PATH_CHANGES,MAINTAINERS_STYLE,SPDX_LICENSE_TAG,\
18 VOLATILE,PREFER_PACKED,PREFER_ALIGNED,PREFER_PRINTF,\
19 PREFER_KERNEL_TYPES,BIT_MACRO,CONST_STRUCT,\
20 SPLIT_STRING,LONG_LINE_STRING,\
21 LINE_SPACING,PARENTHESIS_ALIGNMENT,NETWORKING_BLOCK_COMMENT_STYLE,\
22 NEW_TYPEDEFS,COMPARISON_TO_NULL"
23
24 print_usage () {
25         cat <<- END_OF_HELP
26         usage: $(basename $0) [-q] [-v] [-nX|patch1 [patch2] ...]]
27
28         Run Linux kernel checkpatch.pl with DPDK options.
29         The environment variable DPDK_CHECKPATCH_PATH must be set.
30
31         The patches to check can be from stdin, files specified on the command line,
32         or latest git commits limited with -n option (default limit: origin/master).
33         END_OF_HELP
34 }
35
36 number=0
37 quiet=false
38 verbose=false
39 while getopts hn:qv ARG ; do
40         case $ARG in
41                 n ) number=$OPTARG ;;
42                 q ) quiet=true ;;
43                 v ) verbose=true ;;
44                 h ) print_usage ; exit 0 ;;
45                 ? ) print_usage ; exit 1 ;;
46         esac
47 done
48 shift $(($OPTIND - 1))
49
50 if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
51         print_usage >&2
52         echo
53         echo 'Cannot execute DPDK_CHECKPATCH_PATH' >&2
54         exit 1
55 fi
56
57 total=0
58 status=0
59
60 check () { # <patch> <commit> <title>
61         total=$(($total + 1))
62         ! $verbose || printf '\n### %s\n\n' "$3"
63         if [ -n "$1" ] ; then
64                 report=$($DPDK_CHECKPATCH_PATH $options "$1" 2>/dev/null)
65         elif [ -n "$2" ] ; then
66                 report=$(git format-patch --find-renames --no-stat --stdout -1 $commit |
67                         $DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
68         else
69                 report=$($DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
70         fi
71         [ $? -ne 0 ] || return 0
72         $verbose || printf '\n### %s\n\n' "$3"
73         printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p'
74         status=$(($status + 1))
75 }
76
77 if [ -n "$1" ] ; then
78         for patch in "$@" ; do
79                 # Subject can be on 2 lines
80                 subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$patch")
81                 check "$patch" '' "$subject"
82         done
83 elif [ ! -t 0 ] ; then # stdin
84         subject=$(while read header value ; do
85                 if [ "$header" = 'Subject:' ] ; then
86                         IFS= read next
87                         continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
88                         echo $value$continuation
89                         break
90                 fi
91         done)
92         check '' '' "$subject"
93 else
94         if [ $number -eq 0 ] ; then
95                 commits=$(git rev-list --reverse origin/master..)
96         else
97                 commits=$(git rev-list --reverse --max-count=$number HEAD)
98         fi
99         for commit in $commits ; do
100                 subject=$(git log --format='%s' -1 $commit)
101                 check '' $commit "$subject"
102         done
103 fi
104 pass=$(($total - $status))
105 $quiet || printf '\n%d/%d valid patch' $pass $total
106 $quiet || [ $pass -le 1 ] || printf 'es'
107 $quiet || printf '\n'
108 exit $status