Commit | Line | Data |
---|---|---|
cdf8b154 PK |
1 | #!/usr/local/bin/perl |
2 | ||
3 | use Config; | |
4 | use File::Basename; | |
5 | use Cwd; | |
6 | ||
7 | # List explicitly here the variables you want Configure to | |
8 | # generate. Metaconfig only looks for shell variables, so you | |
9 | # have to mention them as if they were shell variables, not | |
10 | # %Config entries: | |
11 | # $startperl | |
12 | # $perlpath | |
13 | # $eunicefix | |
14 | ||
15 | # This forces PL files to create target in same directory as PL file. | |
16 | # This is so that make depend always knows where to find PL derivatives. | |
345d73cf | 17 | my $origdir = cwd; |
cdf8b154 | 18 | chdir dirname($0); |
345d73cf | 19 | my $file = basename($0, '.PL'); |
cdf8b154 PK |
20 | $file .= '.com' if $^O eq 'VMS'; |
21 | ||
22 | # Create output file. | |
23 | open OUT,">$file" or die "Can't create $file: $!"; | |
24 | ||
25 | print "Extracting $file (with variable substitutions)\n"; | |
26 | ||
27 | # In this section, perl variables will be expanded during extraction. | |
28 | # You can use $Config{...} to use Configure variables. | |
29 | ||
30 | print OUT <<"!GROK!THIS!"; | |
31 | $Config{'startperl'} | |
32 | eval 'exec $Config{'perlpath'} -S \$0 \${1+"\$@"}' | |
33 | if \$running_under_some_shell; | |
34 | !GROK!THIS! | |
35 | ||
eddad28d RGS |
36 | print OUT "\n# perlivp $^V\n"; |
37 | ||
cdf8b154 PK |
38 | # In the following, perl variables are not expanded during extraction. |
39 | ||
40 | print OUT <<'!NO!SUBS!'; | |
41 | ||
cdf8b154 PK |
42 | sub usage { |
43 | warn "@_\n" if @_; | |
44 | print << " EOUSAGE"; | |
45 | Usage: | |
46 | ||
d08226e4 | 47 | $0 [-p] [-v] | [-h] |
cdf8b154 PK |
48 | |
49 | -p Print a preface before each test telling what it will test. | |
50 | -v Verbose mode in which extra information about test results | |
51 | is printed. Test failures always print out some extra information | |
52 | regardless of whether or not this switch is set. | |
53 | -h Prints this help message. | |
54 | EOUSAGE | |
55 | exit; | |
56 | } | |
57 | ||
345d73cf | 58 | use vars qw(%opt); # allow testing with older versions (do not use our) |
cdf8b154 PK |
59 | |
60 | @opt{ qw/? H h P p V v/ } = qw(0 0 0 0 0 0 0); | |
61 | ||
62 | while ($ARGV[0] =~ /^-/) { | |
63 | $ARGV[0] =~ s/^-//; | |
64 | for my $flag (split(//,$ARGV[0])) { | |
65 | usage() if '?' =~ /\Q$flag/; | |
66 | usage() if 'h' =~ /\Q$flag/; | |
67 | usage() if 'H' =~ /\Q$flag/; | |
28fb188d JK |
68 | usage("unknown flag: '$flag'") unless 'HhPpVv' =~ /\Q$flag/; |
69 | warn "$0: '$flag' flag already set\n" if $opt{$flag}++; | |
cdf8b154 PK |
70 | } |
71 | shift; | |
72 | } | |
73 | ||
74 | $opt{p}++ if $opt{P}; | |
75 | $opt{v}++ if $opt{V}; | |
76 | ||
77 | my $pass__total = 0; | |
78 | my $error_total = 0; | |
79 | my $tests_total = 0; | |
80 | ||
81 | !NO!SUBS! | |
82 | ||
28fb188d | 83 | # We cannot merely check the variable '$^X' in general since on many |
cdf8b154 PK |
84 | # Unixes it is the basename rather than the full path to the perl binary. |
85 | my $perlpath = ''; | |
86 | if (defined($Config{'perlpath'})) { $perlpath = $Config{'perlpath'}; } | |
cdf8b154 | 87 | |
345d73cf PP |
88 | # The useithreads Config variable plays a role in whether or not |
89 | # threads and threads/shared work when C<use>d. They apparently always | |
90 | # get installed on systems that can run Configure. | |
91 | my $useithreads = ''; | |
92 | if (defined($Config{'useithreads'})) { $useithreads = $Config{'useithreads'}; } | |
93 | ||
cdf8b154 PK |
94 | print OUT <<"!GROK!THIS!"; |
95 | my \$perlpath = '$perlpath'; | |
345d73cf | 96 | my \$useithreads = '$useithreads'; |
cdf8b154 PK |
97 | !GROK!THIS! |
98 | ||
99 | print OUT <<'!NO!SUBS!'; | |
100 | ||
28fb188d | 101 | print "## Checking Perl binary via variable '\$perlpath' = $perlpath.\n" if $opt{'p'}; |
cdf8b154 | 102 | |
febdbc36 DG |
103 | my $label = 'Executable perl binary'; |
104 | ||
cdf8b154 | 105 | if (-x $perlpath) { |
28fb188d | 106 | print "## Perl binary '$perlpath' appears executable.\n" if $opt{'v'}; |
febdbc36 | 107 | print "ok 1 $label\n"; |
cdf8b154 PK |
108 | $pass__total++; |
109 | } | |
110 | else { | |
28fb188d | 111 | print "# Perl binary '$perlpath' does not appear executable.\n"; |
febdbc36 | 112 | print "not ok 1 $label\n"; |
cdf8b154 PK |
113 | $error_total++; |
114 | } | |
115 | $tests_total++; | |
116 | ||
117 | ||
28fb188d | 118 | print "## Checking Perl version via variable '\$]'.\n" if $opt{'p'}; |
cdf8b154 PK |
119 | |
120 | !NO!SUBS! | |
121 | ||
122 | print OUT <<"!GROK!THIS!"; | |
8dbc25a7 | 123 | my \$ivp_VERSION = "$]"; |
cdf8b154 PK |
124 | |
125 | !GROK!THIS! | |
126 | print OUT <<'!NO!SUBS!'; | |
febdbc36 DG |
127 | |
128 | $label = 'Perl version correct'; | |
97e8bd19 | 129 | if ($ivp_VERSION eq $]) { |
28fb188d | 130 | print "## Perl version '$]' appears installed as expected.\n" if $opt{'v'}; |
febdbc36 | 131 | print "ok 2 $label\n"; |
cdf8b154 PK |
132 | $pass__total++; |
133 | } | |
134 | else { | |
28fb188d | 135 | print "# Perl version '$]' installed, expected $ivp_VERSION.\n"; |
febdbc36 | 136 | print "not ok 2 $label\n"; |
cdf8b154 PK |
137 | $error_total++; |
138 | } | |
139 | $tests_total++; | |
140 | ||
50646f6f DG |
141 | # We have the right perl and version, so now reset @INC so we ignore |
142 | # PERL5LIB and '.' | |
143 | { | |
144 | local $ENV{PERL5LIB}; | |
145 | my $perl_V = qx($perlpath -V); | |
146 | $perl_V =~ s{.*\@INC:\n}{}ms; | |
147 | @INC = grep { length && $_ ne '.' } split ' ', $perl_V; | |
148 | } | |
cdf8b154 | 149 | |
28fb188d | 150 | print "## Checking roots of the Perl library directory tree via variable '\@INC'.\n" if $opt{'p'}; |
cdf8b154 PK |
151 | |
152 | my $INC_total = 0; | |
153 | my $INC_there = 0; | |
154 | foreach (@INC) { | |
155 | next if $_ eq '.'; # skip -d test here | |
cdf8b154 | 156 | if (-d $_) { |
28fb188d | 157 | print "## Perl \@INC directory '$_' exists.\n" if $opt{'v'}; |
cdf8b154 PK |
158 | $INC_there++; |
159 | } | |
160 | else { | |
28fb188d | 161 | print "# Perl \@INC directory '$_' does not appear to exist.\n"; |
cdf8b154 PK |
162 | } |
163 | $INC_total++; | |
164 | } | |
febdbc36 DG |
165 | |
166 | $label = '@INC directoreis exist'; | |
cdf8b154 | 167 | if ($INC_total == $INC_there) { |
febdbc36 | 168 | print "ok 3 $label\n"; |
cdf8b154 PK |
169 | $pass__total++; |
170 | } | |
171 | else { | |
febdbc36 | 172 | print "not ok 3 $label\n"; |
cdf8b154 PK |
173 | $error_total++; |
174 | } | |
175 | $tests_total++; | |
176 | ||
177 | ||
178 | print "## Checking installations of modules necessary for ivp.\n" if $opt{'p'}; | |
179 | ||
180 | my $needed_total = 0; | |
181 | my $needed_there = 0; | |
182 | foreach (qw(Config.pm ExtUtils/Installed.pm)) { | |
183 | $@ = undef; | |
184 | $needed_total++; | |
185 | eval "require \"$_\";"; | |
186 | if (!$@) { | |
28fb188d | 187 | print "## Module '$_' appears to be installed.\n" if $opt{'v'}; |
cdf8b154 PK |
188 | $needed_there++; |
189 | } | |
190 | else { | |
28fb188d | 191 | print "# Needed module '$_' does not appear to be properly installed.\n"; |
cdf8b154 PK |
192 | } |
193 | $@ = undef; | |
194 | } | |
febdbc36 | 195 | $label = 'Modules needed for rest of perlivp exist'; |
cdf8b154 | 196 | if ($needed_total == $needed_there) { |
febdbc36 | 197 | print "ok 4 $label\n"; |
cdf8b154 PK |
198 | $pass__total++; |
199 | } | |
200 | else { | |
febdbc36 | 201 | print "not ok 4 $label\n"; |
cdf8b154 PK |
202 | $error_total++; |
203 | } | |
204 | $tests_total++; | |
205 | ||
206 | ||
207 | print "## Checking installations of extensions built with perl.\n" if $opt{'p'}; | |
208 | ||
209 | use Config; | |
210 | ||
211 | my $extensions_total = 0; | |
212 | my $extensions_there = 0; | |
213 | if (defined($Config{'extensions'})) { | |
214 | my @extensions = split(/\s+/,$Config{'extensions'}); | |
215 | foreach (@extensions) { | |
216 | next if ($_ eq ''); | |
345d73cf PP |
217 | if ( $useithreads !~ /define/i ) { |
218 | next if ($_ eq 'threads'); | |
219 | next if ($_ eq 'threads/shared'); | |
220 | } | |
e7598a06 VP |
221 | # that's a distribution name, not a module name |
222 | next if $_ eq 'IO/Compress'; | |
960e02cf LB |
223 | next if $_ eq 'Devel/DProf'; |
224 | next if $_ eq 'libnet'; | |
225 | next if $_ eq 'Locale/Codes'; | |
226 | next if $_ eq 'podlators'; | |
ed416107 | 227 | next if $_ eq 'perlfaq'; |
e7598a06 VP |
228 | # test modules |
229 | next if $_ eq 'XS/APItest'; | |
230 | next if $_ eq 'XS/Typemap'; | |
cdf8b154 PK |
231 | # VMS$ perl -e "eval ""require \""Devel/DProf.pm\"";"" print $@" |
232 | # \NT> perl -e "eval \"require 'Devel/DProf.pm'\"; print $@" | |
233 | # DProf: run perl with -d to use DProf. | |
234 | # Compilation failed in require at (eval 1) line 1. | |
235 | eval " require \"$_.pm\"; "; | |
236 | if (!$@) { | |
28fb188d | 237 | print "## Module '$_' appears to be installed.\n" if $opt{'v'}; |
cdf8b154 PK |
238 | $extensions_there++; |
239 | } | |
240 | else { | |
28fb188d | 241 | print "# Required module '$_' does not appear to be properly installed.\n"; |
cdf8b154 PK |
242 | $@ = undef; |
243 | } | |
244 | $extensions_total++; | |
245 | } | |
246 | ||
247 | # A silly name for a module (that hopefully won't ever exist). | |
248 | # Note that this test serves more as a check of the validity of the | |
5538372e | 249 | # actual required module tests above. |
cdf8b154 PK |
250 | my $unnecessary = 'bLuRfle'; |
251 | ||
252 | if (!grep(/$unnecessary/, @extensions)) { | |
253 | $@ = undef; | |
254 | eval " require \"$unnecessary.pm\"; "; | |
255 | if ($@) { | |
28fb188d | 256 | print "## Unnecessary module '$unnecessary' does not appear to be installed.\n" if $opt{'v'}; |
cdf8b154 PK |
257 | } |
258 | else { | |
28fb188d | 259 | print "# Unnecessary module '$unnecessary' appears to be installed.\n"; |
cdf8b154 PK |
260 | $extensions_there++; |
261 | } | |
262 | } | |
263 | $@ = undef; | |
264 | } | |
febdbc36 | 265 | $label = 'All (and only) expected extensions installed'; |
cdf8b154 | 266 | if ($extensions_total == $extensions_there) { |
febdbc36 | 267 | print "ok 5 $label\n"; |
cdf8b154 PK |
268 | $pass__total++; |
269 | } | |
270 | else { | |
febdbc36 | 271 | print "not ok 5 $label\n"; |
cdf8b154 PK |
272 | $error_total++; |
273 | } | |
274 | $tests_total++; | |
275 | ||
276 | ||
277 | print "## Checking installations of later additional extensions.\n" if $opt{'p'}; | |
278 | ||
279 | use ExtUtils::Installed; | |
280 | ||
281 | my $installed_total = 0; | |
282 | my $installed_there = 0; | |
283 | my $version_check = 0; | |
284 | my $installed = ExtUtils::Installed -> new(); | |
285 | my @modules = $installed -> modules(); | |
286 | my @missing = (); | |
287 | my $version = undef; | |
288 | for (@modules) { | |
289 | $installed_total++; | |
290 | # Consider it there if it contains one or more files, | |
291 | # and has zero missing files, | |
292 | # and has a defined version | |
293 | $version = undef; | |
294 | $version = $installed -> version($_); | |
295 | if ($version) { | |
296 | print "## $_; $version\n" if $opt{'v'}; | |
297 | $version_check++; | |
298 | } | |
299 | else { | |
300 | print "# $_; NO VERSION\n" if $opt{'v'}; | |
301 | } | |
302 | $version = undef; | |
303 | @missing = (); | |
304 | @missing = $installed -> validate($_); | |
dae61315 JV |
305 | |
306 | # .bs files are optional | |
307 | @missing = grep { ! /\.bs$/ } @missing; | |
308 | # man files are often compressed | |
309 | @missing = grep { ! ( -s "$_.gz" || -s "$_.bz2" ) } @missing; | |
310 | ||
cdf8b154 PK |
311 | if ($#missing >= 0) { |
312 | print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n"; | |
313 | print '# ',join(' ',@missing),"\n"; | |
314 | } | |
315 | elsif ($#missing == -1) { | |
316 | $installed_there++; | |
317 | } | |
318 | @missing = (); | |
319 | } | |
febdbc36 | 320 | $label = 'Module files correctly installed'; |
cdf8b154 PK |
321 | if (($installed_total == $installed_there) && |
322 | ($installed_total == $version_check)) { | |
febdbc36 | 323 | print "ok 6 $label\n"; |
cdf8b154 PK |
324 | $pass__total++; |
325 | } | |
326 | else { | |
febdbc36 | 327 | print "not ok 6 $label\n"; |
cdf8b154 PK |
328 | $error_total++; |
329 | } | |
330 | $tests_total++; | |
331 | ||
cdf8b154 PK |
332 | # Final report (rather than feed ousrselves to Test::Harness::runtests() |
333 | # we simply format some output on our own to keep things simple and | |
334 | # easier to "fix" - at least for now. | |
335 | ||
336 | if ($error_total == 0 && $tests_total) { | |
337 | print "All tests successful.\n"; | |
338 | } elsif ($tests_total==0){ | |
339 | die "FAILED--no tests were run for some reason.\n"; | |
340 | } else { | |
341 | my $rate = 0.0; | |
342 | if ($tests_total > 0) { $rate = sprintf "%.2f", 100.0 * ($pass__total / $tests_total); } | |
343 | printf " %d/%d subtests failed, %.2f%% okay.\n", | |
344 | $error_total, $tests_total, $rate; | |
345 | } | |
346 | ||
347 | =head1 NAME | |
348 | ||
2a36bdc2 | 349 | perlivp - Perl Installation Verification Procedure |
cdf8b154 PK |
350 | |
351 | =head1 SYNOPSIS | |
352 | ||
d08226e4 | 353 | B<perlivp> [B<-p>] [B<-v>] [B<-h>] |
cdf8b154 PK |
354 | |
355 | =head1 DESCRIPTION | |
356 | ||
357 | The B<perlivp> program is set up at Perl source code build time to test the | |
358 | Perl version it was built under. It can be used after running: | |
359 | ||
360 | make install | |
361 | ||
362 | (or your platform's equivalent procedure) to verify that B<perl> and its | |
363 | libraries have been installed correctly. A correct installation is verified | |
364 | by output that looks like: | |
365 | ||
366 | ok 1 | |
367 | ok 2 | |
368 | ||
369 | etc. | |
370 | ||
371 | =head1 OPTIONS | |
372 | ||
373 | =over 5 | |
374 | ||
375 | =item B<-h> help | |
376 | ||
377 | Prints out a brief help message. | |
378 | ||
379 | =item B<-p> print preface | |
380 | ||
381 | Gives a description of each test prior to performing it. | |
382 | ||
383 | =item B<-v> verbose | |
384 | ||
385 | Gives more detailed information about each test, after it has been performed. | |
386 | Note that any failed tests ought to print out some extra information whether | |
387 | or not -v is thrown. | |
388 | ||
389 | =back | |
390 | ||
391 | =head1 DIAGNOSTICS | |
392 | ||
393 | =over 4 | |
394 | ||
28fb188d | 395 | =item * print "# Perl binary '$perlpath' does not appear executable.\n"; |
cdf8b154 PK |
396 | |
397 | Likely to occur for a perl binary that was not properly installed. | |
398 | Correct by conducting a proper installation. | |
399 | ||
28fb188d | 400 | =item * print "# Perl version '$]' installed, expected $ivp_VERSION.\n"; |
cdf8b154 PK |
401 | |
402 | Likely to occur for a perl that was not properly installed. | |
403 | Correct by conducting a proper installation. | |
404 | ||
28fb188d | 405 | =item * print "# Perl \@INC directory '$_' does not appear to exist.\n"; |
cdf8b154 PK |
406 | |
407 | Likely to occur for a perl library tree that was not properly installed. | |
408 | Correct by conducting a proper installation. | |
409 | ||
28fb188d | 410 | =item * print "# Needed module '$_' does not appear to be properly installed.\n"; |
cdf8b154 PK |
411 | |
412 | One of the two modules that is used by perlivp was not present in the | |
413 | installation. This is a serious error since it adversely affects perlivp's | |
414 | ability to function. You may be able to correct this by performing a | |
415 | proper perl installation. | |
416 | ||
28fb188d | 417 | =item * print "# Required module '$_' does not appear to be properly installed.\n"; |
cdf8b154 PK |
418 | |
419 | An attempt to C<eval "require $module"> failed, even though the list of | |
420 | extensions indicated that it should succeed. Correct by conducting a proper | |
421 | installation. | |
422 | ||
28fb188d | 423 | =item * print "# Unnecessary module 'bLuRfle' appears to be installed.\n"; |
cdf8b154 PK |
424 | |
425 | This test not coming out ok could indicate that you have in fact installed | |
426 | a bLuRfle.pm module or that the C<eval " require \"$module_name.pm\"; "> | |
427 | test may give misleading results with your installation of perl. If yours | |
428 | is the latter case then please let the author know. | |
429 | ||
430 | =item * print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n"; | |
431 | ||
432 | One or more files turned up missing according to a run of | |
433 | C<ExtUtils::Installed -E<gt> validate()> over your installation. | |
434 | Correct by conducting a proper installation. | |
435 | ||
cdf8b154 PK |
436 | =back |
437 | ||
438 | For further information on how to conduct a proper installation consult the | |
439 | INSTALL file that comes with the perl source and the README file for your | |
440 | platform. | |
441 | ||
442 | =head1 AUTHOR | |
443 | ||
444 | Peter Prymmer | |
445 | ||
446 | =cut | |
447 | ||
448 | !NO!SUBS! | |
449 | ||
450 | close OUT or die "Can't close $file: $!"; | |
451 | chmod 0755, $file or die "Can't reset permissions for $file: $!\n"; | |
452 | exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; | |
453 | chdir $origdir; | |
454 |