blib/lib/ExtUtils/CBuilder/Base.pm

filter: Statementstmt 88.1% 126 / 143 Branchbran 53.7% 29 / 54 Conditioncond 19.2% 5 / 26 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 94.1% 32 / 34 Podpod 0.0% 0 / 24 totaltotal 64.8% 192 / 296 CC 42 SCAR 24.1
CC
42
Cov
72%
prelink
56.0
perl_src
31.8
_do_link
8.9
CRAP 11.1
« blib/lib/ExtUtils/CBuilder/Platform/Windows.pm ↑ Summary Build »
1 package ExtUtils::CBuilder::Base;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Text::ParseWords;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 $VERSION = '0.24_01';
13  
14 sub new {
15 2 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
16 2 my $self = bless {@_}, $class;
17  
18 2 ▶ $self->{properties}{perl} = $class->find_perl_interpreter
Branch: 1 branch
BranchTrueFalseTotal
$self->{"properties"}{"perl"} = $class->find_perl_interpreter or warn "Warning: Can't locate your perl binary" 0 2 2
19 or warn "Warning: Can't locate your perl binary";
20  
21 2 ▶ while (my ($k,$v) = each %Config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ExtUtils::CBuilder::Base::Config) 2512 2 2514
22 2512 ▶ $self->{config}{$k} = $v unless exists $self->{config}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"config"}{$k} 2512 0 2512
23 }
24 2 return $self;
25 }
26  
27 sub find_perl_interpreter {
28 2 ▶ my $perl;
Subroutine find_perl_interpreter: called CC=3 SCAR=12.5
Pod undocumented
29 File::Spec->file_name_is_absolute($perl = $^X)
30 or -f ($perl = $Config::Config{perlpath})
31 2 ▶ or ($perl = $^X);
Branch: 1 branch
BranchTrueFalseTotal
"File::Spec"->file_name_is_absolute($perl = $^X) or -f ($perl = $Config::Config{"perlpath"}) or $perl = $^X 0 2 2
Condition33%1/3
"File::Spec"->file_name_is_absolute($perl = $^X) or -f ($perl = $Config::Config{"perlpath"})
l!l&&r!l&&!r
200
MC/DC0%0/2
"File::Spec"->file_name_is_absolute($perl = $^X) or -f ($perl = $Config::Config{"perlpath"})
"File::Spec"->file_name_is_absolute($perl = $^X) -f ($perl = $Config::Config{"perlpath"})
Truth table33%1/3
A or B
A= "File::Spec"->file_name_is_absolute($perl = $^X)B= -f ($perl = $Config::Config{"perlpath"})
ABresult
1X1
011
000
32 2 return $perl;
33 }
34  
35 sub add_to_cleanup {
36 0 ▶ my $self = shift;
Subroutine add_to_cleanup: not called CC=2 SCAR=17.9
Pod undocumented
37 0 foreach (@_) {
38 0 $self->{files_to_clean}{$_} = 1;
39 }
40 }
41  
42 sub cleanup {
43 2 ▶ my $self = shift;
Subroutine cleanup: called CC=2 SCAR=7.2
Pod undocumented
44 2 foreach my $file (keys %{$self->{files_to_clean}}) {
45 0 unlink $file;
46 }
47 }
48  
49 sub object_file {
50 4 ▶ my ($self, $filename) = @_;
Subroutine object_file: called CC=1 SCAR=0.0
Pod undocumented
51  
52 # File name, minus the suffix
53 4 (my $file_base = $filename) =~ s/\.[^.]+$//;
54 4 return "$file_base$self->{config}{obj_ext}";
55 }
56  
57 sub arg_include_dirs {
58 3 ▶ my $self = shift;
Subroutine arg_include_dirs: called CC=1 SCAR=0.0
Pod undocumented
59 3 return map {"-I$_"} @_;
60 }
61  
62 3 ▶sub arg_nolink { '-c' }
Subroutine arg_nolink: called CC=1 SCAR=0.0
Pod undocumented
63  
64 sub arg_object_file {
65 3 ▶ my ($self, $file) = @_;
Subroutine arg_object_file: called CC=1 SCAR=0.0
Pod undocumented
66 3 return ('-o', $file);
67 }
68  
69 sub arg_share_object_file {
70 2 ▶ my ($self, $file) = @_;
Subroutine arg_share_object_file: called CC=1 SCAR=0.0
Pod undocumented
71 2 return ($self->split_like_shell($self->{config}{lddlflags}), '-o', $file);
72 }
73  
74 sub arg_exec_file {
75 1 ▶ my ($self, $file) = @_;
Subroutine arg_exec_file: called CC=1 SCAR=0.0
Pod undocumented
76 1 return ('-o', $file);
77 }
78  
79 sub arg_defines {
80 3 ▶ my ($self, %args) = @_;
Subroutine arg_defines: called CC=1 SCAR=0.0
Pod undocumented
81 3 return map "-D$_=$args{$_}", keys %args;
82 }
83  
84 sub compile {
85 3 ▶ my ($self, %args) = @_;
Subroutine compile: called CC=6 SCAR=18.6
Pod undocumented
86 3 ▶ die "Missing 'source' argument to compile()" unless defined $args{source};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"source"} 0 3 3
87
88 3 my $cf = $self->{config}; # For convenience
89  
90 3 ▶ $args{object_file} ||= $self->object_file($args{source});
Condition33%1/3
$args{"object_file"} ||= $self->object_file($args{"source"})
l!l&&r!l&&!r
030
MC/DC0%0/2
$args{"object_file"} ||= $self->object_file($args{"source"})
$args{"object_file"} $self->object_file($args{"source"})
Truth table33%1/3
A ||= B
A= $args{"object_file"}B= $self->object_file($args{"source"})
ABresult
1X1
011
000
91
92 my @include_dirs = $self->arg_include_dirs
93 3 ▶ (@{$args{include_dirs} || []},
Branch: 1 branch
BranchTrueFalseTotal
$args{"include_dirs"} or [] 3 0 3
94 $self->perl_inc());
95
96 3 ▶ my @defines = $self->arg_defines( %{$args{defines} || {}} );
Branch: 1 branch
BranchTrueFalseTotal
$args{"defines"} or {} 3 0 3
97
98 3 my @extra_compiler_flags = $self->split_like_shell($args{extra_compiler_flags});
99 3 my @cccdlflags = $self->split_like_shell($cf->{cccdlflags});
100 3 my @ccflags = $self->split_like_shell($cf->{ccflags});
101 3 my @optimize = $self->split_like_shell($cf->{optimize});
102 my @flags = (@include_dirs, @defines, @cccdlflags, @extra_compiler_flags,
103 $self->arg_nolink,
104 @ccflags, @optimize,
105 3 $self->arg_object_file($args{object_file}),
106 );
107
108 3 my @cc = $self->split_like_shell($cf->{cc});
109
110 $self->do_system(@cc, @flags, $args{source})
111 3 ▶ or die "error building $args{object_file} from '$args{source}'";
Branch: 1 branch
BranchTrueFalseTotal
$self->do_system(@cc, @flags, $args{"source"}) or die qq[error building $args{"object_file"} from '$args{"source"}'] 0 3 3
112  
113 3 return $args{object_file};
114 }
115  
116 sub have_compiler {
117 1 ▶ my ($self) = @_;
Subroutine have_compiler: called CC=7 SCAR=19.7
Pod undocumented
118 1 ▶ return $self->{have_compiler} if defined $self->{have_compiler};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"have_compiler"} 0 1 1
119
120 1 my $tmpfile = File::Spec->catfile(File::Spec->tmpdir, 'compilet.c');
121 {
122 1 ▶ my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $FH = "IO::File"->new("> $tmpfile") or die "Can't create ${tmpfile}: $!" 0 1 1
123 1 print $FH "int boot_compilet() { return 1; }\n";
124 }
125  
126 1 my ($obj_file, @lib_files);
127 1 eval {
128 1 $obj_file = $self->compile(source => $tmpfile);
129 1 @lib_files = $self->link(objects => $obj_file, module_name => 'compilet');
130 };
131 1 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
132 1 ▶ my $result = $self->{have_compiler} = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 1 1
133
134 1 foreach (grep defined, $tmpfile, $obj_file, @lib_files) {
135 3 ▶ 1 while unlink;
Branch: 1 branch
BranchTrueFalseTotal
unlink $_ and do { '???' } 3 3 6
136 }
137 1 return $result;
138 }
139  
140 sub lib_file {
141 3 ▶ my ($self, $dl_file) = @_;
Subroutine lib_file: called CC=1 SCAR=0.0
Pod undocumented
142 3 $dl_file =~ s/\.[^.]+$//;
143 3 $dl_file =~ tr/"//d;
144 3 return "$dl_file.$self->{config}{dlext}";
145 }
146  
147  
148 sub exe_file {
149 1 ▶ my ($self, $dl_file) = @_;
Subroutine exe_file: called CC=1 SCAR=0.0
Pod undocumented
150 1 $dl_file =~ s/\.[^.]+$//;
151 1 $dl_file =~ tr/"//d;
152 1 return "$dl_file$self->{config}{_exe}";
153 }
154  
155 2 ▶sub need_prelink { 0 }
Subroutine need_prelink: called CC=1 SCAR=0.0
Pod undocumented
156  
157 3 ▶sub extra_link_args_after_prelink { return }
Subroutine extra_link_args_after_prelink: called CC=1 SCAR=0.0
Pod undocumented
158  
159 sub prelink {
160 0 ▶ my ($self, %args) = @_;
Subroutine prelink: not called CC=7 SCAR=40.3
Pod undocumented
161
162 0 ▶ ($args{dl_file} = $args{dl_name}) =~ s/.*::// unless $args{dl_file};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"dl_file"} 0 0 0
163
164 0 require ExtUtils::Mksymlists;
165 ExtUtils::Mksymlists::Mksymlists( # dl. abbrev for dynamic library
166 DL_VARS => $args{dl_vars} || [],
167 DL_FUNCS => $args{dl_funcs} || {},
168 FUNCLIST => $args{dl_func_list} || [],
169 IMPORTS => $args{dl_imports} || {},
170 NAME => $args{dl_name}, # Name of the Perl module
171 DLBASE => $args{dl_base}, # Basename of DLL file
172 FILE => $args{dl_file}, # Dir + Basename of symlist file
173 0 ▶ VERSION => (defined $args{dl_version} ? $args{dl_version} : '0.0'),
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'dl_version'} ? : 0 0 0
Condition0%0/8
$args{'dl_vars'} || []
l!l
00
$args{'dl_funcs'} || {}
l!l
00
$args{'dl_func_list'} || []
l!l
00
$args{'dl_imports'} || {}
l!l
00
MC/DC0%0/1
$args{'dl_vars'} || []
$args{'dl_vars'}
MC/DC0%0/1
$args{'dl_funcs'} || {}
$args{'dl_funcs'}
MC/DC0%0/1
$args{'dl_func_list'} || []
$args{'dl_func_list'}
MC/DC0%0/1
$args{'dl_imports'} || {}
$args{'dl_imports'}
Truth table0%0/2
A
A= $args{'dl_vars'}
Aresult
11
00
Truth table0%0/2
A
A= $args{'dl_funcs'}
Aresult
11
00
Truth table0%0/2
A
A= $args{'dl_func_list'}
Aresult
11
00
Truth table0%0/2
A
A= $args{'dl_imports'}
Aresult
11
00
174 );
175
176 # Mksymlists will create one of these files
177 0 return grep -e, map "$args{dl_file}.$_", qw(ext def opt);
178 }
179  
180 sub link {
181 2 ▶ my ($self, %args) = @_;
Subroutine link: called CC=1 SCAR=0.0
Pod undocumented
182 2 return $self->_do_link('lib_file', lddl => 1, %args);
183 }
184  
185 sub link_executable {
186 1 ▶ my ($self, %args) = @_;
Subroutine link_executable: called CC=1 SCAR=0.0
Pod undocumented
187 1 return $self->_do_link('exe_file', lddl => 0, %args);
188 }
189  
190 sub _do_link {
191 3 ▶ my ($self, $type, %args) = @_;
Subroutine _do_link: called CC=8 SCAR=21.9
192  
193 3 my $cf = $self->{config}; # For convenience
194
195 3 my $objects = delete $args{objects};
196 3 ▶ $objects = [$objects] unless ref $objects;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $objects 3 0 3
197 3 ▶ my $out = $args{$type} || $self->$type($objects->[0]);
Condition33%1/3
$args{$type} || $self->$type($objects->[0])
l!l&&r!l&&!r
030
MC/DC0%0/2
$args{$type} || $self->$type($objects->[0])
$args{$type} $self->$type($objects->[0])
Truth table33%1/3
A || B
A= $args{$type}B= $self->$type($objects->[0])
ABresult
1X1
011
000
198
199 3 my @temp_files;
200 @temp_files =
201 $self->prelink(%args,
202 3 ▶ dl_name => $args{module_name}) if $args{lddl} && $self->need_prelink;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"lddl"} and $self->need_prelink 0 3 3
Condition66%2/3
$args{"lddl"} and $self->need_prelink
!ll&&!rl&&r
120
MC/DC0%0/2
$args{"lddl"} and $self->need_prelink
$args{"lddl"} $self->need_prelink
Truth table66%2/3
A and B
A= $args{"lddl"}B= $self->need_prelink
ABresult
0X0
100
111
203
204 my @linker_flags = ($self->split_like_shell($args{extra_linker_flags}),
205 $self->extra_link_args_after_prelink(%args, dl_name => $args{module_name},
206 3 prelink_res => \@temp_files));
207  
208 3 ▶ my @output = $args{lddl} ? $self->arg_share_object_file($out) : $self->arg_exec_file($out);
Branch: 1 branch
BranchTrueFalseTotal
$args{'lddl'} ? : 2 1 3
209 3 my @shrp = $self->split_like_shell($cf->{shrpenv});
210 3 my @ld = $self->split_like_shell($cf->{ld});
211
212 3 ▶ $self->do_system(@shrp, @ld, @output, @$objects, @linker_flags)
Branch: 1 branch
BranchTrueFalseTotal
$self->do_system(@shrp, @ld, @output, @$objects, @linker_flags) or die "error building $out from @$objects" 0 3 3
213 or die "error building $out from @$objects";
214
215 3 ▶ return wantarray ? ($out, @temp_files) : $out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
216 }
217  
218  
219 sub do_system {
220 6 ▶ my ($self, @cmd) = @_;
Subroutine do_system: called CC=2 SCAR=7.1
Pod undocumented
221 6 ▶ print "@cmd\n" if !$self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 6 0 6
222 6 return !system(@cmd);
223 }
224  
225 sub split_like_shell {
226 27 ▶ my ($self, $string) = @_;
Subroutine split_like_shell: called CC=4 SCAR=13.9
Pod undocumented
227
228 27 ▶ return () unless defined($string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 6 21 27
229 21 ▶ return @$string if UNIVERSAL::isa($string, 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($string, "ARRAY") 0 21 21
230 21 $string =~ s/^\s+|\s+$//g;
231 21 ▶ return () unless length($string);
Branch: 1 branch
BranchTrueFalseTotal
unless length $string 3 18 21
232
233 18 return Text::ParseWords::shellwords($string);
234 }
235  
236 # if building perl, perl's main source directory
237 sub perl_src {
238 # N.B. makemaker actually searches regardless of PERL_CORE, but
239 # only squawks at not finding it if PERL_CORE is set
240  
241 3 ▶ return unless $ENV{PERL_CORE};
Subroutine perl_src: called CC=6 SCAR=34.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PERL_CORE"} 3 0 3
242  
243 0 my $Updir = File::Spec->updir;
244 0 my $dir = File::Spec->curdir;
245  
246 # Try up to 5 levels upwards
247 0 for (0..10) {
248 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (-f "File::Spec"->catfile($dir, "config_h.SH") and -f "File::Spec"->catfile($dir, "perl.h") and -f "File::Spec"->catfile($dir, "lib", "Exporter.pm")) 0 0 0
Condition0%0/6
-f "File::Spec"->catfile($dir, "config_h.SH") and -f "File::Spec"->catfile($dir, "perl.h") and -f "File::Spec"->catfile($dir, "lib", "Exporter.pm")
!ll&&!rl&&r
000
-f "File::Spec"->catfile($dir, "config_h.SH") and -f "File::Spec"->catfile($dir, "perl.h")
!ll&&!rl&&r
000
MC/DC0%0/3
-f "File::Spec"->catfile($dir, "config_h.SH") and -f "File::Spec"->catfile($dir, "perl.h") and -f "File::Spec"->catfile($dir, "lib", "Exporter.pm")
-f "File::Spec"->catfile($dir, "config_h.SH") -f "File::Spec"->catfile($dir, "perl.h") -f "File::Spec"->catfile($dir, "lib", "Exporter.pm")
Truth table0%0/4
A and B and C
A= -f "File::Spec"->catfile($dir, "config_h.SH")B= -f "File::Spec"->catfile($dir, "perl.h")C= -f "File::Spec"->catfile($dir, "lib", "Exporter.pm")
ABCresult
0XX0
10X0
1100
1111
249 -f File::Spec->catfile($dir,"config_h.SH")
250 &&
251 -f File::Spec->catfile($dir,"perl.h")
252 &&
253 -f File::Spec->catfile($dir,"lib","Exporter.pm")
254 ) {
255 0 return Cwd::realpath( $dir );
256 }
257  
258 0 $dir = File::Spec->catdir($dir, $Updir);
259 }
260  
261 0 warn "PERL_CORE is set but I can't find your perl source!\n";
262 0 return ''; # return empty string if $ENV{PERL_CORE} but can't find dir ???
263 }
264  
265 # directory of perl's include files
266 sub perl_inc {
267 3 ▶ my $self = shift;
Subroutine perl_inc: called CC=2 SCAR=7.2
Pod undocumented
268  
269 3 ▶ $self->perl_src() || File::Spec->catdir($self->{config}{archlibexp},"CORE");
Branch: 1 branch
BranchTrueFalseTotal
$self->perl_src or "File::Spec"->catdir($self->{"config"}{"archlibexp"}, "CORE") 3 0 3
270 }
271  
272 sub DESTROY {
273 2 ▶ my $self = shift;
Subroutine DESTROY: called CC=1 SCAR=0.0
274 2 local($., $@, $!, $^E, $?);
275 2 $self->cleanup();
276 }
277  
278 2 1;
« blib/lib/ExtUtils/CBuilder/Platform/Windows.pm ↑ Summary Build »