blib/lib/ExtUtils/HasCompiler.pm

filter: Statementstmt 70.4% 100 / 142 Branchbran 40.3% 25 / 62 Conditioncond 50.0% 11 / 22 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 60.6% 154 / 254 CC 43 SCAR 44.4
CC
43
Cov
60%
can_compile_loadable_object
159.7
can_compile_static_library
16.8
can_compile_extension
6.4
CRAP 84.4
↑ Summary Makefile.PL »
1 package ExtUtils::HasCompiler;
2 1 $ExtUtils::HasCompiler::VERSION = '0.022';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our @EXPORT_OK = qw/can_compile_loadable_object can_compile_static_library can_compile_extension/;
8 1 our %EXPORT_TAGS = (all => \@EXPORT_OK);
9  
10 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp 'carp';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Spec::Functions qw/catfile catdir rel2abs/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Temp qw/tempdir tempfile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 my $tempdir = tempdir('HASCOMPILERXXXX', CLEANUP => 1, DIR => '.');
17  
18 1 my $loadable_object_format = <<'END';
19 #define PERL_NO_GET_CONTEXT
20 #include "EXTERN.h"
21 #include "perl.h"
22 #include "XSUB.h"
23  
24 #ifndef PERL_UNUSED_VAR
25 #define PERL_UNUSED_VAR(var)
26 #endif
27  
28 XS(exported) {
29 #ifdef dVAR
30 dVAR;
31 #endif
32 dXSARGS;
33  
34 PERL_UNUSED_VAR(cv); /* -W */
35 PERL_UNUSED_VAR(items); /* -W */
36  
37 XSRETURN_IV(42);
38 }
39  
40 #ifndef XS_EXTERNAL
41 #define XS_EXTERNAL(foo) XS(foo)
42 #endif
43  
44 /* we don't want to mess with .def files on mingw */
45 #if defined(WIN32) && defined(__GNUC__)
46 # define EXPORT __declspec(dllexport)
47 #else
48 # define EXPORT
49 #endif
50  
51 EXPORT XS_EXTERNAL(boot_%s) {
52 #ifdef dVAR
53 dVAR;
54 #endif
55 dXSARGS;
56  
57 PERL_UNUSED_VAR(cv); /* -W */
58 PERL_UNUSED_VAR(items); /* -W */
59  
60 newXS("%s::exported", exported, __FILE__);
61 }
62  
63 END
64  
65 1 my $counter = 1;
66 1 my %prelinking = map { $_ => 1 } qw/MSWin32 VMS aix/;
67  
68 sub can_compile_loadable_object {
69 2 ▶ my %args = @_;
Subroutine can_compile_loadable_object: called CC=27 SCAR=50.7
Pod documented
70  
71 2 ▶ my $output = $args{output} || \*STDOUT;
Condition50%1/2
$args{'output'} || \*STDOUT
l!l
20
MC/DC0%0/1
$args{'output'} || \*STDOUT
$args{'output'}
Truth table50%1/2
A
A= $args{'output'}
Aresult
11
00
72  
73 2 ▶ my $config = $args{config} || 'ExtUtils::HasCompiler::Config';
Condition100%2/2
$args{'config'} || 'ExtUtils::HasCompiler::Config'
l!l
11
MC/DC100%1/1
$args{'config'} || 'ExtUtils::HasCompiler::Config'
$args{'config'}
Truth table100%2/2
A
A= $args{'config'}
Aresult
11
00
74 2 ▶ return if not $config->get('usedl');
Branch: 1 branch
BranchTrueFalseTotal
unless $config->get("usedl") 0 2 2
75  
76 2 my ($source_handle, $source_name) = tempfile('TESTXXXX', DIR => $tempdir, SUFFIX => '.c', UNLINK => 1);
77 2 my $basename = basename($source_name, '.c');
78 2 my $abs_basename = catfile($tempdir, $basename);
79  
80 2 my ($cc, $ccflags, $optimize, $cccdlflags, $ld, $ldflags, $lddlflags, $libperl, $perllibs, $archlibexp, $_o, $dlext) = map { $config->get($_) } qw/cc ccflags optimize cccdlflags ld ldflags lddlflags libperl perllibs archlibexp _o dlext/;
81  
82 2 my $incdir = catdir($archlibexp, 'CORE');
83 2 my $object_file = $abs_basename.$_o;
84 2 my $loadable_object = "$abs_basename.$dlext";
85  
86 2 my @commands;
87 2 ▶ if ($^O eq 'MSWin32' && $cc =~ /^cl/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32' and $cc =~ /^cl/) { } 0 2 2
elsif ($^O eq 'VMS') { } 0 2 2
Condition33%1/3
$^O eq "MSWin32" and $cc =~ /^cl/
!ll&&!rl&&r
200
MC/DC0%0/2
$^O eq "MSWin32" and $cc =~ /^cl/
$^O eq "MSWin32" $cc =~ /^cl/
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= $cc =~ /^cl/
ABresult
0X0
100
111
88 0 push @commands, qq{$cc $ccflags $cccdlflags $optimize /I "$incdir" /c $source_name /Fo$object_file};
89 0 push @commands, qq{$ld $object_file $lddlflags $libperl $perllibs /out:$loadable_object /def:$abs_basename.def /pdb:$abs_basename.pdb};
90 }
91 elsif ($^O eq 'VMS') {
92 # Mksymlists is only the beginning of the story.
93 0 ▶ open my $opt_fh, '>>', "$abs_basename.opt" or do { carp "Couldn't append to '$abs_basename.opt'"; return };
Branch: 1 branch
BranchTrueFalseTotal
open my $opt_fh, ">>", "$abs_basename.opt" or do { carp("Couldn't append to '$abs_basename.opt'"); return } 0 0 0
94 0 print $opt_fh "PerlShr/Share\n";
95 0 close $opt_fh;
96  
97 0 ▶ my $incdirs = $ccflags =~ s{ /inc[^=]+ (?:=)+ (?:\()? ( [^\/\)]* ) }{}xi ? "$1,$incdir" : $incdir;
Branch: 1 branch
BranchTrueFalseTotal
$ccflags =~ s[ /inc[^=]+ (?:=)+ (?:\()? ( [^\/\)]* ) ][]xi ? : 0 0 0
98 0 push @commands, qq{$cc $ccflags $optimize /include=($incdirs) $cccdlflags $source_name /obj=$object_file};
99 0 push @commands, qq{$ld $ldflags $lddlflags=$loadable_object $object_file,$abs_basename.opt/OPTIONS,${incdir}perlshr_attr.opt/OPTIONS' $perllibs};
100 }
101 else {
102 2 my @extra;
103 2 ▶ if ($^O eq 'MSWin32') {
Branch: 4 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 2 2
elsif ($^O =~ /^(cygwin|msys)$/) { } 0 2 2
elsif ($^O eq 'aix') { } 0 2 2
elsif ($^O eq 'android') { } 0 2 2
104 0 my $lib = '-l' . ($libperl =~ /lib([^.]+)\./)[0];
105 0 push @extra, "$abs_basename.def", $lib, $perllibs;
106 }
107 elsif ($^O =~ /^(cygwin|msys)$/) {
108 0 ▶ push @extra, catfile($incdir, $config->get('useshrplib') ? 'libperl.dll.a' : 'libperl.a');
Branch: 1 branch
BranchTrueFalseTotal
$config->get('useshrplib') ? : 0 0 0
109 }
110 elsif ($^O eq 'aix') {
111 0 $lddlflags =~ s/\Q$(BASEEXT)\E/$abs_basename/;
112 0 $lddlflags =~ s/\Q$(PERL_INC)\E/$incdir/;
113 }
114 elsif ($^O eq 'android') {
115 0 push @extra, qq{"-L$incdir"}, '-lperl', $perllibs;
116 }
117 2 push @commands, qq{$cc $ccflags $optimize "-I$incdir" $cccdlflags -c $source_name -o $object_file};
118 2 push @commands, qq{$ld $object_file -o $loadable_object $lddlflags @extra};
119 }
120  
121 2 ▶ if ($prelinking{$^O}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prelinking{$^O}) 0 2 2
122 0 require ExtUtils::Mksymlists;
123 0 ExtUtils::Mksymlists::Mksymlists(NAME => $basename, FILE => $abs_basename, IMPORTS => {});
124 }
125  
126 2 my $shortname = '_Loadable' . $counter++;
127 2 my $package = "ExtUtils::HasCompiler::$shortname";
128 2 ▶ printf $source_handle $loadable_object_format, $basename, $package or do { carp "Couldn't write to $source_name: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
printf $source_handle $loadable_object_format, $basename, $package or do { carp("Couldn't write to ${source_name}: $!"); return } 0 2 2
129 2 ▶ close $source_handle or do { carp "Couldn't close $source_name: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
close $source_handle or do { carp("Couldn't close ${source_name}: $!"); return } 0 2 2
130  
131 2 for my $command (@commands) {
132 4 ▶ print $output "$command\n" if not $args{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"quiet"} 4 0 4
133 4 ▶ system $command and do { carp "Couldn't execute $command: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
system $command and do { carp("Couldn't execute ${command}: $!"); return } 0 4 4
134 }
135  
136 # Skip loading when cross-compiling
137 2 ▶ return 1 if exists $args{skip_load} ? $args{skip_load} : $config->get('usecrosscompile');
Branch: 2 branches
BranchTrueFalseTotal
if exists $args{"skip_load"} ? $args{"skip_load"} : $config->get("usecrosscompile") 0 2 2
exists $args{'skip_load'} ? : 0 2 2
138  
139 2 require DynaLoader;
140 2 local @DynaLoader::dl_require_symbols = "boot_$basename";
141 2 my $handle = DynaLoader::dl_load_file(rel2abs($loadable_object), 0);
142 2 ▶ if ($handle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle) { } 0 2 2
143 0 ▶ my $symbol = DynaLoader::dl_find_symbol($handle, "boot_$basename") or do { carp "Couldn't find boot symbol for $basename"; return };
Branch: 1 branch
BranchTrueFalseTotal
my $symbol = DynaLoader::dl_find_symbol($handle, "boot_$basename") or do { carp("Couldn't find boot symbol for $basename"); return } 0 0 0
144 0 my $compilet = DynaLoader::dl_install_xsub('__ANON__::__ANON__', $symbol, $source_name);
145 0 ▶ my $ret = eval { $compilet->(); $package->exported } or carp $@;
Branch: 1 branch
BranchTrueFalseTotal
my $ret = eval { do { &$compilet(); $package->exported } } or carp($@) 0 0 0
146 0 delete $ExtUtils::HasCompiler::{"$shortname\::"};
147 0 ▶ eval { DynaLoader::dl_unload_file($handle) } or carp $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { DynaLoader::dl_unload_file($handle) } } or carp($@) 0 0 0
148 0 ▶ return defined $ret && $ret == 42;
Condition0%0/3
defined $ret && $ret == 42
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret && $ret == 42
defined $ret $ret == 42
Truth table0%0/3
A && B
A= defined $retB= $ret == 42
ABresult
0X0
100
111
149 }
150 else {
151 2 carp "Couldn't load $loadable_object: " . DynaLoader::dl_error();
152 2 return;
153 }
154 }
155  
156 1 my %static_unsupported_on = map { $_ => 1 } qw/VMS aix MSWin32 cygwin/;
157 sub can_compile_static_library {
158 1 ▶ my %args = @_;
Subroutine can_compile_static_library: called CC=12 SCAR=28.2
Pod documented
159  
160 1 ▶ my $output = $args{output} || \*STDOUT;
Condition50%1/2
$args{'output'} || \*STDOUT
l!l
10
MC/DC0%0/1
$args{'output'} || \*STDOUT
$args{'output'}
Truth table50%1/2
A
A= $args{'output'}
Aresult
11
00
161  
162 1 ▶ my $config = $args{config} || 'ExtUtils::HasCompiler::Config';
Condition50%1/2
$args{'config'} || 'ExtUtils::HasCompiler::Config'
l!l
01
MC/DC0%0/1
$args{'config'} || 'ExtUtils::HasCompiler::Config'
$args{'config'}
Truth table50%1/2
A
A= $args{'config'}
Aresult
11
00
163 1 ▶ return if $config->get('useshrplib') eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $config->get("useshrplib") eq "true" 0 1 1
164  
165 1 my ($source_handle, $source_name) = tempfile('TESTXXXX', DIR => $tempdir, SUFFIX => '.c', UNLINK => 1);
166 1 my $basename = basename($source_name, '.c');
167 1 my $abs_basename = catfile($tempdir, $basename);
168  
169 1 my ($cc, $ccflags, $optimize, $ar, $full_ar, $ranlib, $archlibexp, $_o, $lib_ext) = map { $config->get($_) } qw/cc ccflags optimize ar full_ar ranlib archlibexp _o lib_ext/;
170 1 my $incdir = catdir($archlibexp, 'CORE');
171 1 my $object_file = "$abs_basename$_o";
172 1 my $static_library = $abs_basename.$lib_ext;
173  
174 1 my @commands;
175 1 ▶ if ($static_unsupported_on{$^O}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($static_unsupported_on{$^O}) { } 0 1 1
176 0 return;
177 }
178 else {
179 1 ▶ my $my_ar = length $full_ar ? $full_ar : $ar;
Branch: 1 branch
BranchTrueFalseTotal
length $full_ar ? : 1 0 1
180 1 push @commands, qq{$cc $ccflags $optimize "-I$incdir" -c $source_name -o $object_file};
181 1 push @commands, qq{$my_ar cr $static_library $object_file};
182 1 ▶ push @commands, qq{$ranlib $static_library} if $ranlib ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if $ranlib ne ":" 0 1 1
183 }
184  
185 1 my $shortname = '_Loadable' . $counter++;
186 1 my $package = "ExtUtils::HasCompiler::$shortname";
187 1 ▶ printf $source_handle $loadable_object_format, $basename, $package or do { carp "Couldn't write to $source_name: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
printf $source_handle $loadable_object_format, $basename, $package or do { carp("Couldn't write to ${source_name}: $!"); return } 0 1 1
188 1 ▶ close $source_handle or do { carp "Couldn't close $source_name: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
close $source_handle or do { carp("Couldn't close ${source_name}: $!"); return } 0 1 1
189  
190 1 for my $command (@commands) {
191 2 ▶ print $output "$command\n" if not $args{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"quiet"} 2 0 2
192 2 ▶ system $command and do { carp "Couldn't execute $command: $!"; return };
Branch: 1 branch
BranchTrueFalseTotal
system $command and do { carp("Couldn't execute ${command}: $!"); return } 0 2 2
193 }
194 1 return 1;
195 }
196  
197 sub can_compile_extension {
198 1 ▶ my %args = @_;
Subroutine can_compile_extension: called CC=5 SCAR=18.6
Pod documented
199 1 ▶ $args{config} ||= 'ExtUtils::HasCompiler::Config';
Condition50%1/2
$args{"config"} ||= "ExtUtils::HasCompiler::Config"
l!l
01
MC/DC0%0/1
$args{"config"} ||= "ExtUtils::HasCompiler::Config"
$args{"config"}
Truth table50%1/2
A
A= $args{"config"}
Aresult
11
00
200 1 ▶ my $linktype = $args{linktype} || ($args{config}->get('usedl') ? 'dynamic' : 'static');
Branch: 1 branch
BranchTrueFalseTotal
$args{'config'}->get('usedl') ? : 1 0 1
Condition33%1/3
$args{'linktype'} || ($args{'config'}->get('usedl') ? 'dynamic' : 'static')
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'linktype'} || ($args{'config'}->get('usedl') ? 'dynamic' : 'static')
$args{'linktype'} ($args{'config'}->get('usedl') ? 'dynamic' : 'static')
Truth table33%1/3
A || B
A= $args{'linktype'}B= ($args{'config'}->get('usedl') ? 'dynamic' : 'static')
ABresult
1X1
011
000
201 1 ▶ return $linktype eq 'static' ? can_compile_static_library(%args) : can_compile_loadable_object(%args);
Branch: 1 branch
BranchTrueFalseTotal
$linktype eq 'static' ? : 0 1 1
202 }
203  
204 sub ExtUtils::HasCompiler::Config::get {
205 39 ▶ my (undef, $key) = @_;
Subroutine get: called CC=2 SCAR=6.9
206 39 ▶ return $ENV{uc $key} || $Config{$key};
Condition100%3/3
$ENV{uc $key} || $ExtUtils::HasCompiler::Config{$key}
l!l&&r!l&&!r
3342
MC/DC100%2/2
$ENV{uc $key} || $ExtUtils::HasCompiler::Config{$key}
$ENV{uc $key} $ExtUtils::HasCompiler::Config{$key}
Truth table100%3/3
A || B
A= $ENV{uc $key}B= $ExtUtils::HasCompiler::Config{$key}
ABresult
1X1
011
000
207 }
208  
209 1 1;
210  
211 # ABSTRACT: Check for the presence of a compiler
212  
213 __END__
↑ Summary Makefile.PL »