| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# Copyright IBM Corp. 2020 |
| 4 |
# |
| 5 |
# Usage: checkdeps <perl-file1> [<perl-file2> ...] |
| 6 |
# |
| 7 |
# Check if all Perl modules required by the Perl programs specified on the |
| 8 |
# command line are available. Note that this is a simple check that will only |
| 9 |
# catch straight-forward use directives. |
| 10 |
# |
| 11 |
# Example: |
| 12 |
# $ checkdeps file.pl file2.pl |
| 13 |
# |
| 14 |
|
| 15 |
use strict; |
| 16 |
use warnings; |
| 17 |
|
| 18 |
my $verbose = 0; |
| 19 |
|
| 20 |
sub check_file($) |
| 21 |
{ |
| 22 |
my ($file) = @_; |
| 23 |
my $fd; |
| 24 |
my $line; |
| 25 |
my $rc = 0; |
| 26 |
|
| 27 |
open($fd, "<", $file) or die("Could not open $file: $!\n"); |
| 28 |
$line = <$fd>; |
| 29 |
|
| 30 |
if (defined($line) && |
| 31 |
$line =~ /^#.*perl/) { |
| 32 |
while ($line = <$fd>) { |
| 33 |
my $module; |
| 34 |
|
| 35 |
# Look for ...use...module...; |
| 36 |
next if ($line !~ /^\s*use\s+(\S+).*;\s*$/); |
| 37 |
|
| 38 |
$module = $1; |
| 39 |
# skip modules we define... |
| 40 |
next |
| 41 |
if grep(/^$module$/, |
| 42 |
('lcovutil', 'annotateutil', |
| 43 |
'gitversion', 'gitblame', |
| 44 |
'getp4version', 'p4annotate')); |
| 45 |
print("Checking for $module\n") if ($verbose); |
| 46 |
if (!eval("require $module")) { |
| 47 |
warn("Error: Missing Perl module '$module' " . |
| 48 |
"required by $file\n"); |
| 49 |
$rc = 1; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
close($fd); |
| 55 |
|
| 56 |
return $rc; |
| 57 |
} |
| 58 |
|
| 59 |
sub main() |
| 60 |
{ |
| 61 |
my $rc = 0; |
| 62 |
|
| 63 |
for my $file (@ARGV) { |
| 64 |
$rc = 1 if (check_file($file)); |
| 65 |
} |
| 66 |
|
| 67 |
return $rc; |
| 68 |
} |
| 69 |
|
| 70 |
exit(main()); |