| 1 | package | ||||||||||||||||||||||||||||
| 2 | XS::Install::Deps; | ||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Cwd 'abs_path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 31 | ▶ | sub find_header_deps { | ||||||||||||||||||||||||||
|
Subroutine
find_header_deps: called CC=8 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 31 | my $p = shift; | |||||||||||||||||||||||||||
| 10 | 31 | ▶ | my $headers = [ grep {$_} map { abs_path($_) } @{$p->{headers} || []} ]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$p->{'headers'} || []
MC/DC0%0/1
$p->{'headers'} || []
$p->{'headers'}
Truth table50%1/2
A
A= $p->{'headers'}
| |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | my $inc = [ grep {$_} map { abs_path($_) } @{$p->{inc} || []} ]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$p->{'inc'} || []
MC/DC0%0/1
$p->{'inc'} || []
$p->{'inc'}
Truth table50%1/2
A
A= $p->{'inc'}
| |||||||||||||||||||||||||||||
| 12 | 31 | my $cache = {}; | |||||||||||||||||||||||||||
| 13 | 31 | ▶ | $headers = undef unless @$headers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 31 | my %ret; | |||||||||||||||||||||||||||
| 16 | 31 | foreach my $file (@{$p->{files}}) { | |||||||||||||||||||||||||||
| 17 | 179 | ▶ | my $absfile = eval { abs_path($file) } or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 179 | ▶ | next unless -f $absfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 179 | ▶ | my $deps = _find_header_deps($absfile, $cache, $inc, $headers) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 179 | $ret{$file} = [keys %$deps]; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 31 | return \%ret; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 179 | ▶ | sub _find_header_deps { | ||||||||||||||||||||||||||
|
Subroutine
_find_header_deps: called CC=14 SCAR=47.1
| |||||||||||||||||||||||||||||
| 27 | 179 | my ($file, $cache, $inc, $headers) = @_; | |||||||||||||||||||||||||||
| 28 | 179 | ▶ | return $cache->{$file} if exists $cache->{$file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 179 | my $deps = $cache->{$file} = {}; | |||||||||||||||||||||||||||
| 31 | 179 | my $content = readfile($file); | |||||||||||||||||||||||||||
| 32 | 179 | my $dir = $file; | |||||||||||||||||||||||||||
| 33 | 179 | $dir =~ s#[^/\\]+$##; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 179 | ▶ | while ($content =~ /^\s*#\s*include\s*("|<)([^">]+)(?:"|>)/mg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | my ($type, $dep) = ($1, $2); | |||||||||||||||||||||||||||
| 37 | 0 | my $absdep; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($type eq '"') { # try to find locally first | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | $absdep = getfile($dir.$dep); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | unless ($absdep) { # try to find globally | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | foreach my $dir (@$inc) { | |||||||||||||||||||||||||||
| 43 | 0 | $absdep = getfile($dir.'/'.$dep); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | last if $absdep; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($absdep and $headers) { # if supplied, ignore everything that is outside of specified dirs | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$absdep and $headers
MC/DC0%0/2
$absdep and $headers
$absdep
$headers
Truth table0%0/3
A and B
A= $absdepB= $headers
| |||||||||||||||||||||||||||||
| 48 | 0 | my $found; | |||||||||||||||||||||||||||
| 49 | 0 | foreach my $dir (@$headers) { | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | next unless index($absdep, $dir) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $found = 1; | |||||||||||||||||||||||||||
| 52 | 0 | last; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $absdep = undef unless $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | next unless $absdep; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $deps->{File::Spec->abs2rel($absdep)}++; | |||||||||||||||||||||||||||
| 59 | 0 | my $subdeps = _find_header_deps($absdep, $cache, $inc, $headers); | |||||||||||||||||||||||||||
| 60 | 0 | $deps->{$_}++ for keys %$subdeps; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 179 | return $deps; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 77 | ▶ | sub find_xsi_deps { | ||||||||||||||||||||||||||
|
Subroutine
find_xsi_deps: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 77 | my $files = shift; | |||||||||||||||||||||||||||
| 68 | 77 | my %ret; | |||||||||||||||||||||||||||
| 69 | 77 | foreach my $file (@$files) { | |||||||||||||||||||||||||||
| 70 | 77 | ▶ | my $absfile = abs_path($file) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 77 | ▶ | next unless -f $absfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 77 | ▶ | my $deps = _find_xsi_deps($absfile) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 77 | $ret{$file} = [keys %$deps]; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 77 | return \%ret; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 77 | ▶ | sub _find_xsi_deps { | ||||||||||||||||||||||||||
|
Subroutine
_find_xsi_deps: called CC=4 SCAR=17.3
| |||||||||||||||||||||||||||||
| 79 | 77 | my $file = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 77 | my $content = readfile($file); | |||||||||||||||||||||||||||
| 82 | 77 | my $dir = $file; | |||||||||||||||||||||||||||
| 83 | 77 | $dir =~ s#[^/\\]+$##; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 77 | my $deps = {}; | |||||||||||||||||||||||||||
| 86 | 77 | ▶ | while ($content =~ /^\s*INCLUDE\s*:\s*(.+)/mg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $xsi = getfile($dir.$1) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $deps->{File::Spec->abs2rel($xsi)}++; | |||||||||||||||||||||||||||
| 89 | 0 | my $subdeps = _find_xsi_deps($xsi); | |||||||||||||||||||||||||||
| 90 | 0 | $deps->{$_}++ for keys %$subdeps; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 77 | return $deps; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub getfile { | ||||||||||||||||||||||||||
|
Subroutine
getfile: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $f = abs_path($_[0]); | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | return undef unless $f and -f $f; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$f and -f $f
MC/DC0%0/2
$f and -f $f
$f
-f $f
Truth table0%0/3
A and B
A= $fB= -f $f
| |||||||||||||||||||||||||||||
| 99 | 0 | return $f; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 256 | ▶ | sub readfile { | ||||||||||||||||||||||||||
|
Subroutine
readfile: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 256 | my $file = shift; | |||||||||||||||||||||||||||
| 104 | 256 | ▶ | open my $fh, '<', $file or die "cannot open $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 256 | local $/ = undef; | |||||||||||||||||||||||||||
| 106 | 256 | my $content = <$fh>; | |||||||||||||||||||||||||||
| 107 | 256 | close $fh; | |||||||||||||||||||||||||||
| 108 | 256 | return $content; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 11 | 1; | |||||||||||||||||||||||||||