X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=devtools%2Fcheckpatches.sh;h=ba795ad1dc362c7241b04288c071cd0bb2ba490c;hb=c4ea98c42da7d2e4f990d2cca291f6415b57ed9f;hp=1439bce94fa2768ae71ce326c56a83eb212d630a;hpb=4bec48184e33893a9530a451e5a053d723a88769;p=dpdk.git diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 1439bce94f..ba795ad1dc 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -25,11 +25,11 @@ NEW_TYPEDEFS,COMPARISON_TO_NULL" clean_tmp_files() { if echo $tmpinput | grep -q '^checkpatches\.' ; then - rm -f $tmpinput + rm -f "$tmpinput" fi } -trap "clean_tmp_files" SIGINT +trap "clean_tmp_files" INT print_usage () { cat <<- END_OF_HELP @@ -43,6 +43,88 @@ print_usage () { END_OF_HELP } +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" - +} + number=0 quiet=false verbose=false @@ -77,13 +159,13 @@ check () { # elif [ -n "$2" ] ; then tmpinput=$(mktemp checkpatches.XXXXXX) git format-patch --find-renames \ - --no-stat --stdout -1 $commit > $tmpinput + --no-stat --stdout -1 $commit > "$tmpinput" else tmpinput=$(mktemp checkpatches.XXXXXX) - cat > $tmpinput + cat > "$tmpinput" fi - report=$($DPDK_CHECKPATCH_PATH $options $tmpinput 2>/dev/null) + report=$($DPDK_CHECKPATCH_PATH $options "$tmpinput" 2>/dev/null) if [ $? -ne 0 ] ; then $verbose || printf '\n### %s\n\n' "$3" printf '%s\n' "$report" | sed -n '1,/^total:.*lines checked$/p' @@ -97,6 +179,13 @@ check () { # <patch> <commit> <title> ret=1 fi + ! $verbose || printf '\nChecking forbidden tokens additions:\n' + report=$(check_forbidden_additions <"$tmpinput") + if [ $? -ne 0 ] ; then + printf '%s\n' "$report" + ret=1 + fi + clean_tmp_files [ $ret -eq 0 ] && return 0