2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
6 # - DPDK_CHECKPATCH_PATH
7 # - DPDK_CHECKPATCH_LINE_LENGTH
8 . $(dirname $(readlink -e $0))/load-devel-config
10 length=${DPDK_CHECKPATCH_LINE_LENGTH:-80}
12 # override default Linux options
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"
26 usage: $(basename $0) [-q] [-v] [-nX|patch1 [patch2] ...]]
28 Run Linux kernel checkpatch.pl with DPDK options.
29 The environment variable DPDK_CHECKPATCH_PATH must be set.
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).
39 while getopts hn:qv ARG ; do
44 h ) print_usage ; exit 0 ;;
45 ? ) print_usage ; exit 1 ;;
48 shift $(($OPTIND - 1))
50 if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
53 echo 'Cannot execute DPDK_CHECKPATCH_PATH' >&2
60 check () { # <patch> <commit> <title>
62 ! $verbose || printf '\n### %s\n\n' "$3"
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)
69 report=$($DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
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))
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"
83 elif [ ! -t 0 ] ; then # stdin
84 subject=$(while read header value ; do
85 if [ "$header" = 'Subject:' ] ; then
87 continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
88 echo $value$continuation
92 check '' '' "$subject"
94 if [ $number -eq 0 ] ; then
95 commits=$(git rev-list --reverse origin/master..)
97 commits=$(git rev-list --reverse --max-count=$number HEAD)
99 for commit in $commits ; do
100 subject=$(git log --format='%s' -1 $commit)
101 check '' $commit "$subject"
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'