builder/Affix/Builder.pm

filter: Statementstmt 33.8% 142 / 420 Branchbran 12.9% 31 / 240 Conditioncond 17.5% 19 / 108 MC/DCmcdc 1.5% 1 / 64 Subroutinesub 57.5% 23 / 40 Podpod 0.0% 0 / 18 totaltotal 24.2% 216 / 890 CC 172 SCAR 57.5
CC
172
Cov
25%
step_fuzz
756.0
step_infix
756.0
step_affix
650.0
CRAP 313.3
↑ Summary blib/lib/Affix/Build.pm »
1 # Based on Module::Build::Tiny which is copyright (c) 2011 by Leon Timmermans, David Golden.
2 # Module::Build::Tiny is free software; you can redistribute it and/or modify it under
3 # the same terms as the Perl 5 programming language system itself.
4 1 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 class #
8 1 Affix::Builder {
9 1 ▶ use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use ExtUtils::Install qw[pm_to_blib install];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use ExtUtils::InstallPaths 0.002;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use File::Basename qw[basename dirname];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use File::Path qw[make_path remove_tree];
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use File::Spec::Functions qw[catfile catdir rel2abs abs2rel splitdir curdir];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use JSON::PP 2 qw[encode_json decode_json];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use File::Temp qw[tempfile];
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use Getopt::Long 2.36 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Not in CORE
20 1 ▶ use Path::Tiny qw[path cwd];
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use ExtUtils::Helpers 0.028 qw[make_executable split_like_shell detildefy];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # infix and Affix stuff
24 1 ▶ use Config qw[%Config];
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 field $force : param //= 0;
26 1 field $debug : param //= 0;
27 1 field $libver;
28 1 field $cflags;
29 1 field $ldflags;
30 1 field $cppver = 'c++17'; # https://en.wikipedia.org/wiki/C%2B%2B20#Compiler_support
31 1 field $cver = 'c17'; # https://en.wikipedia.org/wiki/C17_(C_standard_revision)
32 1 field $make : param //= $Config{make} || 'dmake';
33 #
34 1 field $action : param //= 'build';
35 1 field $meta : reader = CPAN::Meta->load_file('META.json');
36  
37 # Params to Build script
38 1 field $install_base : param //= '';
39 1 field $installdirs : param //= '';
40 1 field $install_path : param //= {};
41 1 field $uninst : param //= 0; # Make more sense to have a ./Build uninstall command but...
42 1 field $create_packlist : param //= 1;
43 1 field $install_paths : param //= undef;
44 1 field $verbose : param(v) //= 0;
45 1 field $dry_run : param //= 0;
46 1 field $pureperl : param //= 0;
47 1 field $jobs : param //= 1;
48 1 field $destdir : param //= '';
49 1 field $prefix : param //= '';
50 1 field $config : param //= {};
51 1 field $extra_compiler_flags : param //= '';
52 1 field $extra_linker_flags : param //= '';
53 #
54 1 ▶ ADJUST {
Subroutine __ANON__: called CC=18 SCAR=37.1
55 1 ▶ die "No META information provided\n" unless -e 'META.json';
Branch: 1 branch
BranchTrueFalseTotal
unless -e "META.json" 0 1 1
56 1 ▶ die "OS unsupported: Affix requires a 64-bit architecture\n" if $Config{ptrsize} < 8;
Branch: 1 branch
BranchTrueFalseTotal
if $Affix::Builder::Config{"ptrsize"} < 8 0 1 1
57 1 ▶ $_ = detildefy($_) for grep { defined && length } $install_base, $destdir, $prefix, values %{$install_path};
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
030
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
58 1 ▶ $install_paths //= $self->_build_install_paths();
Condition33%1/3
$install_paths //= $self->_build_install_paths
l!l&&r!l&&!r
010
MC/DC0%0/2
$install_paths //= $self->_build_install_paths
$install_paths $self->_build_install_paths
Truth table33%1/3
A //= B
A= $install_pathsB= $self->_build_install_paths
ABresult
1X1
011
000
59  
60 # Configure Flags
61 1 my $is_bsd = $^O =~ /bsd/i;
62 1 my $is_win = $^O =~ /MSWin32/i;
63 1 my $is_sun = $^O =~ /(solaris|sunos)/i;
64 1 ▶ $cflags = ( $is_bsd || $is_sun ) ? '' : '-fPIC ';
Branch: 1 branch
BranchTrueFalseTotal
$is_bsd || $is_sun ? : 0 1 1
Condition33%1/3
$is_bsd or $is_sun
l!l&&r!l&&!r
001
MC/DC0%0/2
$is_bsd or $is_sun
$is_bsd $is_sun
Truth table33%1/3
A or B
A= $is_bsdB= $is_sun
ABresult
1X1
011
000
65 1 ▶ $ldflags = ( $is_bsd || $is_sun ) ? '' : ' -flto=auto ';
Branch: 1 branch
BranchTrueFalseTotal
$is_bsd || $is_sun ? : 0 1 1
Condition33%1/3
$is_bsd or $is_sun
l!l&&r!l&&!r
001
MC/DC0%0/2
$is_bsd or $is_sun
$is_bsd $is_sun
Truth table33%1/3
A or B
A= $is_bsdB= $is_sun
ABresult
1X1
011
000
66 1 ▶ $cflags .= ' -D__EXTENSIONS__ -D_LARGEFILE64_SOURCE' if $is_sun;
Branch: 1 branch
BranchTrueFalseTotal
if $is_sun 0 1 1
67 1 ▶ if ( $debug > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($debug > 0) { } 0 1 1
elsif (not $is_win) { } 1 0 1
68 0 $cflags
69 .= '-DDEBUG=' .
70 $debug .
71 ' -g3 -gdwarf-4 ' .
72 ' -Wno-deprecated -pipe ' .
73 ' -Wall -Wextra -Wpedantic -Wvla -Wnull-dereference ' .
74 ' -Wswitch-enum -Wduplicated-cond ' .
75 ' -Wduplicated-branches';
76 0 ▶ $cflags .= ' -fvar-tracking-assignments' unless $Config{osname} eq 'darwin';
Branch: 1 branch
BranchTrueFalseTotal
unless $Affix::Builder::Config{"osname"} eq "darwin" 0 0 0
77 }
78 elsif ( !$is_win ) {
79 1 $cflags .= ' -DNDEBUG -DBOOST_DISABLE_ASSERTS -O3 -ftree-vectorize -ffast-math -fno-align-functions -fno-omit-frame-pointer';
80 1 ▶ $cflags .= ' -flto' unless ( $is_bsd || $is_sun );
Branch: 1 branch
BranchTrueFalseTotal
unless $is_bsd or $is_sun 1 0 1
Condition33%1/3
$is_bsd or $is_sun
l!l&&r!l&&!r
001
MC/DC0%0/2
$is_bsd or $is_sun
$is_bsd $is_sun
Truth table33%1/3
A or B
A= $is_bsdB= $is_sun
ABresult
1X1
011
000
81 }
82  
83 # Threading support (Critical for shm_open/librt on Linux)
84 1 ▶ if ( !$is_win ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_win) 1 0 1
85 1 $cflags .= ' -pthread';
86 1 $ldflags .= ' -pthread';
87 1 ▶ $ldflags .= ' -Wl,-z,nobtcfi' if $^O eq 'openbsd'; # XXX - Temp BTI/IBT workaround https://www.openbsd.org/innovations.html
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "openbsd" 0 1 1
88 }
89 }
90 0 ▶ method write_file( $filename, $content ) { path($filename)->spew_raw($content) or die "Could not open $filename: $!\n" }
Subroutine write_file: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
path($filename)->spew_raw($content) or die "Could not open ${filename}: $!\n" 0 0 0
91 0 ▶ method read_file ($filename) { path($filename)->slurp_utf8 or die "Could not open $filename: $!\n" }
Subroutine read_file: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
path($filename)->slurp_utf8 or die "Could not open ${filename}: $!\n" 0 0 0
92  
93 0 ▶ method step_build() {
Subroutine step_build: not called CC=2 SCAR=17.9
Pod undocumented
94 0 $self->step_affix;
95 0 my %modules = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pm$/, 'lib' );
96 0 my %docs = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pod$/, 'lib' );
97 0 my %scripts = map { $_ => catfile( 'blib', $_ ) } find( qr/(?:)/, 'script' );
98 0 my %sdocs = map { $_ => delete $scripts{$_} } grep {/.pod$/} keys %scripts;
99 0 my %dist_shared = map { $_ => catfile( qw[blib lib auto share dist], $meta->name, abs2rel( $_, 'share' ) ) } find( qr/(?:)/, 'share' );
100 0 my %module_shared = map { $_ => catfile( qw[blib lib auto share module], abs2rel( $_, 'module-share' ) ) } find( qr/(?:)/, 'module-share' );
101 0 pm_to_blib( { %modules, %docs, %scripts, %dist_shared, %module_shared }, catdir(qw[blib lib auto]) );
102 0 make_executable($_) for values %scripts;
103 0 make_path( catdir(qw[blib arch]), { chmod => 0755, verbose => $verbose } );
104 0 0;
105 }
106  
107 0 ▶ method _clean_objects() {
Subroutine _clean_objects: not called CC=2 SCAR=17.9
108 0 my $lib_dir = path('lib');
109 0 my @objs;
110 $lib_dir->visit(
111 0 ▶ sub ( $path, $state ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
112 0 ▶ push @objs, $path if $path->is_file && $path =~ /\.(?:o|obj)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_file and $path =~ /\.(?:o|obj)\z/iu 0 0 0
Condition0%0/3
$path->is_file and $path =~ /\.(?:o|obj)\z/iu
!ll&&!rl&&r
000
MC/DC0%0/2
$path->is_file and $path =~ /\.(?:o|obj)\z/iu
$path->is_file $path =~ /\.(?:o|obj)\z/iu
Truth table0%0/3
A and B
A= $path->is_fileB= $path =~ /\.(?:o|obj)\z/iu
ABresult
0X0
100
111
113 },
114 0 { recurse => 1 }
115 );
116 0 remove_tree( $_, { verbose => $verbose } ) for @objs;
117 0 0;
118 }
119  
120 0 ▶ method step_clean() {
Subroutine step_clean: not called CC=2 SCAR=17.9
Pod undocumented
121 0 remove_tree( $_, { verbose => $verbose } ) for qw[blib temp];
122 0 $self->_clean_objects;
123 0 0;
124 }
125  
126 0 ▶ method step_install() {
Subroutine step_install: not called CC=2 SCAR=17.9
Pod undocumented
127 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
128 0 my %res;
129 0 install(
130 [ from_to => $install_paths->install_map,
131 verbose => $verbose,
132 always_copy => 1,
133 dry_run => $dry_run,
134 uninstall_shadows => $uninst,
135 result => \%res
136 ]
137 );
138  
139 # In the future, I might check the values of %res according to https://metacpan.org/pod/ExtUtils::Install#install
140 0 0;
141 }
142  
143 0 ▶ method step_realclean () {
Subroutine step_realclean: not called CC=2 SCAR=17.9
Pod undocumented
144 0 remove_tree( $_, { verbose => $verbose } ) for qw[blib temp Build _build_params MYMETA.yml MYMETA.json];
145 0 remove_tree( 'infix/build_lib', { verbose => $verbose } );
146 0 $self->_clean_objects;
147 0 0;
148 }
149  
150 1 ▶ method step_test(%args) {
Subroutine step_test: called CC=5 SCAR=18.1
Pod undocumented
151 1 ▶ $jobs = $args{j} // $args{jobs} // $jobs;
Condition33%2/6
($args{"j"} // $args{"jobs"}) // $jobs
l!l&&r!l&&!r
010
$args{"j"} // $args{"jobs"}
l!l&&r!l&&!r
001
MC/DC0%0/3
($args{"j"} // $args{"jobs"}) // $jobs
$args{"j"} $args{"jobs"} $jobs
Truth table25%1/4
A // B // C
A= $args{"j"}B= $args{"jobs"}C= $jobs
ABCresult
1XX1
01X1
0011
0000
152 1 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 1 1
153 1 require TAP::Harness::Env;
154 my %test_args = (
155 ( verbosity => $verbose ),
156 ( $jobs ? ( jobs => $jobs ) : () ),
157 ( color => -t STDOUT ),
158 1 ▶ lib => [ map { rel2abs( catdir( 'blib', $_ ) ) } qw[arch lib] ]
Branch: 1 branch
BranchTrueFalseTotal
$jobs ? : 1 0 1
159 );
160 1 TAP::Harness::Env->create( \%test_args )->runtests( sort map { $_->stringify } find( qr/\.t$/, 't' ) )->has_errors;
161 }
162  
163 0 ▶ method step_fuzz(@args) {
Subroutine step_fuzz: not called CC=27 SCAR=66.3
Pod undocumented
164 0 my %args = @args;
165 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
166  
167 # Fuzz config via env vars (or caller can pass %args)
168 0 ▶ my $max_iter = $ENV{FUZZ_MAX_ITER} // $args{iter} // 10000;
Condition0%0/5
($ENV{"FUZZ_MAX_ITER"} // $args{"iter"}) // 10000
l!l
00
$ENV{"FUZZ_MAX_ITER"} // $args{"iter"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($ENV{"FUZZ_MAX_ITER"} // $args{"iter"}) // 10000
$ENV{"FUZZ_MAX_ITER"} $args{"iter"}
Truth table0%0/3
A // B
A= $ENV{"FUZZ_MAX_ITER"}B= $args{"iter"}
ABresult
1X1
011
000
169 0 ▶ my $timeout = $ENV{FUZZ_TIMEOUT} // $args{timeout} // 5;
Condition0%0/5
($ENV{"FUZZ_TIMEOUT"} // $args{"timeout"}) // 5
l!l
00
$ENV{"FUZZ_TIMEOUT"} // $args{"timeout"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($ENV{"FUZZ_TIMEOUT"} // $args{"timeout"}) // 5
$ENV{"FUZZ_TIMEOUT"} $args{"timeout"}
Truth table0%0/3
A // B
A= $ENV{"FUZZ_TIMEOUT"}B= $args{"timeout"}
ABresult
1X1
011
000
170 0 ▶ my $verbose_fuzz = $ENV{FUZZ_VERBOSE} // $args{verbose} // 0;
Condition0%0/5
($ENV{"FUZZ_VERBOSE"} // $args{"verbose"}) // 0
l!l
00
$ENV{"FUZZ_VERBOSE"} // $args{"verbose"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($ENV{"FUZZ_VERBOSE"} // $args{"verbose"}) // 0
$ENV{"FUZZ_VERBOSE"} $args{"verbose"}
Truth table0%0/3
A // B
A= $ENV{"FUZZ_VERBOSE"}B= $args{"verbose"}
ABresult
1X1
011
000
171  
172 # Determine which Perl targets to run
173 0 my @targets;
174 0 ▶ if ( $args{all} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($args{'all'}) { } 0 0 0
elsif ($args{'smoke'}) { } 0 0 0
elsif ($args{'target'}) { } 0 0 0
175 0 @targets = qw[wrap grammar register cross compile];
176 }
177 elsif ( $args{smoke} ) {
178 0 @targets = qw[wrap grammar register cross];
179 }
180 elsif ( $args{target} ) {
181 0 ▶ @targets = ref $args{target} ? @{ $args{target} } : ( $args{target} );
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'target'} ? : 0 0 0
182 }
183 else {
184 0 @targets = qw[wrap grammar register cross];
185 }
186  
187 # Perl fuzz target metadata
188 0 my %perl_targets = (
189 wrap => { script => 'fuzz_wrap_type_sig.pl', desc => 'Affix::Wrap::Type->parse()', needs_lib => 1 },
190 grammar => { script => 'fuzz_grammar_mutate.pl', desc => 'Grammar-aware C sig mutations', needs_lib => 1, extra_inc => 1 },
191 register => { script => 'fuzz_register_types.pl', desc => 'Affix::_typedef() — C parser direct', needs_lib => 1 },
192 cross => { script => 'fuzz_cross_boundary.pl', desc => 'Cross-boundary Perl->C->JIT', needs_lib => 1 },
193 compile => { script => 'fuzz_compile_ok.pl', desc => 'compile_ok() C compilation', needs_lib => 1 },
194 shared => { script => 'fuzz_shared_lib.pl', desc => 'Compile→load→affix→call→verify ABI', needs_lib => 1 }
195 );
196  
197 # C fuzz targets (delegate to infix/build.pl)
198 0 my %c_targets = (
199 signature => 'Parser crashes + arena stress',
200 abi => 'ABI classification',
201 types => 'Type generator bugs',
202 roundtrip => 'Type->String->Type consistency',
203 trampoline => 'JIT trampoline creation',
204 direct => 'Direct marshalling JIT'
205 );
206 0 my $fuzz_dir = path('fuzz');
207 0 ▶ die "fuzz/ directory not found\n" unless -d $fuzz_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $fuzz_dir 0 0 0
208 0 my $failures = 0;
209 0 ▶ my $iters = $args{smoke} ? 100 : $max_iter;
Branch: 1 branch
BranchTrueFalseTotal
$args{'smoke'} ? : 0 0 0
210 0 ▶ my $to = $args{smoke} ? 3 : $timeout;
Branch: 1 branch
BranchTrueFalseTotal
$args{'smoke'} ? : 0 0 0
211  
212 # Run Perl fuzz targets via TAP::Harness for proper TAP output
213 0 require TAP::Harness::Env;
214 0 my @fuzz_scripts;
215 0 for my $name (@targets) {
216 0 ▶ my $target = $perl_targets{$name} // do { warn "Unknown Perl fuzz target: $name\n"; $failures++; next };
Condition0%0/3
$perl_targets{$name} // do { warn "Unknown Perl fuzz target: $name\n"; ++$failures; next }
l!l&&r!l&&!r
000
MC/DC0%0/2
$perl_targets{$name} // do { warn "Unknown Perl fuzz target: $name\n"; ++$failures; next }
$perl_targets{$name} do { warn "Unknown Perl fuzz target: $name\n"; ++$failures; next }
Truth table0%0/3
A // B
A= $perl_targets{$name}B= do { warn "Unknown Perl fuzz target: $name\n"; ++$failures; next }
ABresult
1X1
011
000
217 0 my $script = $fuzz_dir->child( $target->{script} );
218 0 ▶ unless ( -f $script ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $script) 0 0 0
219 0 warn "Fuzz script not found: $script\n";
220 0 $failures++;
221 0 next;
222 }
223 0 say "=" x 60;
224 0 say "Fuzzing: $target->{desc}";
225 0 say " Script: $target->{script}";
226 0 say " Iterations: $iters, Timeout: ${to}s";
227 0 say "=" x 60;
228 0 push @fuzz_scripts, $script->stringify;
229 }
230 0 ▶ if (@fuzz_scripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fuzz_scripts) 0 0 0
231 0 local $ENV{FUZZ_MAX_ITER} = $iters;
232 0 local $ENV{FUZZ_TIMEOUT} = $to;
233 0 local $ENV{FUZZ_VERBOSE} = $verbose_fuzz;
234 0 my %harness_args = ( ( verbosity => $verbose ), ( color => -t STDOUT ), lib => [ map { rel2abs( catdir( 'blib', $_ ) ) } qw[arch lib] ] );
235 0 my $harness = TAP::Harness::Env->create( \%harness_args );
236 0 my $aggr = $harness->runtests( sort @fuzz_scripts );
237 0 ▶ $failures++ if $aggr->has_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $aggr->has_errors 0 0 0
238 0 say "";
239 }
240  
241 # Smoke test: also quick-build C targets if available
242 0 ▶ if ( $args{smoke} || $args{all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"smoke"} or $args{"all"}) 0 0 0
Condition0%0/3
$args{"smoke"} or $args{"all"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"smoke"} or $args{"all"}
$args{"smoke"} $args{"all"}
Truth table0%0/3
A or B
A= $args{"smoke"}B= $args{"all"}
ABresult
1X1
011
000
243 0 my $build_pl = path('infix/build.pl');
244 0 ▶ if ( -f $build_pl ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $build_pl) { } 0 0 0
245 0 for my $name ( sort keys %c_targets ) {
246 0 say "=" x 60;
247 0 say "Building C fuzz target: fuzz:$name";
248 0 say " $c_targets{$name}";
249 0 say "=" x 60;
250 0 my $exit = system( $^X, $build_pl->stringify, "fuzz:$name" );
251 0 ▶ $failures++ if $exit != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $exit != 0 0 0 0
252 0 say "";
253 }
254 }
255 else {
256 0 say "Skipping C fuzz targets (infix/build.pl not found)";
257 }
258 }
259 0 say "=" x 60;
260 0 ▶ if ($failures) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failures) { } 0 0 0
261 0 say "FAILED: $failures target(s) reported crashes or build errors";
262 }
263 else {
264 0 say "All fuzz targets clean.";
265 }
266 0 ▶ return $failures > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$failures > 0 ? : 0 0 0
267 }
268 1 my @cli_options = qw[
269 install_base=s
270 install_path=s%
271 installdirs=s
272 destdir=s
273 prefix=s
274 config=s%
275 uninst:1
276 v|verbose:1
277 dry_run:1
278 pureperl|pureperl-only|pureperl_only:1
279 create_packlist=i
280 jobs|j=i
281 make=s
282 force:1
283 debug:1
284 extra_compiler_flags=s
285 extra_linker_flags=s
286 ];
287 1 my @fuzz_options = qw[
288 all:1
289 smoke:1
290 target=s@
291 iter=i
292 timeout=i
293 ];
294 1 my %bare_opt_keys = map { $_ => 1 } qw[
295 install_base install_path installdirs destdir prefix config
296 uninst v verbose dry_run pureperl pureperl-only pureperl_only
297 create_packlist jobs j make force debug
298 extra_compiler_flags extra_linker_flags
299 all smoke target iter timeout
300 ];
301 1 my %fuzz_opt_keys = map { $_ => 1 } qw[all smoke target iter timeout];
302  
303 1 ▶ sub _parse_args (@sources) {
Subroutine _parse_args: called CC=8 SCAR=21.2
304 1 my %opt;
305 1 my $parser = Getopt::Long::Parser->new( config => ['pass_through'] );
306 1 for my $src (@sources) {
307 3 ▶ next unless ref $src eq 'ARRAY' && @$src;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $src eq "ARRAY" and @$src 2 1 3
Condition66%2/3
ref $src eq "ARRAY" and @$src
!ll&&!rl&&r
021
MC/DC50%1/2
ref $src eq "ARRAY" and @$src
ref $src eq "ARRAY" @$src
Truth table66%2/3
A and B
A= ref $src eq "ARRAY"B= @$src
ABresult
0X0
100
111
308 1 ▶ my @args = map { /\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/s && $bare_opt_keys{$1} ? "--$1=$2" : $_ } @$src;
Branch: 1 branch
BranchTrueFalseTotal
/\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/su && $bare_opt_keys{$1} ? : 0 4 4
Condition66%2/3
/\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/su and $bare_opt_keys{$1}
!ll&&!rl&&r
310
MC/DC0%0/2
/\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/su and $bare_opt_keys{$1}
/\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/su $bare_opt_keys{$1}
Truth table66%2/3
A and B
A= /\A([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)\z/suB= $bare_opt_keys{$1}
ABresult
0X0
100
111
309 1 $parser->getoptionsfromarray( \@args, \%opt, @cli_options, @fuzz_options );
310 }
311 1 my %fuzz_opt;
312 1 for my $k ( keys %fuzz_opt_keys ) {
313 5 ▶ $fuzz_opt{$k} = delete $opt{$k} if exists $opt{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{$k} 0 5 5
314 }
315 1 return ( \%opt, \%fuzz_opt );
316 }
317  
318 1 ▶ method _build_install_paths() {
Subroutine _build_install_paths: called CC=15 SCAR=35.1
319 1 my %ip_args = ( dist_name => $meta->name );
320 1 ▶ $ip_args{install_base} = $install_base if defined $install_base && length $install_base;
Branch: 1 branch
BranchTrueFalseTotal
if defined $install_base and length $install_base 0 1 1
Condition33%1/3
defined $install_base and length $install_base
!ll&&!rl&&r
010
MC/DC0%0/2
defined $install_base and length $install_base
defined $install_base length $install_base
Truth table33%1/3
A and B
A= defined $install_baseB= length $install_base
ABresult
0X0
100
111
321 1 ▶ $ip_args{installdirs} = $installdirs if defined $installdirs && length $installdirs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $installdirs and length $installdirs 0 1 1
Condition33%1/3
defined $installdirs and length $installdirs
!ll&&!rl&&r
010
MC/DC0%0/2
defined $installdirs and length $installdirs
defined $installdirs length $installdirs
Truth table33%1/3
A and B
A= defined $installdirsB= length $installdirs
ABresult
0X0
100
111
322 1 ▶ $ip_args{destdir} = $destdir if defined $destdir && length $destdir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $destdir and length $destdir 0 1 1
Condition33%1/3
defined $destdir and length $destdir
!ll&&!rl&&r
010
MC/DC0%0/2
defined $destdir and length $destdir
defined $destdir length $destdir
Truth table33%1/3
A and B
A= defined $destdirB= length $destdir
ABresult
0X0
100
111
323 1 ▶ $ip_args{prefix} = $prefix if defined $prefix && length $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prefix and length $prefix 0 1 1
Condition33%1/3
defined $prefix and length $prefix
!ll&&!rl&&r
010
MC/DC0%0/2
defined $prefix and length $prefix
defined $prefix length $prefix
Truth table33%1/3
A and B
A= defined $prefixB= length $prefix
ABresult
0X0
100
111
324 1 ▶ $ip_args{install_path} = $install_path if ref $install_path eq 'HASH' && %$install_path;
Branch: 1 branch
BranchTrueFalseTotal
if ref $install_path eq "HASH" and %$install_path 0 1 1
Condition33%1/3
ref $install_path eq "HASH" and %$install_path
!ll&&!rl&&r
010
MC/DC0%0/2
ref $install_path eq "HASH" and %$install_path
ref $install_path eq "HASH" %$install_path
Truth table33%1/3
A and B
A= ref $install_path eq "HASH"B= %$install_path
ABresult
0X0
100
111
325 1 ▶ $ip_args{create_packlist} = $create_packlist if defined $create_packlist;
Branch: 1 branch
BranchTrueFalseTotal
if defined $create_packlist 1 0 1
326 1 ▶ $ip_args{verbose} = $verbose if defined $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if defined $verbose 1 0 1
327  
328 1 ▶ if ( ref $config eq 'HASH' && %$config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config eq "HASH" and %$config) 1 0 1
Condition33%1/3
ref $config eq "HASH" and %$config
!ll&&!rl&&r
001
MC/DC0%0/2
ref $config eq "HASH" and %$config
ref $config eq "HASH" %$config
Truth table33%1/3
A and B
A= ref $config eq "HASH"B= %$config
ABresult
0X0
100
111
329 1 require ExtUtils::Config;
330 1 $ip_args{config} = ExtUtils::Config->new($config);
331 }
332 1 return ExtUtils::InstallPaths->new(%ip_args);
333 }
334  
335 0 ▶ method get_arguments (@sources) {
Subroutine get_arguments: not called CC=15 SCAR=54.8
Pod undocumented
336 0 my ( $opts, undef ) = _parse_args(@sources);
337 0 for my $path_key (qw[install_base destdir prefix]) {
338 0 ▶ $opts->{$path_key} = detildefy( $opts->{$path_key} ) if defined $opts->{$path_key} && length $opts->{$path_key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{$path_key} and length $opts->{$path_key} 0 0 0
Condition0%0/3
defined $opts->{$path_key} and length $opts->{$path_key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{$path_key} and length $opts->{$path_key}
defined $opts->{$path_key} length $opts->{$path_key}
Truth table0%0/3
A and B
A= defined $opts->{$path_key}B= length $opts->{$path_key}
ABresult
0X0
100
111
339 }
340 0 ▶ if ( ref $opts->{install_path} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{"install_path"} eq "HASH") 0 0 0
341 0 ▶ $_ = detildefy($_) for grep { defined && length } values %{ $opts->{install_path} };
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
342 }
343 0 ▶ $install_base = $opts->{install_base} if exists $opts->{install_base};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"install_base"} 0 0 0
344 0 ▶ $installdirs = $opts->{installdirs} if exists $opts->{installdirs};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"installdirs"} 0 0 0
345 0 ▶ $destdir = $opts->{destdir} if exists $opts->{destdir};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"destdir"} 0 0 0
346 0 ▶ $prefix = $opts->{prefix} if exists $opts->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"prefix"} 0 0 0
347 0 ▶ $install_path = $opts->{install_path} if exists $opts->{install_path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"install_path"} 0 0 0
348 0 ▶ $create_packlist = $opts->{create_packlist} if exists $opts->{create_packlist};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"create_packlist"} 0 0 0
349 0 ▶ $verbose = $opts->{v} if exists $opts->{v};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"v"} 0 0 0
350 0 ▶ $config = $opts->{config} if exists $opts->{config};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"config"} 0 0 0
351 0 $install_paths = $self->_build_install_paths();
352 0 return %$opts;
353 }
354  
355 1 ▶ sub run_from_cli ($class) {
Subroutine run_from_cli: called CC=6 SCAR=19.4
Pod undocumented
356 1 my @argv = @ARGV;
357 1 ▶ my $action = @argv && $argv[0] =~ /\A\w+\z/ ? shift @argv : 'build';
Branch: 1 branch
BranchTrueFalseTotal
@argv && $argv[0] =~ /\A\w+\z/u ? : 1 0 1
Condition33%1/3
@argv and $argv[0] =~ /\A\w+\z/u
!ll&&!rl&&r
001
MC/DC0%0/2
@argv and $argv[0] =~ /\A\w+\z/u
@argv $argv[0] =~ /\A\w+\z/u
Truth table33%1/3
A and B
A= @argvB= $argv[0] =~ /\A\w+\z/u
ABresult
0X0
100
111
358 1 my ( $env, $bargv ) = ( [], [] );
359 1 ▶ if ( -f '_build_params' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "_build_params") 1 0 1
360 1 my $params = decode_json( path('_build_params')->slurp_utf8 );
361 1 ▶ ( $env, $bargv ) = @$params if ref $params eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params eq "ARRAY" 1 0 1
362 }
363 1 my ( $opts, $fuzz_opts ) = _parse_args( $env, $bargv, \@argv );
364 1 my $builder = $class->new( %$opts, action => $action );
365 1 ▶ $builder->Build( $action eq 'fuzz' ? %$fuzz_opts : () );
Branch: 1 branch
BranchTrueFalseTotal
$action eq 'fuzz' ? : 0 1 1
366 }
367  
368 1 ▶ method Build(@args) {
Subroutine Build: called CC=2 SCAR=7.1
Pod undocumented
369 1 my $method = $self->can( 'step_' . $action );
370 1 ▶ $method // die "No such action '$action'\n";
Condition50%1/2
$method // die("No such action '${action}'\n")
l!l
10
MC/DC0%0/1
$method // die("No such action '${action}'\n")
$method
Truth table50%1/2
A
A= $method
Aresult
11
00
371 1 exit $method->( $self, @args );
372 }
373  
374 0 ▶ method Build_PL() {
Subroutine Build_PL: not called CC=6 SCAR=37.4
Pod undocumented
375 0 ▶ my @env = defined $ENV{PERL_MB_OPT} ? split_like_shell( $ENV{PERL_MB_OPT} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL_MB_OPT'} ? : 0 0 0
376 0 my @argv = @ARGV;
377 0 my %opts = $self->get_arguments( \@env, \@argv );
378 0 ▶ die "Pure perl Affix? Ha! You wish.\n" if $pureperl || $opts{pureperl};
Branch: 1 branch
BranchTrueFalseTotal
if $pureperl or $opts{"pureperl"} 0 0 0
Condition0%0/3
$pureperl or $opts{"pureperl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pureperl or $opts{"pureperl"}
$pureperl $opts{"pureperl"}
Truth table0%0/3
A or B
A= $pureperlB= $opts{"pureperl"}
ABresult
1X1
011
000
379 0 say sprintf 'Creating new Build script for %s %s', $meta->name, $meta->version;
380 0 $self->write_file( 'Build', sprintf <<~'', $^X, __PACKAGE__, __PACKAGE__ );
381 #!%s
382 use lib 'builder';
383 use %s;
384 %s->run_from_cli();
385  
386 0 make_executable('Build');
387 0 $self->write_file( '_build_params', encode_json( [ \@env, \@argv ] ) );
388  
389 0 ▶ if ( my $dynamic = $meta->custom('x_dynamic_prereqs') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dynamic = $meta->custom("x_dynamic_prereqs")) 0 0 0
390 0 my %meta = ( %{ $meta->as_struct }, dynamic_config => 1 );
391 0 require CPAN::Requirements::Dynamic;
392 0 my $dynamic_parser = CPAN::Requirements::Dynamic->new();
393 0 my $prereq = $dynamic_parser->evaluate($dynamic);
394 0 $meta{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
395 0 $meta = CPAN::Meta->new( \%meta );
396 }
397 0 $meta->save(@$_) for ['MYMETA.json'], [ 'MYMETA.yml' => { version => 1.4 } ];
398 }
399  
400 1 ▶ sub find ( $pattern, $base ) {
Subroutine find: called CC=2 SCAR=7.0
Pod undocumented
401 1 ▶ $base = path($base) unless builtin::blessed $base;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($base) 1 0 1
402 my $blah = $base->visit(
403 61 ▶ sub ( $path, $state ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
404 61 ▶ $state->{$path} = $path if $path =~ $pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ /$pattern/u 59 2 61
405 },
406 1 { recurse => 1 }
407 );
408 1 values %$blah;
409 }
410  
411 # infix builder
412 0 ▶ method step_clone_infix() {
Subroutine step_clone_infix: not called CC=3 SCAR=24.8
Pod undocumented
413 0 ▶ return if cwd->absolute->child('infix')->exists;
Branch: 1 branch
BranchTrueFalseTotal
if cwd()->absolute->child("infix")->exists 0 0 0
414 0 my $clone_dir = cwd->absolute->child('infix');
415 0 ▶ die 'Failed to clone infix' if system( 'git', 'clone', '--depth', '1', 'https://github.com/sanko/infix.git', $clone_dir->stringify );
Branch: 1 branch
BranchTrueFalseTotal
if system "git", "clone", "--depth", 1, "https://github.com/sanko/infix.git", $clone_dir->stringify 0 0 0
416 }
417  
418 0 ▶ method step_infix () {
Subroutine step_infix: not called CC=27 SCAR=66.3
Pod undocumented
419 0 $self->step_clone_infix();
420 0 my $cwd = cwd->absolute;
421 0 my $infix_dir = $cwd->child('infix');
422  
423 # Use architecture-specific directory to avoid collision on shared filesystems (WSL vs Windows)
424 0 my $build_lib = $infix_dir->child( 'build_lib', $Config{archname} );
425  
426 # If library already exists and is newer than source, we are good.
427 0 my $is_msvc = ( $Config{cc} =~ /cl(\.exe)?$/i );
428 0 ▶ my $lib_ext = $is_msvc ? '.lib' : '.a';
Branch: 1 branch
BranchTrueFalseTotal
$is_msvc ? : 0 0 0
429 0 ▶ my $lib_pre = $is_msvc ? '' : 'lib';
Branch: 1 branch
BranchTrueFalseTotal
$is_msvc ? : 0 0 0
430 0 my $lib_file = $build_lib->child( $lib_pre . 'infix' . $lib_ext );
431 0 my $src_file = $infix_dir->child( 'src', 'infix.c' );
432 0 ▶ if ( -e $lib_file && !$force ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $lib_file and not $force) 0 0 0
Condition0%0/3
-e $lib_file and not $force
!ll&&!rl&&r
000
MC/DC0%0/2
-e $lib_file and not $force
-e $lib_file not $force
Truth table0%0/3
A and not(B)
A= -e $lib_fileB= not $force
ABresult
0X0
100
111
433  
434 # Check timestamps to ensure we rebuild if source changed
435 0 ▶ if ( $src_file->stat->mtime <= $lib_file->stat->mtime ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_file->stat->mtime <= $lib_file->stat->mtime) 0 0 0
436 0 return 0;
437 }
438 }
439 #
440 0 ▶ warn "Building infix static library for $Config{archname}..." if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
441 0 ▶ $build_lib->mkpath unless -d $build_lib;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $build_lib 0 0 0
442 0 my @include_dirs = ( $infix_dir->child('include'), $infix_dir->child('src') );
443  
444 # Detect Compiler settings using Perl's Config as base
445 0 ▶ my $cc_cmd = $Config{cc} || 'cc';
Condition0%0/2
$Affix::Builder::Config{'cc'} || 'cc'
l!l
00
MC/DC0%0/1
$Affix::Builder::Config{'cc'} || 'cc'
$Affix::Builder::Config{'cc'}
Truth table0%0/2
A
A= $Affix::Builder::Config{'cc'}
Aresult
11
00
446 0 my $cc_type = 'gcc'; # Default flavor
447 0 ▶ if ( $cc_cmd =~ /cl(\.exe)?$/i ) { $cc_type = 'msvc'; }
Branch: 4 branches
BranchTrueFalseTotal
if ($cc_cmd =~ /cl(\.exe)?$/iu) { } 0 0 0
elsif ($cc_cmd =~ /clang/iu) { } 0 0 0
elsif ($cc_cmd =~ /gcc/iu) { } 0 0 0
elsif ($cc_cmd =~ /egcc/iu) { } 0 0 0
448 0 elsif ( $cc_cmd =~ /clang/i ) { $cc_type = 'clang'; }
449 0 elsif ( $cc_cmd =~ /gcc/i ) { $cc_type = 'gcc'; }
450 0 elsif ( $cc_cmd =~ /egcc/i ) { $cc_type = 'gcc'; }
451  
452 # Setup Flags
453 0 my ( $ar_cmd, @cflags, @arflags, $out_flag_cc, $out_flag_ar );
454 0 ▶ my @includes = map { ( $cc_type eq 'msvc' ? '/I' : '-I' ) . $_ } @include_dirs;
Branch: 1 branch
BranchTrueFalseTotal
$cc_type eq 'msvc' ? : 0 0 0
455 0 ▶ if ( $cc_type eq 'msvc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc_type eq 'msvc') { } 0 0 0
456 0 $ar_cmd = 'lib';
457 0 @cflags = ( '/nologo', '/c', '/std:c11', '/W3', '/GS', '/MD', '/O2', @includes );
458 0 ▶ @cflags = ( @cflags, '/DINFIX_DEBUG_ENABLED=1' ) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
459 0 @arflags = ('/nologo');
460 0 $out_flag_cc = '/Fo';
461 0 $out_flag_ar = '/OUT:';
462 }
463 else {
464 # GCC / Clang
465 0 $ar_cmd = 'ar';
466 0 @cflags = ( '-std=c11', '-Wall', '-Wextra', '-O2', '-fPIC', @includes );
467 0 ▶ @cflags = ( @cflags, '-DINFIX_DEBUG_ENABLED=1' ) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
468 0 @arflags = ('rcs');
469 0 $out_flag_cc = '-o';
470 0 $out_flag_ar = '';
471  
472 # Pass pthread to compilation of static lib too (safe practice)
473 0 ▶ push @cflags, '-pthread' unless $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 0 0 0
474 #
475 0 ▶ push @cflags, '-D__EXTENSIONS__', '-D_LARGEFILE64_SOURCE' if $^O =~ /(solaris|sunos)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /(solaris|sunos)/iu 0 0 0
476 }
477  
478 # Compile infix.c -> infix.o
479 0 ▶ my $obj_ext = $cc_type eq 'msvc' ? '.obj' : '.o';
Branch: 1 branch
BranchTrueFalseTotal
$cc_type eq 'msvc' ? : 0 0 0
480 0 my $obj_file = $build_lib->child( 'infix' . $obj_ext );
481 0 my @compile_cmd;
482 0 ▶ if ( $cc_type eq 'msvc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc_type eq 'msvc') { } 0 0 0
483 0 @compile_cmd = ( $cc_cmd, @cflags, $out_flag_cc . $obj_file, $src_file );
484 }
485 else {
486 0 @compile_cmd = ( $cc_cmd, @cflags, '-c', $src_file, $out_flag_cc, $obj_file );
487 }
488 0 ▶ warn " Compiling: @compile_cmd\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
489 0 ▶ if ( system(@compile_cmd) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (system(@compile_cmd) != 0) 0 0 0
490 0 die "Failed to compile infix.c";
491 }
492  
493 # Archive infix.o -> libinfix.a
494 0 my @archive_cmd;
495 0 ▶ if ( $cc_type eq 'msvc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc_type eq 'msvc') { } 0 0 0
496 0 @archive_cmd = ( $ar_cmd, @arflags, $out_flag_ar . $lib_file, $obj_file );
497 }
498 else {
499 0 @archive_cmd = ( $ar_cmd, @arflags, $lib_file, $obj_file );
500 }
501 0 ▶ warn " Archiving: @archive_cmd\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
502 0 ▶ if ( system(@archive_cmd) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (system(@archive_cmd) != 0) 0 0 0
503 0 die "Failed to create infix static library";
504 }
505 0 ▶ warn "Infix library built: $lib_file\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
506 0 return 0;
507 }
508  
509 # Detects if linking against librt is required (common on Linux/BSD/Solaris for shm_open)
510 0 ▶ method check_for_lrt() {
Subroutine check_for_lrt: not called CC=15 SCAR=54.8
Pod undocumented
511 0 ▶ return '' if $^O eq 'MSWin32' || $^O eq 'android';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" or $^O eq "android" 0 0 0
Condition0%0/3
$^O eq "MSWin32" or $^O eq "android"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O eq "MSWin32" or $^O eq "android"
$^O eq "MSWin32" $^O eq "android"
Truth table0%0/3
A or B
A= $^O eq "MSWin32"B= $^O eq "android"
ABresult
1X1
011
000
512 0 ▶ warn "Checking if -lrt is required...\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
513 0 ▶ my $cc = $Config{cc} || 'cc';
Condition0%0/2
$Affix::Builder::Config{'cc'} || 'cc'
l!l
00
MC/DC0%0/1
$Affix::Builder::Config{'cc'} || 'cc'
$Affix::Builder::Config{'cc'}
Truth table0%0/2
A
A= $Affix::Builder::Config{'cc'}
Aresult
11
00
514 0 my $test_code = <<~'';
515 #include <sys/mman.h>
516 #include <fcntl.h>
517 int main(void) { shm_open("/test", O_RDONLY, 0); return 0; }
518  
519 0 my ( $fh, $src ) = tempfile( SUFFIX => '.c', UNLINK => 1 );
520 0 print $fh $test_code;
521 0 close $fh;
522 0 my ( $ofh, $out ) = tempfile( UNLINK => 1 );
523 0 close $ofh;
524  
525 # Try without -lrt (list-form system to avoid shell injection)
526 0 ▶ open( my $devnull, '>', '/dev/null' ) if $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" 0 0 0
527 0 ▶ my $old_stdout = select $devnull if $devnull;
Branch: 1 branch
BranchTrueFalseTotal
if $devnull 0 0 0
528 0 system( $cc, '-o', $out, $src );
529 0 ▶ select $old_stdout if $old_stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $old_stdout 0 0 0
530 0 ▶ close $devnull if $devnull;
Branch: 1 branch
BranchTrueFalseTotal
if $devnull 0 0 0
531 0 ▶ return '' if $? == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? == 0 0 0 0
532  
533 # Try with -lrt
534 0 ▶ open( $devnull, '>', '/dev/null' ) if $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" 0 0 0
535 0 ▶ $old_stdout = select $devnull if $devnull;
Branch: 1 branch
BranchTrueFalseTotal
if $devnull 0 0 0
536 0 system( $cc, '-o', $out, $src, '-lrt' );
537 0 ▶ select $old_stdout if $old_stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $old_stdout 0 0 0
538 0 ▶ close $devnull if $devnull;
Branch: 1 branch
BranchTrueFalseTotal
if $devnull 0 0 0
539 0 ▶ return '-lrt' if $? == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? == 0 0 0 0
540 0 return '';
541 }
542  
543 0 ▶ sub command_exists {
Subroutine command_exists: not called CC=2 SCAR=17.9
Pod undocumented
544 0 my ($cmd) = @_;
545 0 ▶ if ( $Config{osname} eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Affix::Builder::Config{'osname'} eq 'MSWin32') { } 0 0 0
546 0 return system( 'where', $cmd ) == 0;
547 }
548 else {
549 0 return system( 'command', '-v', $cmd ) == 0;
550 }
551 }
552  
553 0 ▶ method step_affix {
Subroutine step_affix: not called CC=25 SCAR=64.8
Pod undocumented
554 0 $self->step_infix;
555 0 my $cwd = cwd->absolute;
556 0 my @objs;
557 0 require ExtUtils::CBuilder;
558 0 my %config = %Config;
559  
560 # ExtUtils::CBuilder only uses $Config{ccflags} and silently drops
561 # ccflags_uselargefiles, which Configure keeps separate on Solaris/
562 # illumos (and a few other platforms). Without those defines the system
563 # headers do not expose off64_t, sigjmp_buf, alloca or fileno, so the
564 # same source that perl itself builds fails to compile here. Merge them
565 # in (harmless duplication when ccflags already contains them).
566 0 $config{ccflags} = join ' ', grep {length} $config{ccflags}, $config{ccflags_uselargefiles};
567 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
568 0 $config{ldflags} =~ s/-s //g;
569 0 $config{ldflags} =~ s/ -s//g;
570 0 $config{lddlflags} =~ s/-s //g;
571 0 $config{lddlflags} =~ s/ -s//g;
572 }
573 0 my $builder = ExtUtils::CBuilder->new( quiet => !$verbose, config => \%config );
574 0 my $pre = $cwd->child(qw[blib arch auto])->absolute;
575 0 require DynaLoader;
576 0 ▶ my $mod2fname = defined &DynaLoader::mod2fname ? \&DynaLoader::mod2fname : sub { return $_[0][-1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined &DynaLoader::mod2fname ? : 0 0 0
577 0 my @parts = ('Affix');
578 0 my $archdir = rel2abs catdir( curdir, qw[. blib arch auto], @parts );
579 0 my $err;
580 0 make_path( $archdir, { chmod => 0755, error => \$err, verbose => $verbose } );
581 0 my $lib_file = catfile( $archdir, $mod2fname->( \@parts ) . '.' . $Config{dlext} );
582 0 my @dirs;
583 0 push @dirs, '../';
584 0 my $has_cxx = !1;
585 0 my $recompiled = 0;
586 0 my @sources = $cwd->child('lib/Affix.c');
587  
588 #~ warn "Sources to process: @sources\n";
589 0 for my $source (@sources) {
590  
591 #~ warn "Processing source: $source\n";
592 0 my $cxx = $source =~ /cx+$/;
593 0 my $file_base = $source->basename(qr[.c$]);
594 0 my $tempdir = path('lib');
595 0 $tempdir->mkdir( { verbose => $verbose, mode => oct '755' } );
596 0 my $version = $meta->version;
597 0 my $obj = $builder->object_file($source);
598  
599 #~ warn "Checking obj: $obj\n";
600 # Check mtimes of all .c and .h files under lib/ (includes Affix.c, marshal.c, Affix.h)
601 0 my $newest_dep = $source->stat->mtime;
602 0 my $iter = path('lib')->iterator;
603 0 ▶ while ( my $entry = $iter->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $entry = &$iter()) 0 0 0
604 0 ▶ next unless $entry->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->is_file 0 0 0
605 0 ▶ next unless $entry =~ /\.[ch]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry =~ /\.[ch]$/u 0 0 0
606 0 my $dep_mtime = $entry->stat->mtime;
607 0 ▶ $newest_dep = $dep_mtime if $dep_mtime > $newest_dep;
Branch: 1 branch
BranchTrueFalseTotal
if $dep_mtime > $newest_dep 0 0 0
608 }
609 0 ▶ my $should_compile
Condition0%0/9
$force || !(-f $obj) || $newest_dep >= path($obj)->stat->mtime || path(__FILE__)->stat->mtime > path($obj)->stat->mtime
l!l&&r!l&&!r
000
$force or not -f $obj or $newest_dep >= path($obj)->stat->mtime
l!l&&r!l&&!r
000
$force or not -f $obj
l!l&&r!l&&!r
000
MC/DC0%0/4
$force || !(-f $obj) || $newest_dep >= path($obj)->stat->mtime || path(__FILE__)->stat->mtime > path($obj)->stat->mtime
$force not -f $obj $newest_dep >= path($obj)->stat->mtime path(__FILE__)->stat->mtime > path($obj)->stat->mtime
Truth table0%0/5
A or not(B) or C || D
A= $forceB= not -f $objC= $newest_dep >= path($obj)->stat->mtimeD= path(__FILE__)->stat->mtime > path($obj)->stat->mtime
ABCDresult
1XXX1
01XX1
001X1
00011
00000
610 = ( $force ||
611 ( !-f $obj ) ||
612 ( $newest_dep >= path($obj)->stat->mtime ) ||
613 ( path(__FILE__)->stat->mtime > path($obj)->stat->mtime ) );
614 0 ▶ if ($should_compile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($should_compile) 0 0 0
615 0 ▶ my $reason
Branch: 3 branches
BranchTrueFalseTotal
!(-f $obj) ? : 0 0 0
$newest_dep >= path($obj)->stat->mtime ? : 0 0 0
path(__FILE__)->stat->mtime > path($obj)->stat->mtime ? : 0 0 0
616 = !-f $obj ? 'object file missing' :
617 $newest_dep >= path($obj)->stat->mtime ? 'source newer than object' :
618 path(__FILE__)->stat->mtime > path($obj)->stat->mtime ? 'builder changed' :
619 'forced';
620 0 warn "Compiling $source ($reason)\n";
621 0 $recompiled = 1;
622 }
623 0 push @dirs, $source->dirname();
624 0 ▶ $has_cxx = 1 if $cxx;
Branch: 1 branch
BranchTrueFalseTotal
if $cxx 0 0 0
625 0 ▶ push @objs,
Branch: 4 branches
BranchTrueFalseTotal
$should_compile ? : 0 0 0
$cxx ? : 0 0 0
$debug ? : 0 0 0
defined $extra_compiler_flags && length $extra_compiler_flags ? : 0 0 0
Condition0%0/3
defined $extra_compiler_flags and length $extra_compiler_flags
!ll&&!rl&&r
000
MC/DC0%0/2
defined $extra_compiler_flags and length $extra_compiler_flags
defined $extra_compiler_flags length $extra_compiler_flags
Truth table0%0/3
A and B
A= defined $extra_compiler_flagsB= length $extra_compiler_flags
ABresult
0X0
100
111
626 $should_compile ?
627 $builder->compile(
628 quiet => 0,
629 'C++' => $cxx,
630 source => $source->stringify,
631 defines => { VERSION => qq/"$version"/, XS_VERSION => qq/"$version"/ },
632 include_dirs => [
633 cwd->stringify, cwd->child('infix')->realpath->stringify,
634 cwd->child('infix')->child('include')->realpath->stringify, cwd->child('infix')->child('src')->realpath->stringify,
635 $source->dirname, $pre->child( $meta->name, 'include' )->stringify
636 ],
637 extra_compiler_flags => (
638 '-fPIC -std=' .
639 ( $cxx ? $cppver : $cver ) . ' ' .
640 $cflags .
641 ( $debug ? ' -ggdb3 -g -Wall -Wextra -pedantic' : '' ) .
642 ( defined $extra_compiler_flags && length $extra_compiler_flags ? " $extra_compiler_flags" : '' )
643 )
644 ) :
645 $obj;
646 }
647  
648 # Point to the Architecture-specific build lib
649 0 my $infix_build_lib = cwd->absolute->child('infix')->child( 'build_lib', $Config{archname} )->stringify;
650  
651 # Check for -lrt requirement
652 0 my $lrt_flag = $self->check_for_lrt();
653 0 ▶ my $data = {
Branch: 2 branches
BranchTrueFalseTotal
$lrt_flag ? : 0 0 0
defined $extra_linker_flags && length $extra_linker_flags ? : 0 0 0
Condition0%0/3
defined $extra_linker_flags and length $extra_linker_flags
!ll&&!rl&&r
000
MC/DC0%0/2
defined $extra_linker_flags and length $extra_linker_flags
defined $extra_linker_flags length $extra_linker_flags
Truth table0%0/3
A and B
A= defined $extra_linker_flagsB= length $extra_linker_flags
ABresult
0X0
100
111
654  
655 # Removed incorrect -lstdc++ logic. Added -lm for math.
656 # -pthread is already in $ldflags via ADJUST
657 extra_linker_flags => [
658 split( ' ', $ldflags ),
659 "-L$infix_build_lib", '-linfix', ( $lrt_flag ? ( split( ' ', $lrt_flag ) ) : () ),
660 '-lm', ( defined $extra_linker_flags && length $extra_linker_flags ? split_like_shell($extra_linker_flags) : () )
661 ],
662 objects => [@objs],
663 lib_file => $lib_file,
664 module_name => join '::',
665 @parts
666 };
667 0 ▶ warn "Linking $lib_file\n" if $recompiled;
Branch: 1 branch
BranchTrueFalseTotal
if $recompiled 0 0 0
668 0 return $builder->link(%$data);
669 }
670 };
671 #
672 1 1;
↑ Summary blib/lib/Affix/Build.pm »