| 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.12'; # VERSION | |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | sub accept_suffix | ||||||||||||||||||||||||||||||||||||
| 18 | 105 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
accept_suffix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 19 | 105 | (qr/\.(c|i)$/) | |||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | sub build_item | ||||||||||||||||||||||||||||||||||||
| 23 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
build_item: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 24 | 64 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | 64 | my $oname = $self->basename; | |||||||||||||||||||||||||||||||||||
| 27 | 64 | $oname =~ s/\.(c(xx|pp)|i)?$//; | |||||||||||||||||||||||||||||||||||
| 28 | 64 | $oname .= $self->platform->object_suffix; | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | 64 | my $buildname = '_build'; | |||||||||||||||||||||||||||||||||||
| 31 | 64 | ▶ | $buildname = $self->build->buildname if $self->build; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | 64 | my $object = FFI::Build::File::Object->new( | |||||||||||||||||||||||||||||||||||
| 34 | [ $self->dirname, $buildname, $oname ], | ||||||||||||||||||||||||||||||||||||
| 35 | platform => $self->platform, | ||||||||||||||||||||||||||||||||||||
| 36 | build => $self->build, | ||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | 64 | ▶ | return $object if -f $object->path && !$object->needs_rebuild($self->_deps); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $object->path and not $object->needs_rebuild($self->_deps)
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)
| |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | 64 | File::Path::mkpath($object->dirname, { verbose => 0, mode => oct(700) }); | |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | 64 | my @cmd = ( | |||||||||||||||||||||||||||||||||||
| 44 | $self->_base_args, | ||||||||||||||||||||||||||||||||||||
| 45 | -c => $self->path, | ||||||||||||||||||||||||||||||||||||
| 46 | $self->platform->flag_object_output($object->path), | ||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 64 | ▶ | my($out, $exit) = Capture::Tiny::capture_merged(sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 50 | 64 | $self->platform->run(@cmd); | |||||||||||||||||||||||||||||||||||
| 51 | 64 | }); | |||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 64 | ▶ | if($exit || !-f $object->path) | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$exit or not -f $object->path
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
| |||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||
| 60 | 16 | print $out; | |||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||
| 62 | ▶ | elsif($self->build && $self->build->verbose >= 1) | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->build and $self->build->verbose >= 1
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
| |||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||
| 64 | 43 | print "CC @{[ $self->path ]}\n"; | |||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | 63 | $object; | |||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | sub cc | ||||||||||||||||||||||||||||||||||||
| 71 | 66 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
cc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 72 | 66 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 73 | 66 | $self->platform->cc; | |||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | sub _base_args | ||||||||||||||||||||||||||||||||||||
| 77 | 69 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_base_args: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 78 | 69 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 79 | 69 | my @cmd = ($self->cc); | |||||||||||||||||||||||||||||||||||
| 80 | 69 | ▶ | push @cmd, $self->build->cflags_I if $self->build; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 81 | 69 | push @cmd, $self->platform->ccflags; | |||||||||||||||||||||||||||||||||||
| 82 | 69 | ▶ | push @cmd, @{ $self->build->cflags } if $self->build; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 83 | 69 | @cmd; | |||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | sub _base_args_cpp | ||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_base_args_cpp: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 88 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 89 | 0 | my @cmd = ($self->platform->cpp); | |||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | push @cmd, $self->build->cflags_I if $self->build; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 91 | 0 | push @cmd, grep /^-[DI]/, $self->platform->ccflags; | |||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | push @cmd, grep /^-D/, @{ $self->build->cflags } if $self->build; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 93 | 0 | @cmd; | |||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | sub build_item_cpp | ||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
build_item_cpp: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 98 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | my($out, $err, $exit) = Capture::Tiny::capture(sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->platform->run(@cmd); | |||||||||||||||||||||||||||||||||||
| 122 | 0 | }); | |||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if($exit) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | print "[out]\n$out\n" if defined $out && $out ne ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $out and $out ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | print "[err]\n$err\n" if defined $err && $err ne ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $err and $err ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_deps: called CC=3 SCAR=11.9
| |||||||||||||||||||||||||||||||||||||
| 143 | 5 | my($self) = @_; | |||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | return $self->path unless $self->platform->cc_mm_works; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||
| 147 | 5 | my @cmd = ( | |||||||||||||||||||||||||||||||||||
| 148 | $self->_base_args, | ||||||||||||||||||||||||||||||||||||
| 149 | '-MM', | ||||||||||||||||||||||||||||||||||||
| 150 | $self->path, | ||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | my($out,$err,$exit) = Capture::Tiny::capture(sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 154 | 5 | $self->platform->run(@cmd); | |||||||||||||||||||||||||||||||||||
| 155 | 5 | }); | |||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if($exit) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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 | 5 | $out =~ s/^\+.*\n//; # remove the command line | |||||||||||||||||||||||||||||||||||
| 167 | # which on windows could have an confusing : | ||||||||||||||||||||||||||||||||||||
| 168 | 5 | my(undef, $deps) = split /:/, $out, 2; | |||||||||||||||||||||||||||||||||||
| 169 | 5 | $deps =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||
| 170 | 5 | $deps =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||
| 171 | 5 | return grep !/^\\$/, split /\s+/, $deps; | |||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | 12 | 1; | |||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||||||||||