File: checkdeps

package info (click to toggle)
lcov 2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,464 kB
  • sloc: perl: 27,911; sh: 7,320; xml: 6,982; python: 1,152; makefile: 597; cpp: 520; ansic: 176
file content (70 lines) | stat: -rwxr-xr-x 1,494 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl
#
# Copyright IBM Corp. 2020
#
# Usage: checkdeps <perl-file1> [<perl-file2> ...]
#
# Check if all Perl modules required by the Perl programs specified on the
# command line are available. Note that this is a simple check that will only
# catch straight-forward use directives.
#
# Example:
# $ checkdeps file.pl file2.pl
#

use strict;
use warnings;

my $verbose = 0;

sub check_file($)
{
    my ($file) = @_;
    my $fd;
    my $line;
    my $rc = 0;

    open($fd, "<", $file) or die("Could not open $file: $!\n");
    $line = <$fd>;

    if (defined($line) &&
        $line =~ /^#.*perl/) {
        while ($line = <$fd>) {
            my $module;

            # Look for ...use...module...;
            next if ($line !~ /^\s*use\s+(\S+).*;\s*$/);

            $module = $1;
            # skip modules we define...
            next
                if grep(/^$module$/,
                        ('lcovutil', 'annotateutil',
                         'gitversion', 'gitblame',
                         'getp4version', 'p4annotate'));
            print("Checking for $module\n") if ($verbose);
            if (!eval("require $module")) {
                warn("Error: Missing Perl module '$module' " .
                     "required by $file\n");
                $rc = 1;
            }
        }
    }

    close($fd);

    return $rc;
}

sub main()
{
    my $rc = 0;

    for my $file (@ARGV) {
        $rc = 1 if (check_file($file));
    }

    return $rc;
}

exit(main());