2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
6 # - DPDK_CHECKPATCH_PATH
7 # - DPDK_CHECKPATCH_CODESPELL
8 # - DPDK_CHECKPATCH_LINE_LENGTH
9 # - DPDK_CHECKPATCH_OPTIONS
10 . $(dirname $(readlink -f $0))/load-devel-config
12 VALIDATE_NEW_API=$(dirname $(readlink -f $0))/check-symbol-change.sh
14 # Enable codespell by default. This can be overwritten from a config file.
15 # Codespell can also be enabled by setting DPDK_CHECKPATCH_CODESPELL to a valid path
16 # to a dictionary.txt file if dictionary.txt is not in the default location.
17 codespell=${DPDK_CHECKPATCH_CODESPELL:-enable}
18 length=${DPDK_CHECKPATCH_LINE_LENGTH:-80}
20 # override default Linux options
22 if [ "$codespell" = "enable" ] ; then
23 options="$options --codespell"
24 elif [ -f "$codespell" ] ; then
25 options="$options --codespell"
26 options="$options --codespellfile $codespell"
28 options="$options --max-line-length=$length"
29 options="$options --show-types"
30 options="$options --ignore=LINUX_VERSION_CODE,\
31 FILE_PATH_CHANGES,MAINTAINERS_STYLE,SPDX_LICENSE_TAG,\
32 VOLATILE,PREFER_PACKED,PREFER_ALIGNED,PREFER_PRINTF,\
33 PREFER_KERNEL_TYPES,BIT_MACRO,CONST_STRUCT,\
34 SPLIT_STRING,LONG_LINE_STRING,C99_COMMENT_TOLERANCE,\
35 LINE_SPACING,PARENTHESIS_ALIGNMENT,NETWORKING_BLOCK_COMMENT_STYLE,\
36 NEW_TYPEDEFS,COMPARISON_TO_NULL"
37 options="$options $DPDK_CHECKPATCH_OPTIONS"
41 usage: $(basename $0) [-q] [-v] [-nX|-r range|patch1 [patch2] ...]]
43 Run Linux kernel checkpatch.pl with DPDK options.
44 The environment variable DPDK_CHECKPATCH_PATH must be set.
46 The patches to check can be from stdin, files specified on the command line,
47 latest git commits limited with -n option, or commits in the git range
48 specified with -r option (default: "origin/master..").
52 check_forbidden_additions() { # <patch>
55 # refrain from new additions of rte_panic() and rte_exit()
56 # multiple folders and expressions are separated by spaces
57 awk -v FOLDERS="lib drivers" \
58 -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
60 -v MESSAGE='Using rte_panic/rte_exit' \
61 -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
64 # refrain from using compiler attribute without defining a common macro
65 awk -v FOLDERS="lib drivers app examples" \
66 -v EXPRESSIONS="__attribute__" \
68 -v MESSAGE='Using compiler attribute directly' \
69 -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
72 # svg figures must be included with wildcard extension
73 # because of png conversion for pdf docs
74 awk -v FOLDERS='doc' \
75 -v EXPRESSIONS='::[[:space:]]*[^[:space:]]*\\.svg' \
77 -v MESSAGE='Using explicit .svg extension instead of .*' \
78 -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
84 check_experimental_tags() { # <patch>
95 /^+.*__rte_experimental/ {
96 if (current_file ~ ".c$" ) {
97 print "Please only put __rte_experimental tags in " \
98 "headers ("current_file")";
101 if ($1 != "+__rte_experimental" || $2 != "") {
102 print "__rte_experimental must appear alone on the line" \
103 " immediately preceding the return type of a function."
114 check_internal_tags() { # <patch>
125 /^+.*__rte_internal/ {
126 if (current_file ~ ".c$" ) {
127 print "Please only put __rte_internal tags in " \
128 "headers ("current_file")";
131 if ($1 != "+__rte_internal" || $2 != "") {
132 print "__rte_internal must appear alone on the line" \
133 " immediately preceding the return type of" \
146 range='origin/master..'
149 while getopts hn:qr:v ARG ; do
151 n ) number=$OPTARG ;;
155 h ) print_usage ; exit 0 ;;
156 ? ) print_usage ; exit 1 ;;
159 shift $(($OPTIND - 1))
161 if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
164 echo 'Cannot execute DPDK_CHECKPATCH_PATH' >&2
168 print_headline() { # <title>
169 printf '\n### %s\n\n' "$1"
170 headline_printed=true
176 check () { # <patch> <commit> <title>
178 headline_printed=false
180 total=$(($total + 1))
181 ! $verbose || print_headline "$3"
182 if [ -n "$1" ] ; then
185 tmpinput=$(mktemp -t dpdk.checkpatches.XXXXXX)
186 trap "rm -f '$tmpinput'" INT
188 if [ -n "$2" ] ; then
189 git format-patch --find-renames \
190 --no-stat --stdout -1 $commit > "$tmpinput"
196 ! $verbose || printf 'Running checkpatch.pl:\n'
197 report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null)
198 if [ $? -ne 0 ] ; then
199 $headline_printed || print_headline "$3"
200 printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p'
204 ! $verbose || printf '\nChecking API additions/removals:\n'
205 report=$($VALIDATE_NEW_API "$tmpinput")
206 if [ $? -ne 0 ] ; then
207 $headline_printed || print_headline "$3"
208 printf '%s\n' "$report"
212 ! $verbose || printf '\nChecking forbidden tokens additions:\n'
213 report=$(check_forbidden_additions "$tmpinput")
214 if [ $? -ne 0 ] ; then
215 $headline_printed || print_headline "$3"
216 printf '%s\n' "$report"
220 ! $verbose || printf '\nChecking __rte_experimental tags:\n'
221 report=$(check_experimental_tags "$tmpinput")
222 if [ $? -ne 0 ] ; then
223 $headline_printed || print_headline "$3"
224 printf '%s\n' "$report"
228 ! $verbose || printf '\nChecking __rte_internal tags:\n'
229 report=$(check_internal_tags "$tmpinput")
230 if [ $? -ne 0 ] ; then
231 $headline_printed || print_headline "$3"
232 printf '%s\n' "$report"
236 if [ "$tmpinput" != "$1" ]; then
240 [ $ret -eq 0 ] && return 0
242 status=$(($status + 1))
245 if [ -n "$1" ] ; then
246 for patch in "$@" ; do
247 # Subject can be on 2 lines
248 subject=$(sed '/^Subject: */!d;s///;N;s,\n[[:space:]]\+, ,;s,\n.*,,;q' "$patch")
249 check "$patch" '' "$subject"
251 elif [ ! -t 0 ] ; then # stdin
252 subject=$(while read header value ; do
253 if [ "$header" = 'Subject:' ] ; then
255 continuation=$(echo "$next" | sed -n 's,^[[:space:]]\+, ,p')
256 echo $value$continuation
260 check '' '' "$subject"
262 if [ $number -eq 0 ] ; then
263 commits=$(git rev-list --reverse $range)
265 commits=$(git rev-list --reverse --max-count=$number HEAD)
267 for commit in $commits ; do
268 subject=$(git log --format='%s' -1 $commit)
269 check '' $commit "$subject"
272 pass=$(($total - $status))
273 $quiet || printf '\n%d/%d valid patch' $pass $total
274 $quiet || [ $pass -le 1 ] || printf 'es'
275 $quiet || printf '\n'