From: Arnon Warshavsky Date: Thu, 27 Sep 2018 09:04:08 +0000 (+0300) Subject: devtools: move awk script ckecking forbidden tokens X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=42f4d724ec27ffb4f512713cfb83cfc645086571 devtools: move awk script ckecking forbidden tokens The awk code previously read inline in checkpatches.sh was using -d which is a bash option, while bash is not the default shell in all distributions. Now moved to be read from a separate file. Signed-off-by: Arnon Warshavsky Acked-by: Andrzej Ostruszka --- diff --git a/MAINTAINERS b/MAINTAINERS index 5967c1dd30..87993a3f4c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -81,6 +81,7 @@ M: Thomas Monjalon F: MAINTAINERS F: devtools/check-dup-includes.sh F: devtools/check-maintainers.sh +F: devtools/check-forbidden-tokens.awk F: devtools/check-git-log.sh F: devtools/check-includes.sh F: devtools/check-symbol-maps.sh diff --git a/devtools/check-forbidden-tokens.awk b/devtools/check-forbidden-tokens.awk new file mode 100755 index 0000000000..fd77cdd87c --- /dev/null +++ b/devtools/check-forbidden-tokens.awk @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2018 Arnon Warshavsky + +# 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 + +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 + } +} diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index ba795ad1dc..18e474f9d1 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