-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathngx-releng
executable file
·248 lines (216 loc) · 7.53 KB
/
ngx-releng
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
DIR=${1:-$PWD}
cd $DIR
README_FILE=(README.*)
if [ -f $README_FILE ]; then
#wiki_file=`perl -e 'print glob "doc/*.wiki"'`
#if [ -n "$wiki_file" -a -f "$wiki_file" ]; then
# echo "Generating $README_FILE"
# (set -x; wiki2markdown.pl $wiki_file > $README_FILE 2>/dev/null || exit 1)
# #wiki2pod.pl $wiki_file > /tmp/a.pod || exit 1
# #pod2text /tmp/a.pod > README || exit 1
#fi
grep -Pzo '(?<=This document describes).*(?:-nginx-module|ngx_\w+)\s*\[v\d+\.\d[^\s\]]*' $README_FILE \
| tr '\n' ' ' \
| ack '(\w+).*?\[v(\S+)' --output '$1 $2'
fi
if [ -d src ]; then
echo "Checking sources in $PWD/src"
find_opts=""
if [ -f .ngx-releng.ignore ]; then
find_opts=`awk '{printf("! -name %s ", $1)}' .ngx-releng.ignore`
fi
cfiles=`find -L src -name 'ngx_*.[ch]' $find_opts`
hfiles=`find -L src -name 'ngx_*.h' $find_opts`
#ack '/\* +' src /dev/null && exit 1
ack '(?<=\#define)\s*DDEBUG\s*[1-9]' src /dev/null
ack '\(\);' $hfiles /dev/null
ack '^\w+[^()]*?\*\s\w+' $hfiles /dev/null
ack '.{81}' $cfiles /dev/null
ack '[ \t]+$' $cfiles /dev/null
ack '(?<!:)//' $cfiles /dev/null
ack '^\s*?\t\s*\S' $cfiles /dev/null
ack '^static .*?\(\);' $cfiles /dev/null
ack '^[a-zA-Z]\w+\(\)$' $cfiles /dev/null
ack '_log_error\(NGX_[^L]' $cfiles /dev/null
ack '^static [^()]*?\*\s\w+' $cfiles /dev/null
ack '^\s*if\s*\([^()]+\)\s*$' $cfiles /dev/null
ack 'if \( |if \(! |if \(.*? \)' $cfiles /dev/null
ack '\b(?:if|for|while|switch)\(|\bdo\{' $cfiles /dev/null
ack '^\#\s*define\s+ngx_[a-z]+_\w+?_version\s+\d+' $cfiles /dev/null
perl -e 'use strict; use warnings;
for my $fname (@ARGV) {
my $func;
open my $in, $fname or die $!;
while (<$in>) {
next if /^\s*$/ || m{^\s*/\*};
if (/^[a-z]\w+\(\S+.*?\) \{$/) {
print "$fname:$.: \e[33m$_\e[0m";
undef $func;
next;
}
if (/^[a-z]\w+\(.*?,$/) {
$func = 1;
next;
}
if ($func && /^ {4}[a-z]\S+.*?,$/) {
next;
}
if ($func && /^ {4}[a-z]\S+.*? \{$/) {
print "$fname:$.: \e[33m$_\e[0m";
undef $func;
next;
}
undef $func;
}
close $in;
}' $cfiles
perl -e 'use strict; use warnings;
for my $fname (@ARGV) {
my $seen;
open my $in, $fname or die $!;
while (<$in>) {
next if /^\s*$/ || m{^\s*/\*};
if (/^ {5,}\S+.*?\)$/) {
$seen = $_;
next;
}
if ($seen && /^\{$/) {
my $ln = $. - 1;
print "$fname:$ln: \e[33m$seen\e[0m";
undef $seen;
next;
}
undef $seen;
}
close $in;
}' $cfiles
perl -e 'use strict; use warnings;
my $seen = 0;
my $saved;
my $indent;
my $supfile = "./ngx-releng.suppress";
my %whitelist;
if (open my $sup, "<$supfile") {
while (<$sup>) {
if (/^(\S+:\d+)$/) {
#warn "loaded rule $1\n";
$whitelist{$1} = 1;
}
}
}
for my $fname (@ARGV) {
open my $in, $fname or die $!;
while (<$in>) {
next if /^\s*$/ || m{^\s*/\*};
if (/ngx_(?:p[cn]*)?alloc\b|\b[mc]alloc\b(?!\.)|\bngx_array_push\b|\bngx_array_create\b|\bngx_alloc_chain_link\b|\bngx_c?alloc_buf\b|\bngx_create_temp_buf\b/) {
my $pattern = $&;
#warn "got pattern: $pattern\n";
if (!/return\b.*?\Q$pattern\E/ && !/"[^"]*\Q$pattern\E/ && !/^\s+\*/) {
if (/^\s+/) {
$indent = $&;
} else {
$indent = "";
}
if (/(\S+)\s*=\s*\Q$pattern\E/) {
#warn "seen var $1\n";
$seen = $1;
} else {
$seen = 1;
}
$saved = $_;
next;
}
}
if ($seen) {
if (/^\s+/) {
if (length($&) > length($indent)) {
next;
}
}
if (($seen ne 1 && !/\bif\b.*?\Q$seen\E\s*==\s*NULL/)
|| ($seen eq 1 && !/\bif\b.*?\s*==\s*NULL/))
{
if (!$whitelist{"$fname:$."}) {
print "missing NULL check: $fname: line $.: $saved$_";
}
}
}
$seen = 0;
}
close $in;
}' $cfiles
perl -e 'use strict; use warnings;
for my $fname (@ARGV) {
my $seen;
open my $in, $fname or die $!;
while (<$in>) {
if (/^[a-z]\w*:$/) {
$seen = $_;
next;
}
if ($seen && !/^$/) {
my $ln = $. - 1;
print "$fname:$ln: \e[33m$seen\e[0m";
undef $seen;
next;
}
undef $seen;
}
close $in;
}' $cfiles
perl -e 'use strict; use warnings;
for my $fname (@ARGV) {
my $seen;
open my $in, $fname or die $!;
while (<$in>) {
if (/^ngx_\w+?_create_(loc|srv|main)_conf\s*\(/) {
$seen = 1;
next;
}
if ($seen && /\breturn\s+NGX_CONF_ERROR/) {
my $ln = $.;
$seen = $_;
print "$fname:$ln: \e[33m$seen\e[0m";
next;
}
if (/^}$/) {
undef $seen;
}
}
close $in;
}' $cfiles
perl -e '
use strict; use warnings;
my $line_cont;
for my $fname (@ARGV) {
open my $in, $fname or die $!;
while (<$in>) {
if (m{^ ( \# \s* [a-z]\w* .* ) (\\ \s*) $}x) {
$line_cont = 1;
if (length $1 != 77) {
print "$fname:$.: \e[33m$1\e[0m$2";
next;
}
} elsif (m{^ (\s+ .* ) (\\ \s*) $}x) {
if (!$line_cont) {
print "$fname:$.: $_";
}
if (length $1 != 77) {
print "$fname:$.: \e[33m$1\e[0m$2";
next;
}
}
}
close $in;
}' $cfiles
ngx-style.pl $cfiles
fi
if [ -d src ]; then
echo "Checking tests in $PWD/t"
tfiles=`find -L t -name '*.t'`
ack -l '\r\n' $tfiles /dev/null
ack '=== TEST \d+\s+' $tfiles /dev/null
ack '\--- *(?:ONLY|LAST)' $tfiles /dev/null
ack '^\s*plan\s+tests\s*=>.*?repeat_each\(\d+\)' $tfiles /dev/null
fi