From patchwork Thu Sep 20 21:11:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnon Warshavsky X-Patchwork-Id: 45059 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 805CD5F13; Thu, 20 Sep 2018 23:12:10 +0200 (CEST) Received: from mta.qwilt.com (mta.qwilt.com [52.9.191.255]) by dpdk.org (Postfix) with ESMTP id CD30E5B3C for ; Thu, 20 Sep 2018 23:12:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mta.qwilt.com (Postfix) with ESMTP id 02572806A3E; Thu, 20 Sep 2018 21:12:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at qwilt.com Received: from mta.qwilt.com ([127.0.0.1]) by localhost (mta.qwilt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sHckDd2556wV; Thu, 20 Sep 2018 21:12:06 +0000 (UTC) Received: from rd01.it.qwilt.com.qwilt.com (80.179.204.39.cable.012.net.il [80.179.204.39]) by mta.qwilt.com (Postfix) with ESMTPSA id 0CABB806A1D; Thu, 20 Sep 2018 21:12:04 +0000 (UTC) From: Arnon Warshavsky To: amo@semihalf.com, i.maximets@samsung.com, thomas@monjalon.net, stephen@networkplumber.org, david.marchand@6wind.com Cc: dev@dpdk.org, arnon@qwilt.com Date: Fri, 21 Sep 2018 00:11:40 +0300 Message-Id: <1537477900-32682-1-git-send-email-arnon@qwilt.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH] devtools: move forbidden tokens awk script to a separate file X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The awk code previously read inline in checkpatches.pl 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 --- devtools/check-forbidden-tokens.awk | 68 +++++++++++++++++++++++++++++++++ devtools/checkpatches.sh | 75 +------------------------------------ 2 files changed, 69 insertions(+), 74 deletions(-) create mode 100755 devtools/check-forbidden-tokens.awk diff --git a/devtools/check-forbidden-tokens.awk b/devtools/check-forbidden-tokens.awk new file mode 100755 index 0000000..f4f38e3 --- /dev/null +++ b/devtools/check-forbidden-tokens.awk @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2018 Arnon Warshavsky + +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 ba795ad..18e474f 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