buildtools: make experimental symbol check lighter
[dpdk.git] / devtools / check-forbidden-tokens.awk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2018 Arnon Warshavsky <arnon@qwilt.com>
3
4 # This awk script receives a list of expressions to monitor
5 # and a list of folders to search these expressions in
6 # - No search is done inside comments
7 # - Both additions and removals of the expressions are checked
8 #   A positive balance of additions fails the check
9
10 BEGIN {
11         split(FOLDERS,deny_folders," ");
12         split(EXPRESSIONS,deny_expr," ");
13         in_file=0;
14         in_comment=0;
15         count=0;
16         comment_start="/*"
17         comment_end="*/"
18 }
19 # search for add/remove instances in current file
20 # state machine assumes the comments structure is enforced by
21 # checkpatches.pl
22 (in_file) {
23         # comment start
24         if (index($0,comment_start) > 0) {
25                 in_comment = 1
26         }
27         # non comment code
28         if (in_comment == 0) {
29                 for (i in deny_expr) {
30                         forbidden_added = "^\\+.*" deny_expr[i];
31                         forbidden_removed="^-.*" deny_expr[i];
32                         current = expressions[deny_expr[i]]
33                         if ($0 ~ forbidden_added) {
34                                 count = count + 1;
35                                 expressions[deny_expr[i]] = current + 1
36                         }
37                         if ($0 ~ forbidden_removed) {
38                                 count = count - 1;
39                                 expressions[deny_expr[i]] = current - 1
40                         }
41                 }
42         }
43         # comment end
44         if (index($0,comment_end) > 0) {
45                 in_comment = 0
46         }
47 }
48 # switch to next file , check if the balance of add/remove
49 # of previous filehad new additions
50 ($0 ~ "^\\+\\+\\+ b/") {
51         in_file = 0;
52         if (count > 0) {
53                 exit;
54         }
55         for (i in deny_folders) {
56                 re = "^\\+\\+\\+ b/" deny_folders[i];
57                 if ($0 ~ deny_folders[i]) {
58                         in_file = 1
59                         last_file = $0
60                 }
61         }
62 }
63 END {
64         if (count > 0) {
65                 print "Warning in " substr(last_file,6) ":"
66                 print MESSAGE
67                 exit RET_ON_FAIL
68         }
69 }