blib/lib/Alien/Build/Plugin/Build/Xrepo.pm

filter: Statementstmt 10.3% 33 / 318 Branchbran 0.0% 0 / 166 Conditioncond 0.0% 0 / 94 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 23.3% 7 / 30 Podpod 100% 1 / 1 totaltotal 6.1% 41 / 664 CC 137 SCAR 51.3
CC
137
Cov
6%
__ANON__
506.0
__ANON__
306.0
__ANON__
272.0
CRAP 169.0
↑ Summary
1 1 package Alien::Build::Plugin::Build::Xrepo v1.0.1 {
2 1 ▶ use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶ use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #
9 0 ▶ has '+packages' => sub { Carp::croak 'packages is a required property' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
10 1 has name => undef;
11 1 has version => undef;
12 1 has kind => undef;
13 1 has root => undef;
14 1 has ffi => 0;
15 1 has verbose => 0;
16 1 has repo => undef;
17 1 has local_repos => undef;
18 1 has __build => undef;
19  
20 1 ▶ sub init ( $self, $meta ) {
Subroutine init: called CC=6 SCAR=37.1
Pod documented
21 1 my $verbose = $self->verbose;
22 1 $meta->add_requires( 'configure', 'Alien::Build' => '2.84' );
23 1 $meta->add_requires( 'configure', 'Alien::Xrepo' => 'v1.0.0' );
24 1 require Alien::Xrepo;
25 0 require Alien::Xrepo::Build::Recipe;
26 0 require Alien::Xmake;
27 0 ▶ my $recipe = Alien::Xrepo::Build::Recipe->new(
Branch: 2 branches
BranchTrueFalseTotal
defined $self->name ? : 0 0 0
defined $self->local_repos ? : 0 0 0
28 ( defined $self->name ? ( name => $self->name ) : () ),
29 ( defined $self->local_repos ? ( local_repos => $self->local_repos ) : () ),
30 packages => $self->packages
31 );
32 0 my %ambient;
33 0 ▶ $ambient{version} = $self->version if defined $self->version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->version 0 0 0
34 0 ▶ $ambient{kind} = $self->kind if defined $self->kind;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->kind 0 0 0
35 0 my $repo = $self->repo;
36 0 my $engine;
37 0 ▶ my $engine_for = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
38 0 ▶ return $engine if defined $engine;
Branch: 1 branch
BranchTrueFalseTotal
if defined $engine 0 0 0
39 0 ▶ if ( ref $repo eq 'CODE' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $repo eq 'CODE') { } 0 0 0
elsif (ref $repo) { } 0 0 0
elsif (defined $repo) { } 0 0 0
40 0 $engine = $repo->();
41 }
42 elsif ( ref $repo ) {
43 0 $engine = $repo;
44 }
45 elsif ( defined $repo ) {
46 0 $engine = $repo->new();
47 }
48 else {
49 0 $engine = Alien::Xrepo->new( root => $self->root, verbose => $verbose );
50 }
51 0 $engine;
52 0 };
53 $meta->register_hook(
54 0 ▶ probe => sub ($build) {
Subroutine __ANON__: not called CC=16 SCAR=56.1
55 0 my $r = eval { $engine_for->() };
56 0 ▶ if ( !$r ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
57 0 ▶ my $err = $@ || 'unknown error';
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
58 0 $err =~ s/\s+/ /g;
59 0 ▶ $err = substr( $err, 0, 300 ) . '...' if length($err) > 300;
Branch: 1 branch
BranchTrueFalseTotal
if length $err > 300 0 0 0
60 0 die "Alien::Build::Plugin::Build::Xrepo: could not construct the xrepo engine during probe: $err\n";
61 }
62 0 my %probed;
63 0 for my $name ( $recipe->packages ) {
64 0 my $version = $recipe->version_for($name);
65 0 ▶ $version = $ambient{version} unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
66 0 my %opts = $recipe->opts_for( $name, %ambient );
67 0 my ( $found, $satisfied );
68 0 eval {
69 0 my $info = $r->info( $name, format => 'json', %opts );
70 0 ▶ if ( ref $info eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info eq "HASH") 0 0 0
71 0 ▶ $found = $info->{version} // $info->{package}{version} // undef;
Condition0%0/5
($info->{"version"} // $info->{"package"}{"version"}) // undef
l!l
00
$info->{"version"} // $info->{"package"}{"version"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($info->{"version"} // $info->{"package"}{"version"}) // undef
$info->{"version"} $info->{"package"}{"version"}
Truth table0%0/3
A // B
A= $info->{"version"}B= $info->{"package"}{"version"}
ABresult
1X1
011
000
72 }
73 };
74 0 ▶ $satisfied = ( defined $found && defined $version ) ? ( $found eq $version ) : ( defined $found ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $found && defined $version ? : 0 0 0
defined $found ? : 0 0 0
Condition0%0/3
defined $found and defined $version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $found and defined $version
defined $found defined $version
Truth table0%0/3
A and B
A= defined $foundB= defined $version
ABresult
0X0
100
111
75 0 $probed{$name} = { version => $found, satisfied => $satisfied };
76 0 ▶ my $status = $satisfied ? 'satisfied' : 'missing';
Branch: 1 branch
BranchTrueFalseTotal
$satisfied ? : 0 0 0
77 0 ▶ say "[xrepo] probe: $name " . ( $found // 'not installed' ) . " ($status)\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
Condition0%0/2
$found // "not installed"
l!l
00
MC/DC0%0/1
$found // "not installed"
$found
Truth table0%0/2
A
A= $found
Aresult
11
00
78 }
79 0 ▶ $build->install_prop->{xrepo} ||= {};
Condition0%0/2
$build->install_prop->{"xrepo"} ||= {}
l!l
00
MC/DC0%0/1
$build->install_prop->{"xrepo"} ||= {}
$build->install_prop->{"xrepo"}
Truth table0%0/2
A
A= $build->install_prop->{"xrepo"}
Aresult
11
00
80 0 $build->install_prop->{xrepo}{probed} = \%probed;
81 0 return 'share';
82 }
83 0 );
84 $meta->register_hook(
85 0 ▶ download => sub ($build) {
Subroutine __ANON__: not called CC=22 SCAR=62.3
86 0 $self->__build($build);
87 0 ▶ unless ( ref $repo ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $repo) 0 0 0
88 0 ▶ my $xrepo = eval { Alien::Xmake->new->xrepo } || 'xrepo';
Condition0%0/2
eval { do { 'Alien::Xmake'->new->xrepo } } || 'xrepo'
l!l
00
MC/DC0%0/1
eval { do { 'Alien::Xmake'->new->xrepo } } || 'xrepo'
eval { do { 'Alien::Xmake'->new->xrepo } }
Truth table0%0/2
A
A= eval { do { 'Alien::Xmake'->new->xrepo } }
Aresult
11
00
89 0 ▶ my $ok = File::Spec->file_name_is_absolute($xrepo) ? ( -e $xrepo ) : _which_in_path($xrepo);
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($xrepo) ? : 0 0 0
90 0 ▶ die "Alien::Build::Plugin::Build::Xrepo: could not locate xrepo ($xrepo). " .
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
91 'Install xmake, or inject an engine via the repo property.'
92 unless $ok;
93 }
94 0 my $r = $engine_for->();
95 0 my $src = Cwd::getcwd();
96  
97 # Register any local repo trees (patched/private package recipes) with the engine
98 # before installing, mirroring the engine's configure stage. Remember only the
99 # repos this stage actually added: they point into the build's temporary tree and
100 # must be unregistered before that tree disappears.
101 0 ▶ for my $repo_def ( @{ $recipe->local_repos || [] } ) {
Condition0%0/2
$recipe->local_repos || []
l!l
00
MC/DC0%0/1
$recipe->local_repos || []
$recipe->local_repos
Truth table0%0/2
A
A= $recipe->local_repos
Aresult
11
00
102 0 my $dir = Path::Tiny->new($repo_def)->absolute;
103 0 ▶ next unless $dir->child('packages')->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->child("packages")->is_dir 0 0 0
104 0 my $nm = 'alien-' . $dir->basename;
105 0 ▶ if ( !$r->can('add_repo') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->can("add_repo")) 0 0 0
106 0 ▶ say "[xrepo] no engine support for add_repo (local repo $nm ignored)" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
107 0 next;
108 }
109 0 my $added = eval { $r->add_repo( $nm, $dir->stringify ); 1 };
110 0 ▶ $build->runtime_prop->{repos}{$nm}++ if $added;
Branch: 1 branch
BranchTrueFalseTotal
if $added 0 0 0
111 }
112  
113 # Keep the repos around a little longer
114 $meta->register_hook(
115 0 ▶ clean_install => sub ($build) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
116 0 ▶ return unless keys %{ $build->runtime_prop->{repos} };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$build->runtime_prop->{"repos"};} 0 0 0
117 0 ▶ say 'Removing temporary repos from xrepo...' if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
118 0 _remove_repos( $r, [ keys %{ $build->runtime_prop->{repos} } ] );
119 }
120 0 );
121 0 my %packages;
122 my %errors;
123 0 for my $name ( $recipe->packages ) {
124  
125 # a per-package recipe version wins; otherwise the ambient plugin version (the
126 # alienfile `version` property) is the install-time default.
127 0 my $version = $recipe->version_for($name);
128 0 ▶ $version = $ambient{version} unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
129 0 my %opts = $recipe->opts_for( $name, %ambient );
130 0 my $info;
131 0 eval { $info = $r->install( $name, $version, %opts ) };
132 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
133 0 $errors{$name} = "$@";
134 0 next;
135 }
136 0 ▶ if ( ref $info && eval { $info->can('_data_printer') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info and eval { do { $info->can("_data_printer") } }) 0 0 0
Condition0%0/3
ref $info and eval { do { $info->can("_data_printer") } }
!ll&&!rl&&r
000
MC/DC0%0/2
ref $info and eval { do { $info->can("_data_printer") } }
ref $info eval { do { $info->can("_data_printer") } }
Truth table0%0/3
A and B
A= ref $infoB= eval { do { $info->can("_data_printer") } }
ABresult
0X0
100
111
137 0 $packages{$name} = $info->_data_printer(undef);
138 }
139 0 my $target = Path::Tiny->new($src)->child($name);
140 0 $target->mkpath;
141 0 try { $r->export( $name, $version, %opts, packagedir => $target->stringify ) }
142 catch ($e) {
143 0 ▶ $target->remove_tree if $target->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $target->exists 0 0 0
144 0 delete $packages{$name};
145 0 ▶ $errors{$name} = 'export failed: ' . ( $e || 'unknown error' );
Condition0%0/2
$e || 'unknown error'
l!l
00
MC/DC0%0/1
$e || 'unknown error'
$e
Truth table0%0/2
A
A= $e
Aresult
11
00
146 }
147 }
148  
149 # A failed sibling does not sink the surviving packages (partial installs are by
150 # design), but it must never be silent: prune export-failures from the success set,
151 # flag every failure in the returned install/runtime prop so consumers can see what
152 # is missing, and warn loudly.
153 0 my $spared = Path::Tiny->new($src)->child('xrepo.manifest');
154 0 $spared->spew_utf8( join "\n", grep { exists $packages{$_} } $recipe->packages );
155 0 ▶ if (%errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (%errors) 0 0 0
156 0 $build->runtime_prop->{errors} = { map { $_ => $errors{$_} } sort keys %errors };
157 0 my $failed = join ', ', sort keys %errors;
158 0 warn "Alien::Build::Plugin::Build::Xrepo: partial failure - these packages failed to install or export: $failed\n";
159 0 my ( $ok, $bad ) = ( scalar( keys %packages ), scalar( keys %errors ) );
160 0 ▶ warn "[xrepo] $ok packages installed, $bad failed (see install_prop->{xrepo}{errors} / runtime_prop->{errors} for details)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
161 if $verbose;
162 }
163 0 ▶ my $xrepo = $build->install_prop->{xrepo} ||= {};
Condition0%0/2
$build->install_prop->{"xrepo"} ||= {}
l!l
00
MC/DC0%0/1
$build->install_prop->{"xrepo"} ||= {}
$build->install_prop->{"xrepo"}
Truth table0%0/2
A
A= $build->install_prop->{"xrepo"}
Aresult
11
00
164 0 $xrepo->{packages} = \%packages;
165 0 $xrepo->{errors} = \%errors;
166 0 $xrepo->{download_dir} = $src;
167  
168 # The produced content is local (xrepo store exports, not a network fetch), so
169 # declare it to Alien::Build as a 'file' protocol download. Without
170 # download_details the extract step warns about a missing digest and a future
171 # Alien::Build will die by default.
172 0 my $dl = Path::Tiny->new('.')->absolute->stringify;
173 0 $build->install_prop->{download_detail}{$dl} = { protocol => 'file' };
174  
175 # Unregister the temporary local repos as soon as the installs/exports are done.
176 # Their paths live under the build's temp tree; leaving them registered makes
177 # later xrepo commands fail because the repositories no longer exist.
178 0 _remove_repos( $r, [ keys %{ $build->runtime_prop->{repos} } ] );
179 0 ▶ die 'Alien::Build::Plugin::Build::Xrepo: no packages installed successfully' unless %packages;
Branch: 1 branch
BranchTrueFalseTotal
unless %packages 0 0 0
180 }
181 0 );
182 $meta->default_hook(
183 0 ▶ extract => sub ( $build, $dest ) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
184 0 $self->__build($build);
185 0 my $xrepo = $build->install_prop->{xrepo};
186 die 'Alien::Build::Plugin::Build::Xrepo: the plugin download stage must run before extract'
187 0 ▶ unless $xrepo && defined $xrepo->{download_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $xrepo and defined $xrepo->{"download_dir"} 0 0 0
Condition0%0/3
$xrepo and defined $xrepo->{"download_dir"}
!ll&&!rl&&r
000
MC/DC0%0/2
$xrepo and defined $xrepo->{"download_dir"}
$xrepo defined $xrepo->{"download_dir"}
Truth table0%0/3
A and B
A= $xrepoB= defined $xrepo->{"download_dir"}
ABresult
0X0
100
111
188 0 my $src = Path::Tiny->new( $xrepo->{download_dir} );
189  
190 # The extract-hook contract makes the current working directory the staging
191 # scaffold: Alien::Build chdirs every extract into a fresh, empty TempDir and
192 # expects the content there (Alien::Build::Manual::PluginAuthor, "extract hook").
193 # $dest is the *source* for a file protocol for this plugin it is the same download
194 # temp dir $xrepo->{download_dir} points at, so copying into it would be a
195 # self-copy. Copy into the cwd scaffold, not $dest.
196 0 my $dst = Path::Tiny->new( Cwd::getcwd() );
197 0 for my $child ( $src->children ) {
198 0 ▶ next if $child->basename eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $child->basename eq "." 0 0 0
199 0 my $out = $dst->child( $child->basename );
200 0 ▶ $child->is_dir ? _copy_tree( $child, $out ) : $child->copy($out);
Branch: 1 branch
BranchTrueFalseTotal
$child->is_dir ? : 0 0 0
201 }
202 0 1;
203 }
204 0 );
205 $meta->default_hook(
206 0 ▶ build => sub ($build) {
Subroutine __ANON__: not called CC=12 SCAR=50.5
207 0 $self->__build($build);
208 0 my $xrepo = $build->install_prop->{xrepo};
209 die 'Alien::Build::Plugin::Build::Xrepo: the plugin download stage must run before build'
210 0 ▶ unless $xrepo && defined $xrepo->{download_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $xrepo and defined $xrepo->{"download_dir"} 0 0 0
Condition0%0/3
$xrepo and defined $xrepo->{"download_dir"}
!ll&&!rl&&r
000
MC/DC0%0/2
$xrepo and defined $xrepo->{"download_dir"}
$xrepo defined $xrepo->{"download_dir"}
Truth table0%0/3
A and B
A= $xrepoB= defined $xrepo->{"download_dir"}
ABresult
0X0
100
111
211 0 my $src = Path::Tiny->new( $xrepo->{download_dir} );
212 0 ▶ my $prefix = Path::Tiny->new( $build->install_prop->{prefix} ) || die 'Alien::Build::Plugin::Build::Xrepo: prefix is not set';
Condition0%0/2
'Path::Tiny'->new($build->install_prop->{'prefix'}) || die('Alien::Build::Plugin::Build::Xrepo: prefix is not set')
l!l
00
MC/DC0%0/1
'Path::Tiny'->new($build->install_prop->{'prefix'}) || die('Alien::Build::Plugin::Build::Xrepo: prefix is not set')
'Path::Tiny'->new($build->install_prop->{'prefix'})
Truth table0%0/2
A
A= 'Path::Tiny'->new($build->install_prop->{'prefix'})
Aresult
11
00
213 0 $prefix->mkpath;
214 0 my %exported;
215 0 for my $name ( $recipe->packages ) {
216 0 my $from = $src->child($name);
217 0 ▶ next unless -d $from;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $from 0 0 0
218 0 my $to = $prefix->child($name);
219 0 $to->mkpath;
220 0 my $content = _locate_content_dir($from);
221 0 ▶ my $base = $content || $from;
Condition0%0/3
$content || $from
l!l&&r!l&&!r
000
MC/DC0%0/2
$content || $from
$content $from
Truth table0%0/3
A || B
A= $contentB= $from
ABresult
1X1
011
000
222 0 for my $child ( $base->children ) {
223 0 my $dest = $to->child( $child->basename );
224 0 ▶ $child->is_dir ? _copy_tree( $child, $dest ) : $child->copy($dest);
Branch: 1 branch
BranchTrueFalseTotal
$child->is_dir ? : 0 0 0
225 }
226 0 $exported{$name} = $to->stringify;
227 0 my $bin = $to->child('bin');
228 0 ▶ next unless -d $bin;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $bin 0 0 0
229 0 my $destbin = $prefix->child('bin');
230 0 $destbin->mkpath;
231 0 for my $file ( $bin->children ) {
232 0 my $out = $destbin->child( $file->basename );
233 0 ▶ next if -e $out;
Branch: 1 branch
BranchTrueFalseTotal
if -e $out 0 0 0
234 0 $file->copy($out);
235 }
236 }
237 0 $xrepo->{exported} = \%exported;
238 }
239 0 );
240 $meta->register_hook(
241 0 ▶ gather_share => sub ($build) {
Subroutine __ANON__: not called CC=17 SCAR=57.2
242 0 $self->__build($build);
243 0 my $xrepo = $build->install_prop->{xrepo};
244 0 ▶ my $data = $xrepo && $xrepo->{packages};
Condition0%0/3
$xrepo && $xrepo->{'packages'}
!ll&&!rl&&r
000
MC/DC0%0/2
$xrepo && $xrepo->{'packages'}
$xrepo $xrepo->{'packages'}
Truth table0%0/3
A && B
A= $xrepoB= $xrepo->{'packages'}
ABresult
0X0
100
111
245 0 ▶ my $exp = $xrepo && $xrepo->{exported};
Condition0%0/3
$xrepo && $xrepo->{'exported'}
!ll&&!rl&&r
000
MC/DC0%0/2
$xrepo && $xrepo->{'exported'}
$xrepo $xrepo->{'exported'}
Truth table0%0/3
A && B
A= $xrepoB= $xrepo->{'exported'}
ABresult
0X0
100
111
246 0 ▶ die 'Alien::Build::Plugin::Build::Xrepo: no package data to gather; ' . 'did the plugin download/build stages run?'
Branch: 1 branch
BranchTrueFalseTotal
unless $data and %$data and $exp and %$exp 0 0 0
Condition0%0/9
$data and %$data and $exp and %$exp
!ll&&!rl&&r
000
$data and %$data and $exp
!ll&&!rl&&r
000
$data and %$data
!ll&&!rl&&r
000
MC/DC0%0/4
$data and %$data and $exp and %$exp
$data %$data $exp %$exp
Truth table0%0/5
A and B and C and D
A= $dataB= %$dataC= $expD= %$exp
ABCDresult
0XXX0
10XX0
110X0
11100
11111
247 unless $data && %$data && $exp && %$exp;
248 0 my $rp = $build->runtime_prop;
249 0 my @pkgs = $recipe->packages;
250 0 ▶ if ( my $p = _pkg_props( $data->{ $pkgs[0] }, $exp->{ $pkgs[0] } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = _pkg_props($$data{$pkgs[0]}, $$exp{$pkgs[0]})) 0 0 0
251 0 $rp->{$_} = $p->{$_} for qw( cflags cflags_static libs libs_static );
252 0 ▶ $rp->{version} = $p->{version} if defined $p->{version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p->{"version"} 0 0 0
253 0 ▶ $rp->{bin_dir} = _reroot_bins( $build, $p->{bin_dir} ) if $p->{bin_dir};
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"bin_dir"} 0 0 0
254 }
255 0 ▶ if ( @pkgs > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pkgs > 1) 0 0 0
256 0 my %alt;
257 0 for my $name ( @pkgs[ 1 .. $#pkgs ] ) {
258 0 my $p = _pkg_props( $data->{$name}, $exp->{$name} );
259 0 ▶ $p->{bin_dir} = _reroot_bins( $build, $p->{bin_dir} ) if $p && $p->{bin_dir};
Branch: 1 branch
BranchTrueFalseTotal
if $p and $p->{"bin_dir"} 0 0 0
Condition0%0/3
$p and $p->{"bin_dir"}
!ll&&!rl&&r
000
MC/DC0%0/2
$p and $p->{"bin_dir"}
$p $p->{"bin_dir"}
Truth table0%0/3
A and B
A= $pB= $p->{"bin_dir"}
ABresult
0X0
100
111
260 0 ▶ $alt{$name} = $p if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 0 0
261 }
262 0 ▶ $rp->{alt} = \%alt if keys %alt;
Branch: 1 branch
BranchTrueFalseTotal
if keys %alt 0 0 0
263 }
264 }
265 0 );
266 0 ▶ if ( $self->ffi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ffi) 0 0 0
267 $meta->register_hook(
268 0 ▶ gather_ffi => sub ($build) {
Subroutine __ANON__: not called CC=12 SCAR=50.5
269 0 $self->__build($build);
270 0 ▶ my $xrepo = $build->install_prop->{xrepo} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xrepo = $build->install_prop->{"xrepo"} or return 0 0 0
271 0 ▶ my $data = $xrepo->{packages} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $xrepo->{"packages"} or return 0 0 0
272 0 ▶ my $exp = $xrepo->{exported} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $exp = $xrepo->{"exported"} or return 0 0 0
273 0 my $rp = $build->runtime_prop;
274 0 my $primary = $data->{ ( $recipe->packages )[0] };
275 0 ▶ my @links = @{ $primary->{links} || [] };
Condition0%0/2
$primary->{'links'} || []
l!l
00
MC/DC0%0/1
$primary->{'links'} || []
$primary->{'links'}
Truth table0%0/2
A
A= $primary->{'links'}
Aresult
11
00
276 0 ▶ $rp->{ffi_name} ||= $links[0] if $links[0];
Branch: 1 branch
BranchTrueFalseTotal
if $links[0] 0 0 0
Condition0%0/3
$rp->{"ffi_name"} ||= $links[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$rp->{"ffi_name"} ||= $links[0]
$rp->{"ffi_name"} $links[0]
Truth table0%0/3
A ||= B
A= $rp->{"ffi_name"}B= $links[0]
ABresult
1X1
011
000
277 0 my @dyn;
278  
279 0 for my $dir ( values %$exp ) {
280 0 for my $sub (qw[bin lib]) {
281 0 my $d = Path::Tiny->new($dir)->child($sub);
282 0 ▶ next unless -d $d;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $d 0 0 0
283 0 push @dyn, map { $_->stringify } grep { $_->basename =~ /\.(?:dll|so|dylib)$/i } $d->children;
284 }
285 }
286 0 ▶ $rp->{dynamic_libs} ||= _reroot_dyn( $build, \@dyn ) if @dyn;
Branch: 1 branch
BranchTrueFalseTotal
if @dyn 0 0 0
Condition0%0/3
$rp->{"dynamic_libs"} ||= _reroot_dyn($build, \@dyn)
l!l&&r!l&&!r
000
MC/DC0%0/2
$rp->{"dynamic_libs"} ||= _reroot_dyn($build, \@dyn)
$rp->{"dynamic_libs"} _reroot_dyn($build, \@dyn)
Truth table0%0/3
A ||= B
A= $rp->{"dynamic_libs"}B= _reroot_dyn($build, \@dyn)
ABresult
1X1
011
000
287 }
288 0 );
289 }
290 0 my $intr = $meta->interpolator;
291 0 ▶ $intr->add_helper( xrepo => sub { Alien::Xmake->new->xrepo } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
292 0 ▶ $intr->add_helper( xmake => sub { Alien::Xmake->new->exe } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
293 $intr->add_helper(
294 0 ▶ xrepo_cflags => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
295 0 my $b = $self->__build;
296 0 ▶ defined $b ? ( $b->runtime_prop->{cflags} || '' ) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 0 0 0
Condition0%0/2
$b->runtime_prop->{"cflags"} or ""
l!l
00
MC/DC0%0/1
$b->runtime_prop->{"cflags"} or ""
$b->runtime_prop->{"cflags"}
Truth table0%0/2
A
A= $b->runtime_prop->{"cflags"}
Aresult
11
00
297 }
298 0 );
299 $intr->add_helper(
300 0 ▶ xrepo_libs => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
301 0 my $b = $self->__build;
302 0 ▶ defined $b ? ( $b->runtime_prop->{libs} || '' ) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 0 0 0
Condition0%0/2
$b->runtime_prop->{"libs"} or ""
l!l
00
MC/DC0%0/1
$b->runtime_prop->{"libs"} or ""
$b->runtime_prop->{"libs"}
Truth table0%0/2
A
A= $b->runtime_prop->{"libs"}
Aresult
11
00
303 }
304 0 );
305 $intr->add_helper(
306 0 ▶ xrepo_version => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
307 0 my $b = $self->__build;
308 0 ▶ defined $b ? ( $b->runtime_prop->{version} || '' ) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 0 0 0
Condition0%0/2
$b->runtime_prop->{"version"} or ""
l!l
00
MC/DC0%0/1
$b->runtime_prop->{"version"} or ""
$b->runtime_prop->{"version"}
Truth table0%0/2
A
A= $b->runtime_prop->{"version"}
Aresult
11
00
309 }
310 0 );
311 $intr->add_helper(
312 0 ▶ xrepo_dynamic_libs => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
313 0 my $b = $self->__build;
314 0 ▶ my $d = defined $b ? $b->runtime_prop->{dynamic_libs} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 0 0 0
315 0 ▶ return '' unless $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 0 0
316 0 join ' ', @$d;
317 }
318 0 );
319 0 $self;
320 }
321  
322 0 ▶ sub _remove_repos ( $engine, $names ) {
Subroutine _remove_repos: not called CC=6 SCAR=37.4
323 0 ▶ return unless $names && @$names;
Branch: 1 branch
BranchTrueFalseTotal
unless $names and @$names 0 0 0
Condition0%0/3
$names and @$names
!ll&&!rl&&r
000
MC/DC0%0/2
$names and @$names
$names @$names
Truth table0%0/3
A and B
A= $namesB= @$names
ABresult
0X0
100
111
324 0 ▶ if ( !$engine->can('rm_repo') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($engine->can("rm_repo")) 0 0 0
325 0 my $left = join ', ', @$names;
326 0 warn "Alien::Build::Plugin::Build::Xrepo: engine does not support rm_repo; " . "temporary repo(s) $left left registered\n";
327 0 return;
328 }
329 0 for my $name ( reverse @$names ) {
330 0 eval { $engine->rm_repo($name) };
331 0 ▶ warn "Alien::Build::Plugin::Build::Xrepo: could not remove temporary repo $name: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
332 }
333 0 return;
334 }
335  
336 0 ▶ sub _reroot_bins ( $build, $bins //= () ) {
Subroutine _reroot_bins: not called CC=5 SCAR=34.0
337 0 ▶ return $bins unless $bins;
Branch: 1 branch
BranchTrueFalseTotal
unless $bins 0 0 0
338 0 my $root = $build->install_prop->{prefix};
339 0 my $rr = $build->runtime_prop->{prefix};
340 0 ▶ return $bins unless defined $root && defined $rr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root and defined $rr 0 0 0
Condition0%0/3
defined $root and defined $rr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $root and defined $rr
defined $root defined $rr
Truth table0%0/3
A and B
A= defined $rootB= defined $rr
ABresult
0X0
100
111
341 [ map {
342 0 my $rel = File::Spec->abs2rel( $_, $root );
343 0 File::Spec->catdir( $rr, $rel );
344 } @$bins
345 ];
346 }
347  
348 0 ▶ sub _reroot_dyn ( $build, $dyn ) {
Subroutine _reroot_dyn: not called CC=5 SCAR=34.0
349 0 ▶ return $dyn unless $dyn && @$dyn;
Branch: 1 branch
BranchTrueFalseTotal
unless $dyn and @$dyn 0 0 0
Condition0%0/3
$dyn and @$dyn
!ll&&!rl&&r
000
MC/DC0%0/2
$dyn and @$dyn
$dyn @$dyn
Truth table0%0/3
A and B
A= $dynB= @$dyn
ABresult
0X0
100
111
350 0 my $root = $build->install_prop->{prefix};
351 0 my $rr = $build->runtime_prop->{prefix};
352 0 ▶ return $dyn unless defined $root && defined $rr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root and defined $rr 0 0 0
Condition0%0/3
defined $root and defined $rr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $root and defined $rr
defined $root defined $rr
Truth table0%0/3
A and B
A= defined $rootB= defined $rr
ABresult
0X0
100
111
353 [ map {
354 0 my $rel = File::Spec->abs2rel( $_, $root );
355 0 File::Spec->catdir( $rr, $rel );
356 } @$dyn
357 ];
358 }
359  
360 0 ▶ sub _copy_tree ( $src, $dst ) {
Subroutine _copy_tree: not called CC=3 SCAR=24.8
361 0 $dst->mkpath;
362 0 for my $child ( $src->children ) {
363 0 my $out = $dst->child( $child->basename );
364 0 ▶ $child->is_dir ? _copy_tree( $child, $out ) : $child->copy($out);
Branch: 1 branch
BranchTrueFalseTotal
$child->is_dir ? : 0 0 0
365 }
366 0 1;
367 }
368  
369 0 ▶ sub _locate_content_dir ($root) {
Subroutine _locate_content_dir: not called CC=9 SCAR=45.0
370 0 my $found;
371 0 my $depth = -1;
372 0 my @stack = ( [ $root, 0 ] );
373 0 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
374 0 my ( $dir, $d ) = @{ shift @stack };
375 0 my @kids = $dir->children;
376 0 my @with;
377 0 for my $k (@kids) {
378 0 ▶ next unless $k->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $k->is_dir 0 0 0
379 0 ▶ next unless $k->basename =~ /^(?:include|lib|bin)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k->basename =~ /^(?:include|lib|bin)$/u 0 0 0
380 0 ▶ next unless _has_entries($k);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_entries($k) 0 0 0
381 0 push @with, $k;
382 }
383 0 ▶ if ( @with && $d > $depth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@with and $d > $depth) 0 0 0
Condition0%0/3
@with and $d > $depth
!ll&&!rl&&r
000
MC/DC0%0/2
@with and $d > $depth
@with $d > $depth
Truth table0%0/3
A and B
A= @withB= $d > $depth
ABresult
0X0
100
111
384 0 $found = $dir;
385 0 $depth = $d;
386 }
387 0 ▶ push @stack, map { [ $_, $d + 1 ] } grep { $_->is_dir && $_->basename !~ /^(?:include|lib|bin)$/ } @kids;
Condition0%0/3
$_->is_dir && !($_->basename =~ /^(?:include|lib|bin)$/u)
!ll&&!rl&&r
000
MC/DC0%0/2
$_->is_dir && !($_->basename =~ /^(?:include|lib|bin)$/u)
$_->is_dir !($_->basename =~ /^(?:include|lib|bin)$/u)
Truth table0%0/3
A && not(B)
A= $_->is_dirB= !($_->basename =~ /^(?:include|lib|bin)$/u)
ABresult
0X0
100
111
388 }
389 0 return $found;
390 }
391 0 ▶ sub _has_entries ($dir) { scalar @{ [ $dir->children ] }; }
Subroutine _has_entries: not called CC=1 SCAR=6.9
392  
393 0 ▶ sub _which_in_path ($exec) {
Subroutine _which_in_path: not called CC=8 SCAR=42.8
394 0 ▶ my $sep = ( $^O eq 'MSWin32' ) ? ';' : ':';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
395 0 ▶ my @exts = ( $^O eq 'MSWin32' ) ? qw(.exe .bat .cmd) : ('');
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
396 0 for my $dir ( split /\Q$sep\E/, $ENV{PATH} ) {
397 0 ▶ next if !length $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless length $dir 0 0 0
398 0 for my $ext (@exts) {
399 0 my $cand = File::Spec->catfile( $dir, "$exec$ext" );
400 0 ▶ return $cand if -e $cand && !-d $cand;
Branch: 1 branch
BranchTrueFalseTotal
if -e $cand and not -d $cand 0 0 0
Condition0%0/3
-e $cand and not -d $cand
!ll&&!rl&&r
000
MC/DC0%0/2
-e $cand and not -d $cand
-e $cand not -d $cand
Truth table0%0/3
A and not(B)
A= -e $candB= not -d $cand
ABresult
0X0
100
111
401 }
402 }
403 0 return undef;
404 }
405  
406 0 ▶ sub _pkg_props ( $info, $dir ) {
Subroutine _pkg_props: not called CC=9 SCAR=45.0
407 0 ▶ return undef unless $info && $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $info and $dir 0 0 0
Condition0%0/3
$info and $dir
!ll&&!rl&&r
000
MC/DC0%0/2
$info and $dir
$info $dir
Truth table0%0/3
A and B
A= $infoB= $dir
ABresult
0X0
100
111
408 0 my $t = Path::Tiny->new($dir);
409 0 my @inc = ();
410 0 my @ldirs = ();
411 0 my @bins = ();
412 0 ▶ push @inc, $t->child('include')->stringify if -d $t->child('include');
Branch: 1 branch
BranchTrueFalseTotal
if -d $t->child("include") 0 0 0
413 0 ▶ push @ldirs, $t->child('lib')->stringify if -d $t->child('lib');
Branch: 1 branch
BranchTrueFalseTotal
if -d $t->child("lib") 0 0 0
414 0 ▶ push @bins, $t->child('bin')->stringify if -d $t->child('bin');
Branch: 1 branch
BranchTrueFalseTotal
if -d $t->child("bin") 0 0 0
415 0 ▶ push @inc, $t->stringify if !@inc;
Branch: 1 branch
BranchTrueFalseTotal
unless @inc 0 0 0
416 0 ▶ push @ldirs, $t->stringify if !@ldirs;
Branch: 1 branch
BranchTrueFalseTotal
unless @ldirs 0 0 0
417 0 my $cflags = join ' ', map {"-I$_"} @inc;
418 0 my $libs = join ' ', map {"-L$_"} @ldirs;
419 0 ▶ $libs .= ' ' . join ' ', map {"-l$_"} @{ $info->{links} || [] };
Condition0%0/2
$info->{'links'} || []
l!l
00
MC/DC0%0/1
$info->{'links'} || []
$info->{'links'}
Truth table0%0/2
A
A= $info->{'links'}
Aresult
11
00
420 0 { cflags => $cflags, cflags_static => $cflags, libs => $libs, libs_static => $libs, version => $info->{version}, bin_dir => \@bins };
421 }
422 };
423 #
424 1 1;
↑ Summary