X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=devtools%2Fcheckpatches.sh;fp=devtools%2Fcheckpatches.sh;h=bf3114f954d04c75bd9f31017a47432b4b2f6e10;hb=8d01b9cd70a67cdafd5b965a70420c3bd7fb3f82;hp=ba795ad1dc362c7241b04288c071cd0bb2ba490c;hpb=b63264c8342e6a1b6971c79550d2af2024b6a4de;p=deb_dpdk.git diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index ba795ad1..bf3114f9 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -44,85 +44,12 @@ print_usage () { } check_forbidden_additions() { - # This awk script receives a list of expressions to monitor - # and a list of folders to search these expressions in - # - No search is done inside comments - # - Both additions and removals of the expressions are checked - # A positive balance of additions fails the check - read -d '' awk_script << 'EOF' - BEGIN { - split(FOLDERS,deny_folders," "); - split(EXPRESSIONS,deny_expr," "); - in_file=0; - in_comment=0; - count=0; - comment_start="/*" - comment_end="*/" - } - # search for add/remove instances in current file - # state machine assumes the comments structure is enforced by - # checkpatches.pl - (in_file) { - # comment start - if (index($0,comment_start) > 0) { - in_comment = 1 - } - # non comment code - if (in_comment == 0) { - for (i in deny_expr) { - forbidden_added = "^\+.*" deny_expr[i]; - forbidden_removed="^-.*" deny_expr[i]; - current = expressions[deny_expr[i]] - if ($0 ~ forbidden_added) { - count = count + 1; - expressions[deny_expr[i]] = current + 1 - } - if ($0 ~ forbidden_removed) { - count = count - 1; - expressions[deny_expr[i]] = current - 1 - } - } - } - # comment end - if (index($0,comment_end) > 0) { - in_comment = 0 - } - } - # switch to next file , check if the balance of add/remove - # of previous filehad new additions - ($0 ~ "^\+\+\+ b/") { - in_file = 0; - if (count > 0) { - exit; - } - for (i in deny_folders) { - re = "^\+\+\+ b/" deny_folders[i]; - if ($0 ~ deny_folders[i]) { - in_file = 1 - last_file = $0 - } - } - } - END { - if (count > 0) { - print "Warning in " substr(last_file,6) ":" - print "are you sure you want to add the following:" - for (key in expressions) { - if (expressions[key] > 0) { - print key - } - } - exit RET_ON_FAIL - } - } -EOF - # --------------------------------- # refrain from new additions of rte_panic() and rte_exit() # multiple folders and expressions are separated by spaces awk -v FOLDERS="lib drivers" \ -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \ -v RET_ON_FAIL=1 \ - "$awk_script" - + -f $(dirname $(readlink -e $0))/check-forbidden-tokens.awk - } number=0 @@ -146,28 +73,35 @@ if [ ! -f "$DPDK_CHECKPATCH_PATH" ] || [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then exit 1 fi +print_headline() { # + printf '\n### %s\n\n' "$1" + headline_printed=true +} + total=0 status=0 check () { # <patch> <commit> <title> local ret=0 + headline_printed=false total=$(($total + 1)) - ! $verbose || printf '\n### %s\n\n' "$3" + ! $verbose || print_headline "$3" if [ -n "$1" ] ; then tmpinput=$1 elif [ -n "$2" ] ; then - tmpinput=$(mktemp checkpatches.XXXXXX) + tmpinput=$(mktemp -t dpdk.checkpatches.XXXXXX) git format-patch --find-renames \ --no-stat --stdout -1 $commit > "$tmpinput" else - tmpinput=$(mktemp checkpatches.XXXXXX) + tmpinput=$(mktemp -t dpdk.checkpatches.XXXXXX) cat > "$tmpinput" fi + ! $verbose || printf 'Running checkpatch.pl:\n' report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null) if [ $? -ne 0 ] ; then - $verbose || printf '\n### %s\n\n' "$3" + $headline_printed || print_headline "$3" printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p' ret=1 fi @@ -175,6 +109,7 @@ check () { # <patch> <commit> <title> ! $verbose || printf '\nChecking API additions/removals:\n' report=$($VALIDATE_NEW_API "$tmpinput") if [ $? -ne 0 ] ; then + $headline_printed || print_headline "$3" printf '%s\n' "$report" ret=1 fi @@ -182,6 +117,7 @@ check () { # <patch> <commit> <title> ! $verbose || printf '\nChecking forbidden tokens additions:\n' report=$(check_forbidden_additions <"$tmpinput") if [ $? -ne 0 ] ; then + $headline_printed || print_headline "$3" printf '%s\n' "$report" ret=1 fi