Debian Codegraph @

util/lua-releng

raw
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 sub file_contains ($$);
7
8 my $version;
9 for my $file (map glob, qw{ *.lua lib/*.lua lib/*/*.lua lib/*/*/*.lua lib/*/*/*/*.lua lib/*/*/*/*/*.lua }) {
10 # Check the sanity of each .lua file
11 open my $in, $file or
12 die "ERROR: Can't open $file for reading: $!\n";
13 my $found_ver;
14 while (<$in>) {
15 my ($ver, $skipping);
16 if (/(?x) (?:_VERSION) \s* = .*? ([\d\.]*\d+) (.*? SKIP)?/) {
17 my $orig_ver = $ver = $1;
18 $found_ver = 1;
19 # $skipping = $2;
20 $ver =~ s{^(\d+)\.(\d{3})(\d{3})$}{join '.', int($1), int($2), int($3)}e;
21 warn "$file: $orig_ver ($ver)\n";
22
23 } elsif (/(?x) (?:_VERSION) \s* = \s* ([a-zA-Z_]\S*)/) {
24 warn "$file: $1\n";
25 $found_ver = 1;
26 last;
27 }
28
29 if ($ver and $version and !$skipping) {
30 if ($version ne $ver) {
31 # die "$file: $ver != $version\n";
32 }
33 } elsif ($ver and !$version) {
34 $version = $ver;
35 }
36 }
37 if (!$found_ver) {
38 warn "WARNING: No \"_VERSION\" or \"version\" field found in `$file`.\n";
39 }
40 close $in;
41
42 #print "Checking use of Lua global variables in file $file ...\n";
43 system("luac5.1 -p -l $file | grep ETGLOBAL | grep -vE '(require|type|tostring|error|ngx|ndk|jit|setmetatable|getmetatable|string|table|io|os|print|tonumber|math|pcall|xpcall|unpack|pairs|ipairs|assert|module|package|coroutine|[gs]etfenv|next|select|rawset|rawget|debug)\$'");
44 #file_contains($file, "attempt to write to undeclared variable");
45 system("grep -H -n -E --color '.{120}' $file");
46 }
47
48 sub file_contains ($$) {
49 my ($file, $regex) = @_;
50 open my $in, $file
51 or die "Cannot open $file fo reading: $!\n";
52 my $content = do { local $/; <$in> };
53 close $in;
54 #print "$content";
55 return scalar ($content =~ /$regex/);
56 }
57
58 if (-d 't') {
59 for my $file (map glob, qw{ t/*.t t/*/*.t t/*/*/*.t }) {
60 system(qq{grep -H -n --color -E '\\--- ?(ONLY|LAST)' $file});
61 }
62 }
63