lib/FFI/Build/File/C.pm

filter: Statementstmt 68.6% 68 / 99 Branchbran 50.0% 15 / 30 Conditioncond 50.0% 9 / 18 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 84.2% 16 / 19 Podpod 50.0% 2 / 4 totaltotal 62.6% 114 / 182 CC 22 SCAR 26.4
CC
22
Cov
63%
build_item_cpp
56.0
_base_args_cpp
12.0
build_item
10.1
CRAP 14.1
« blib/lib/FFI/Build/File/Base.pm ↑ Summary blib/lib/FFI/Platypus/Record.pm »
1 package FFI::Build::File::C;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use parent qw( FFI::Build::File::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use constant default_suffix => '.c';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use constant default_encoding => ':utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Capture::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use FFI::Build::File::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: Class to track C source file in FFI::Build
14 12 our $VERSION = '2.11'; # VERSION
15  
16  
17 sub accept_suffix
18 {
19 103 ▶ (qr/\.(c|i)$/)
Subroutine accept_suffix: called CC=1 SCAR=0.0
Pod documented
20 }
21  
22 sub build_item
23 {
24 61 ▶ my($self) = @_;
Subroutine build_item: called CC=10 SCAR=23.1
Pod documented
25  
26 61 my $oname = $self->basename;
27 61 $oname =~ s/\.(c(xx|pp)|i)?$//;
28 61 $oname .= $self->platform->object_suffix;
29  
30 61 my $buildname = '_build';
31 61 ▶ $buildname = $self->build->buildname if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 58 3 61
32  
33 61 my $object = FFI::Build::File::Object->new(
34 [ $self->dirname, $buildname, $oname ],
35 platform => $self->platform,
36 build => $self->build,
37 );
38  
39 61 ▶ return $object if -f $object->path && !$object->needs_rebuild($self->_deps);
Branch: 1 branch
BranchTrueFalseTotal
if -f $object->path and not $object->needs_rebuild($self->_deps) 0 61 61
Condition66%2/3
-f $object->path and not $object->needs_rebuild($self->_deps)
!ll&&!rl&&r
5830
MC/DC0%0/2
-f $object->path and not $object->needs_rebuild($self->_deps)
-f $object->path not $object->needs_rebuild($self->_deps)
Truth table66%2/3
A and not(B)
A= -f $object->pathB= not $object->needs_rebuild($self->_deps)
ABresult
0X0
100
111
40  
41 61 File::Path::mkpath($object->dirname, { verbose => 0, mode => oct(700) });
42  
43 61 my @cmd = (
44 $self->_base_args,
45 -c => $self->path,
46 $self->platform->flag_object_output($object->path),
47 );
48  
49 my($out, $exit) = Capture::Tiny::capture_merged(sub {
50 61 ▶ $self->platform->run(@cmd);
Subroutine __ANON__: called CC=1 SCAR=0.0
51 61 });
52  
53 61 ▶ if($exit || !-f $object->path)
Branch: 3 branches
BranchTrueFalseTotal
if ($exit or not -f $object->path) { } 1 60 61
elsif ($self->build and $self->build->verbose >= 2) { } 14 46 60
elsif ($self->build and $self->build->verbose >= 1) { } 43 6 49
Condition66%2/3
$exit or not -f $object->path
l!l&&r!l&&!r
1060
MC/DC50%1/2
$exit or not -f $object->path
$exit not -f $object->path
Truth table66%2/3
A or not(B)
A= $exitB= not -f $object->path
ABresult
1X1
011
000
54 {
55 1 print $out;
56 1 die "error building $object from $self";
57 }
58 ▶ elsif($self->build && $self->build->verbose >= 2)
Condition100%3/3
$self->build and $self->build->verbose >= 2
!ll&&!rl&&r
34314
MC/DC100%2/2
$self->build and $self->build->verbose >= 2
$self->build $self->build->verbose >= 2
Truth table100%3/3
A and B
A= $self->buildB= $self->build->verbose >= 2
ABresult
0X0
100
111
59 {
60 14 print $out;
61 }
62 ▶ elsif($self->build && $self->build->verbose >= 1)
Condition66%2/3
$self->build and $self->build->verbose >= 1
!ll&&!rl&&r
3043
MC/DC50%1/2
$self->build and $self->build->verbose >= 1
$self->build $self->build->verbose >= 1
Truth table66%2/3
A and B
A= $self->buildB= $self->build->verbose >= 1
ABresult
0X0
100
111
63 {
64 43 print "CC @{[ $self->path ]}\n";
65 }
66  
67 60 $object;
68 }
69  
70 sub cc
71 {
72 65 ▶ my($self) = @_;
Subroutine cc: called CC=1 SCAR=0.0
Pod undocumented
73 65 $self->platform->cc;
74 }
75  
76 sub _base_args
77 {
78 65 ▶ my($self) = @_;
Subroutine _base_args: called CC=3 SCAR=11.0
79 65 my @cmd = ($self->cc);
80 65 ▶ push @cmd, $self->build->cflags_I if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 62 3 65
81 65 push @cmd, $self->platform->ccflags;
82 65 ▶ push @cmd, @{ $self->build->cflags } if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 62 3 65
83 65 @cmd;
84 }
85  
86 sub _base_args_cpp
87 {
88 0 ▶ my($self) = @_;
Subroutine _base_args_cpp: not called CC=3 SCAR=24.8
89 0 my @cmd = ($self->platform->cpp);
90 0 ▶ push @cmd, $self->build->cflags_I if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 0 0 0
91 0 push @cmd, grep /^-[DI]/, $self->platform->ccflags;
92 0 ▶ push @cmd, grep /^-D/, @{ $self->build->cflags } if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 0 0 0
93 0 @cmd;
94 }
95  
96 sub build_item_cpp
97 {
98 0 ▶ my($self) = @_;
Subroutine build_item_cpp: not called CC=7 SCAR=40.3
Pod undocumented
99  
100 0 my $oname = $self->basename;
101 0 $oname =~ s/\.(c(xx|pp)|i)$?$//;
102 0 $oname .= '.i';
103  
104 0 my $buildname = '_build';
105 0 ▶ $buildname = $self->build->buildname if $self->build;
Branch: 1 branch
BranchTrueFalseTotal
if $self->build 0 0 0
106  
107 0 my $ifile = FFI::Build::File::C->new(
108 [ $self->dirname, $buildname, $oname ],
109 platform => $self->platform,
110 build => $self->build,
111 );
112  
113 0 File::Path::mkpath($ifile->dirname, { verbose => 0, mode => oct(700) });
114  
115 0 my @cmd = (
116 $self->_base_args_cpp,
117 $self->path,
118 );
119  
120 my($out, $err, $exit) = Capture::Tiny::capture(sub {
121 0 ▶ $self->platform->run(@cmd);
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 });
123  
124 0 ▶ if($exit)
Branch: 1 branch
BranchTrueFalseTotal
if ($exit) { } 0 0 0
125 {
126 0 ▶ print "[out]\n$out\n" if defined $out && $out ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $out and $out ne "" 0 0 0
Condition0%0/3
defined $out and $out ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $out and $out ne ""
defined $out $out ne ""
Truth table0%0/3
A and B
A= defined $outB= $out ne ""
ABresult
0X0
100
111
127 0 ▶ print "[err]\n$err\n" if defined $err && $err ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $err and $err ne "" 0 0 0
Condition0%0/3
defined $err and $err ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $err and $err ne ""
defined $err $err ne ""
Truth table0%0/3
A and B
A= defined $errB= $err ne ""
ABresult
0X0
100
111
128 0 die "error building $ifile from $self";
129 }
130 else
131 {
132 0 my $fh;
133 0 open($fh, '>', $ifile->path);
134 0 print $fh $out;
135 0 close $fh;
136 }
137  
138 0 $ifile;
139 }
140  
141 sub _deps
142 {
143 4 ▶ my($self) = @_;
Subroutine _deps: called CC=3 SCAR=11.9
144  
145 4 ▶ return $self->path unless $self->platform->cc_mm_works;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->platform->cc_mm_works 0 4 4
146  
147 4 my @cmd = (
148 $self->_base_args,
149 '-MM',
150 $self->path,
151 );
152  
153 my($out,$err,$exit) = Capture::Tiny::capture(sub {
154 4 ▶ $self->platform->run(@cmd);
Subroutine __ANON__: called CC=1 SCAR=0.0
155 4 });
156  
157 4 ▶ if($exit)
Branch: 1 branch
BranchTrueFalseTotal
if ($exit) { } 0 4 4
158 {
159 0 print $out;
160 0 print $err;
161 0 warn "error computing dependencies for $self";
162 0 return ($self->path);
163 }
164 else
165 {
166 4 $out =~ s/^\+.*\n//; # remove the command line
167 # which on windows could have an confusing :
168 4 my(undef, $deps) = split /:/, $out, 2;
169 4 $deps =~ s/^\s+//;
170 4 $deps =~ s/\s+$//;
171 4 return grep !/^\\$/, split /\s+/, $deps;
172 }
173 }
174  
175 12 1;
176  
177 __END__
« blib/lib/FFI/Build/File/Base.pm ↑ Summary blib/lib/FFI/Platypus/Record.pm »