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.04 {
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 3 ▶ sub accept_suffix {
Subroutine accept_suffix: called CC=1 SCAR=0.0
Pod documented
21 3 (qr/\/v\.mod\z/)
22 }
23  
24 1 ▶ sub build_all ($self, $) {
Subroutine build_all: called CC=1 SCAR=0.0
Pod documented
25 1 $self->build_item;
26 }
27  
28 1 ▶ 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 # V calls GC_set_pages_executable(0) before GC_INIT() in main(),
63 # but shared libraries skip that, so on platforms that forbid
64 # PROT_EXEC mappings (macOS arm64) libgc aborts with
65 # "Cannot allocate executable pages".
66 0 $platform->run('v', '-prod', '-shared', -cflags => '-DNO_EXECUTE_PERMISSION', -o => "$lib_path", '.');
67 0 ▶ die "command failed" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
68 0 ▶ die "no shared library" unless -f $lib_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $lib_path 0 0 0
69 0 say "+cd -";
70  
71 } else {
72  
73 1 my $c_source = $vmod->sibling("$name.c");
74 1 ▶ die "module requires v compiler" unless -f $c_source;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $c_source 0 1 1
75 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
76 1 require FFI::Build;
77  
78 1 my @args;
79 1 ▶ if($self->build) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->build) { } 1 0 1
80 1 foreach my $key (qw( alien buildname cflags export file libs verbose )) {
81 7 push @args, $key => $self->build->$key;
82 }
83 } else {
84 0 push @args,
85 buildname => $buildname,
86 file => $lib,
87 ;
88 }
89  
90 1 warn "c_source = $c_source";
91  
92 1 my $bx = FFI::Build->new(
93 $name,
94 source => ["$c_source"],
95 platform => $platform,
96 dir => $vmod->parent->stringify,
97 @args,
98 );
99  
100 1 return $bx->build;
101  
102 }
103  
104 0 return $lib;
105  
106 }
107  
108 0 ▶ sub _deps ($self, $path)
Subroutine _deps: not called CC=5 SCAR=34.0
109 {
110 0 my @ret;
111 0 foreach my $path ($path->children) {
112 0 ▶ next if -l $path; # skip symlinks to avoid recursion
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 0 0
113 0 ▶ push @ret, $self->_deps($path) if -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $path 0 0 0
114 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
115 }
116 0 return @ret;
117 }
118  
119 1 ▶ sub _have_v_compiler ($self) {
Subroutine _have_v_compiler: called CC=3 SCAR=18.4
120 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
121 0 ▶ return 1 if which 'v';
Branch: 1 branch
BranchTrueFalseTotal
if which("v") 0 0 0
122 0 return 0;
123 }
124  
125 }
126  
127 __END__
↑ Summary blib/lib/FFI/Platypus/Lang/V.pm »