1 | #!perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my %dirOf = (); |
---|
7 | my $arbhome = undef; |
---|
8 | |
---|
9 | sub lookForScripts($\@\@); |
---|
10 | sub lookForScripts($\@\@) { |
---|
11 | my ($dir,$scripts_r,$modules_r) = @_; |
---|
12 | my @subdirs = (); |
---|
13 | |
---|
14 | opendir(DIR,$dir) || die "can't read directory '$dir' (Reason: $!)"; |
---|
15 | foreach (readdir(DIR)) { |
---|
16 | if ($_ ne '.' and $_ ne '..') { |
---|
17 | my $full = $dir.'/'.$_; |
---|
18 | if (-d $full) { |
---|
19 | push @subdirs, $full; |
---|
20 | } |
---|
21 | elsif (/\.(pl|amc)$/io) { push @$scripts_r, $full; $dirOf{$_} = $dir; } |
---|
22 | elsif (/\.pm$/io) { push @$modules_r, $full; $dirOf{$_} = $dir; } |
---|
23 | } |
---|
24 | } |
---|
25 | closedir(DIR); |
---|
26 | foreach (@subdirs) { |
---|
27 | lookForScripts($_,@$scripts_r,@$modules_r); |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | sub convertErrors($) { |
---|
32 | my ($lines) = @_; |
---|
33 | my @lines = split("\n",$lines); |
---|
34 | my $seen_error = 0; |
---|
35 | my @out = (); |
---|
36 | foreach (@lines) { |
---|
37 | if (/ at (.*) line ([0-9]+)/o) { |
---|
38 | my ($err,$name,$line,$rest) = ($`,$1,$2,$'); |
---|
39 | my $full = $dirOf{$name}; |
---|
40 | if (defined $full) { |
---|
41 | $full .= '/'.$name; |
---|
42 | } |
---|
43 | else { |
---|
44 | $full = $name; |
---|
45 | } |
---|
46 | |
---|
47 | my $msg = $full.':'.$line.': '.$err.$rest; |
---|
48 | push @out, $msg; |
---|
49 | $seen_error = 1; |
---|
50 | } |
---|
51 | else { |
---|
52 | push @out, $_; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | if ($seen_error==1) { |
---|
57 | print " FAILED\n"; |
---|
58 | foreach (@out) { print $_."\n"; } |
---|
59 | } |
---|
60 | else { |
---|
61 | print " OK" |
---|
62 | } |
---|
63 | return $seen_error; |
---|
64 | } |
---|
65 | |
---|
66 | sub splitDirName($) { |
---|
67 | my ($file) = @_; |
---|
68 | if ($file =~ /\/([^\/]+)$/o) { |
---|
69 | my ($dir,$name) = ($`,$1); |
---|
70 | return ($dir,$name); |
---|
71 | } |
---|
72 | die "can't split '$file'"; |
---|
73 | } |
---|
74 | |
---|
75 | sub test_script($$) { |
---|
76 | my ($script,$isModule) = @_; |
---|
77 | |
---|
78 | my ($dir,$name) = splitDirName($script); |
---|
79 | if (not chdir($dir)) { die "can't cd to '$dir' (Reason: $!)"; } |
---|
80 | |
---|
81 | my @tests = ( |
---|
82 | '-c', |
---|
83 | '-MO=LintSubs', |
---|
84 | '-MO=Lint,no-regexp-variables', |
---|
85 | ); |
---|
86 | |
---|
87 | print "Testing $name"; |
---|
88 | foreach (@tests) { |
---|
89 | if ($isModule) { $_ = '-I'.$arbhome.'/lib '.$_; } |
---|
90 | my $test = 'perl '.$_.' '.$name.' 2>&1'; |
---|
91 | # print "\ntest='$test'\n"; |
---|
92 | my $result = `$test`; |
---|
93 | if (convertErrors($result)) { |
---|
94 | return 0; |
---|
95 | } |
---|
96 | } |
---|
97 | print "\n"; |
---|
98 | return 1; |
---|
99 | } |
---|
100 | |
---|
101 | sub main() { |
---|
102 | $arbhome = $ENV{ARBHOME}; |
---|
103 | if (not defined $arbhome) { die "ARBHOME undefined"; } |
---|
104 | |
---|
105 | my $script_root = $ENV{ARBHOME}.'/PERL_SCRIPTS'; |
---|
106 | my $macros_root = $ENV{ARBHOME}.'/lib/macros'; |
---|
107 | if (not -d $script_root) { die "No such directory '$script_root'"; } |
---|
108 | if (not -d $macros_root) { die "No such directory '$macros_root'"; } |
---|
109 | |
---|
110 | my @scripts = (); |
---|
111 | my @modules = (); |
---|
112 | lookForScripts($script_root,@scripts,@modules); |
---|
113 | lookForScripts($macros_root,@scripts,@modules); |
---|
114 | |
---|
115 | # print "Existing perl scripts:\n"; |
---|
116 | # foreach (@scripts) { print "- '$_'\n"; } |
---|
117 | |
---|
118 | my $failed = 0; |
---|
119 | foreach (@modules) { if (test_script($_,1)==0) { $failed++; } } |
---|
120 | foreach (@scripts) { if (test_script($_,0)==0) { $failed++; } } |
---|
121 | |
---|
122 | if ($failed>0) { |
---|
123 | die "$failed perl scripts failed to compile\n"; |
---|
124 | } |
---|
125 | } |
---|
126 | main(); |
---|