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 # This awk script receives a list of expressions to monitor
48 # and a list of folders to search these expressions in
49 # - No search is done inside comments
50 # - Both additions and removals of the expressions are checked
51 # A positive balance of additions fails the check
52 read -d '' awk_script << 'EOF'
54 split(FOLDERS,deny_folders," ");
55 split(EXPRESSIONS,deny_expr," ");
62 # search for add/remove instances in current file
63 # state machine assumes the comments structure is enforced by
67 if (index($0,comment_start) > 0) {
71 if (in_comment == 0) {
72 for (i in deny_expr) {
73 forbidden_added = "^\+.*" deny_expr[i];
74 forbidden_removed="^-.*" deny_expr[i];
75 current = expressions[deny_expr[i]]
76 if ($0 ~ forbidden_added) {
78 expressions[deny_expr[i]] = current + 1
80 if ($0 ~ forbidden_removed) {
82 expressions[deny_expr[i]] = current - 1
87 if (index($0,comment_end) > 0) {
91 # switch to next file , check if the balance of add/remove
92 # of previous filehad new additions
98 for (i in deny_folders) {
99 re = "^\+\+\+ b/" deny_folders[i];
100 if ($0 ~ deny_folders[i]) {
108 print "Warning in " substr(last_file,6) ":"
109 print "are you sure you want to add the following:"
110 for (key in expressions) {
111 if (expressions[key] > 0) {
119 # ---------------------------------
120 # refrain from new additions of rte_panic() and rte_exit()
121 # multiple folders and expressions are separated by spaces
122 awk -v FOLDERS="lib drivers" \
123 -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
131 while getopts hn:qv ARG ; do
133 n ) number=$OPTARG ;;
136 h ) print_usage ; exit 0 ;;
137 ? ) print_usage ; exit 1 ;;
140 shift $(($OPTIND - 1))
142 if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
145 echo 'Cannot execute DPDK_CHECKPATCH_PATH' >&2
152 check () { # <patch> <commit> <title>
155 total=$(($total + 1))
156 ! $verbose || printf '\n### %s\n\n' "$3"
157 if [ -n "$1" ] ; then
159 elif [ -n "$2" ] ; then
160 tmpinput=$(mktemp checkpatches.XXXXXX)
161 git format-patch --find-renames \
162 --no-stat --stdout -1 $commit > "$tmpinput"
164 tmpinput=$(mktemp checkpatches.XXXXXX)
168 report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null)
169 if [ $? -ne 0 ] ; then
170 $verbose || printf '\n### %s\n\n' "$3"
171 printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p'
175 ! $verbose || printf '\nChecking API additions/removals:\n'
176 report=$($VALIDATE_NEW_API "$tmpinput")
177 if [ $? -ne 0 ] ; then
178 printf '%s\n' "$report"
182 ! $verbose || printf '\nChecking forbidden tokens additions:\n'
183 report=$(check_forbidden_additions <"$tmpinput")
184 if [ $? -ne 0 ] ; then
185 printf '%s\n' "$report"
190 [ $ret -eq 0 ] && return 0
192 status=$(($status + 1))
195 if [ -n "$1" ] ; then
196 for patch in "$@" ; do
197 # Subject can be on 2 lines
198 subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$patch")
199 check "$patch" '' "$subject"
201 elif [ ! -t 0 ] ; then # stdin
202 subject=$(while read header value ; do
203 if [ "$header" = 'Subject:' ] ; then
205 continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
206 echo $value$continuation
210 check '' '' "$subject"
212 if [ $number -eq 0 ] ; then
213 commits=$(git rev-list --reverse origin/master..)
215 commits=$(git rev-list --reverse --max-count=$number HEAD)
217 for commit in $commits ; do
218 subject=$(git log --format='%s' -1 $commit)
219 check '' $commit "$subject"
222 pass=$(($total - $status))
223 $quiet || printf '\n%d/%d valid patch' $pass $total
224 $quiet || [ $pass -le 1 ] || printf 'es'
225 $quiet || printf '\n'