blib/lib/FFI/Build/File/VMod.pm

filter: Statementstmt 70.9% 61 / 86 Branchbran 30.0% 9 / 30 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 94.1% 16 / 17 Podpod 100% 3 / 3 totaltotal 61.6% 90 / 146 CC 20 SCAR 30.6
CC
20
Cov
58%
build_item
42.1
_deps
30.0
_have_v_compiler
6.3
CRAP 21.4
↑ Summary blib/lib/FFI/Platypus/Lang/V.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use stable qw( postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use true;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 package FFI::Build::File::VMod 0.03 {
8  
9 # ABSTRACT: Class to track V source in FFI::Build
10  
11 1 ▶ use parent qw( FFI::Build::File::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use constant default_suffix => '.mod';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use constant default_encoding => ':utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use File::Which qw( which );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use PerlX::Maybe qw( maybe );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use Path::Tiny 0.130 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 sub accept_suffix {
21 3 ▶ (qr/\/v\.mod\z/)
Subroutine accept_suffix: called CC=1 SCAR=0.0
Pod documented
22 }
23  
24 ▶ sub build_all ($self, $) {
Subroutine build_all: called CC=1 SCAR=0.0
Pod documented
25 1 $self->build_item;
26 }
27  
28 ▶ sub build_item ($self) {
Subroutine build_item: called CC=14 SCAR=37.4
Pod documented
29  
30 1 my $vmod = Path::Tiny->new($self->path);
31  
32 1 my $platform;
33 my $buildname;
34 1 my $lib;
35  
36 1 ▶ my($name) = map { /name:\s*'(.*)'/ ? ($1) : () } $vmod->lines_utf8;
Branch: 1 branch
BranchTrueFalseTotal
/name:\s*'(.*)'/u ? : 1 3 4
37 1 ▶ die "unable to find name in $vmod" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
38  
39 1 ▶ if($self->build) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->build) { } 1 0 1
40 1 $platform = $self->build->platform;
41 1 $buildname = $self->build->buildname;
42 1 $lib = $self->build->file;
43 } else {
44 0 $platform = FFI::Build::Platform->new;
45 0 $buildname = "_build";
46  
47 0 $lib = FFI::Build::File::Library->new(
48 $vmod->sibling("$name" . scalar($platform->library_suffix))->stringify,
49 platform => $self->platform,
50 );
51 }
52  
53 1 ▶ if($self->_have_v_compiler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_have_v_compiler) { } 0 1 1
54  
55 0 ▶ return $lib if -f $lib->path && !$lib->needs_rebuild($self->_deps($vmod->parent));
Branch: 1 branch
BranchTrueFalseTotal
if -f $lib->path and not $lib->needs_rebuild($self->_deps($vmod->parent)) 0 0 0
Condition0%0/3
-f $lib->path and not $lib->needs_rebuild($self->_deps($vmod->parent))
!ll&&!rl&&r
000
MC/DC0%0/2
-f $lib->path and not $lib->needs_rebuild($self->_deps($vmod->parent))
-f $lib->path not $lib->needs_rebuild($self->_deps($vmod->parent))
Truth table0%0/3
A and not(B)
A= -f $lib->pathB= not $lib->needs_rebuild($self->_deps($vmod->parent))
ABresult
0X0
100
111
56  
57 0 my $lib_path = Path::Tiny->new($lib->path)->relative($vmod->parent);
58 0 say "+cd @{[ $vmod->parent ]}";
59 0 local $CWD = $vmod->parent;
60 0 say "+mkdir -p @{[ $lib_path->parent->mkdir ]}";
61 0 $lib_path->parent->mkdir;
62 0 $platform->run('v', '-prod', '-shared', -o => "$lib_path", '.');
63 0 ▶ die "command failed" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
64 0 ▶ die "no shared library" unless -f $lib_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $lib_path 0 0 0
65 0 say "+cd -";
66  
67 } else {
68  
69 1 my $c_source = $vmod->sibling("$name.c");
70 1 ▶ die "module requires v compiler" unless -f $c_source;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $c_source 0 1 1
71 1 ▶ return $lib if -f $lib->path && !$lib->needs_rebuild($c_source->stringify);
Branch: 1 branch
BranchTrueFalseTotal
if -f $lib->path and not $lib->needs_rebuild($c_source->stringify) 0 1 1
Condition33%1/3
-f $lib->path and not $lib->needs_rebuild($c_source->stringify)
!ll&&!rl&&r
100
MC/DC0%0/2
-f $lib->path and not $lib->needs_rebuild($c_source->stringify)
-f $lib->path not $lib->needs_rebuild($c_source->stringify)
Truth table33%1/3
A and not(B)
A= -f $lib->pathB= not $lib->needs_rebuild($c_source->stringify)
ABresult
0X0
100
111
72 1 require FFI::Build;
73  
74 1 my @args;
75 1 ▶ if($self->build) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->build) { } 1 0 1
76 1 foreach my $key (qw( alien buildname cflags export file libs verbose )) {
77 7 push @args, $key => $self->build->$key;
78 }
79 } else {
80 0 push @args,
81 buildname => $buildname,
82 file => $lib,
83 ;
84 }
85  
86 1 warn "c_source = $c_source";
87  
88 1 my $bx = FFI::Build->new(
89 $name,
90 source => ["$c_source"],
91 platform => $platform,
92 dir => $vmod->parent->stringify,
93 @args,
94 );
95  
96 1 return $bx->build;
97  
98 }
99  
100 0 return $lib;
101  
102 }
103  
104 sub _deps ($self, $path)
105 ▶ {
Subroutine _deps: not called CC=5 SCAR=34.0
106 0 my @ret;
107 0 foreach my $path ($path->children) {
108 0 ▶ next if -l $path; # skip symlinks to avoid recursion
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 0 0
109 0 ▶ push @ret, $self->_deps($path) if -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $path 0 0 0
110 0 ▶ push @ret, $path->stringify if $path->basename =~ /^(.*\.(v|c|h)|v\.mod)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $path->basename =~ /^(.*\.(v|c|h)|v\.mod)\z/u 0 0 0
111 }
112 0 return @ret;
113 }
114  
115 ▶ sub _have_v_compiler ($self) {
Subroutine _have_v_compiler: called CC=3 SCAR=18.4
116 1 ▶ return 0 if $ENV{FFI_PLATYPUS_LANG_VMOD_SKIP_V};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"FFI_PLATYPUS_LANG_VMOD_SKIP_V"} 1 0 1
117 0 ▶ return 1 if which 'v';
Branch: 1 branch
BranchTrueFalseTotal
if which("v") 0 0 0
118 0 return 0;
119 }
120  
121 }
122  
123 __END__
↑ Summary blib/lib/FFI/Platypus/Lang/V.pm »