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 VALIDATE_NEW_API=$(dirname $(readlink -e $0))/check-symbol-change.sh
12 length=${DPDK_CHECKPATCH_LINE_LENGTH:-80}
14 # override default Linux options
16 options="$options --max-line-length=$length"
17 options="$options --show-types"
18 options="$options --ignore=LINUX_VERSION_CODE,\
19 FILE_PATH_CHANGES,MAINTAINERS_STYLE,SPDX_LICENSE_TAG,\
20 VOLATILE,PREFER_PACKED,PREFER_ALIGNED,PREFER_PRINTF,\
21 PREFER_KERNEL_TYPES,BIT_MACRO,CONST_STRUCT,\
22 SPLIT_STRING,LONG_LINE_STRING,\
23 LINE_SPACING,PARENTHESIS_ALIGNMENT,NETWORKING_BLOCK_COMMENT_STYLE,\
24 NEW_TYPEDEFS,COMPARISON_TO_NULL"
27 if echo $tmpinput | grep -q '^checkpatches\.' ; then
32 trap "clean_tmp_files" INT
36 usage: $(basename $0) [-q] [-v] [-nX|patch1 [patch2] ...]]
38 Run Linux kernel checkpatch.pl with DPDK options.
39 The environment variable DPDK_CHECKPATCH_PATH must be set.
41 The patches to check can be from stdin, files specified on the command line,
42 or latest git commits limited with -n option (default limit: origin/master).
46 check_forbidden_additions() {
47 # refrain from new additions of rte_panic() and rte_exit()
48 # multiple folders and expressions are separated by spaces
49 awk -v FOLDERS="lib drivers" \
50 -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
52 -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk -
58 while getopts hn:qv ARG ; do
63 h ) print_usage ; exit 0 ;;
64 ? ) print_usage ; exit 1 ;;
67 shift $(($OPTIND - 1))
69 if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
72 echo 'Cannot execute DPDK_CHECKPATCH_PATH' >&2
79 check () { # <patch> <commit> <title>
83 ! $verbose || printf '\n### %s\n\n' "$3"
86 elif [ -n "$2" ] ; then
87 tmpinput=$(mktemp checkpatches.XXXXXX)
88 git format-patch --find-renames \
89 --no-stat --stdout -1 $commit > "$tmpinput"
91 tmpinput=$(mktemp checkpatches.XXXXXX)
95 report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null)
96 if [ $? -ne 0 ] ; then
97 $verbose || printf '\n### %s\n\n' "$3"
98 printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p'
102 ! $verbose || printf '\nChecking API additions/removals:\n'
103 report=$($VALIDATE_NEW_API "$tmpinput")
104 if [ $? -ne 0 ] ; then
105 printf '%s\n' "$report"
109 ! $verbose || printf '\nChecking forbidden tokens additions:\n'
110 report=$(check_forbidden_additions <"$tmpinput")
111 if [ $? -ne 0 ] ; then
112 printf '%s\n' "$report"
117 [ $ret -eq 0 ] && return 0
119 status=$(($status + 1))
122 if [ -n "$1" ] ; then
123 for patch in "$@" ; do
124 # Subject can be on 2 lines
125 subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$patch")
126 check "$patch" '' "$subject"
128 elif [ ! -t 0 ] ; then # stdin
129 subject=$(while read header value ; do
130 if [ "$header" = 'Subject:' ] ; then
132 continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
133 echo $value$continuation
137 check '' '' "$subject"
139 if [ $number -eq 0 ] ; then
140 commits=$(git rev-list --reverse origin/master..)
142 commits=$(git rev-list --reverse --max-count=$number HEAD)
144 for commit in $commits ; do
145 subject=$(git log --format='%s' -1 $commit)
146 check '' $commit "$subject"
149 pass=$(($total - $status))
150 $quiet || printf '\n%d/%d valid patch' $pass $total
151 $quiet || [ $pass -le 1 ] || printf 'es'
152 $quiet || printf '\n'