buildlib/Clownfish/Build.pm

filter: Statementstmt 42.4% 70 / 165 Branchbran 12.5% 7 / 56 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 63.6% 14 / 22 Podpod 0.0% 0 / 8 totaltotal 33.3% 91 / 273 CC 36 SCAR 40.6
CC
36
Cov
33%
ACTION_test_valgrind
182.0
ACTION_dist
72.0
_run_make
42.0
CRAP 58.2
↑ Summary blib/lib/Clownfish.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package Clownfish::Build;
20  
21 1 my $IS_CPAN_DIST;
22  
23 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.1
24 1 $IS_CPAN_DIST = -e 'cfcore';
25  
26 1 ▶ if (!$IS_CPAN_DIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IS_CPAN_DIST) 0 1 1
27 0 unshift @INC,
28 '../../compiler/perl/blib/lib',
29 '../../compiler/perl/blib/arch',
30 '../../compiler/perl/lib'; # blib dir might not exist yet.
31 }
32 }
33  
34 1 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
35 Clownfish::CFC::Perl::Build
36 Clownfish::CFC::Perl::Build::Charmonic
37 1 );
38  
39 1 our $VERSION = '0.008000';
40 1 $VERSION = eval $VERSION;
41  
42 1 ▶use File::Spec::Functions qw( catdir catfile updir rel2abs );
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use File::Path qw( rmtree );
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use File::Copy qw( move );
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Cwd qw( getcwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 my @BASE_PATH = __PACKAGE__->cf_base_path;
50  
51 1 my $COMMON_SOURCE_DIR = catdir( @BASE_PATH, 'common' );
52 1 my $CFC_DIR = catdir( @BASE_PATH, updir(), 'compiler', 'perl' );
53 1 my $XS_SOURCE_DIR = 'xs';
54 1 my $CFC_BUILD = catfile( $CFC_DIR, 'Build' );
55 1 my $LIB_DIR = 'lib';
56 1 my $CORE_SOURCE_DIR;
57 my $TEST_SOURCE_DIR;
58 1 my $CHARMONIZER_C;
59 1 ▶if ($IS_CPAN_DIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IS_CPAN_DIST) { } 1 0 1
60 1 $CORE_SOURCE_DIR = 'cfcore';
61 1 $TEST_SOURCE_DIR = 'cftest';
62 1 $CHARMONIZER_C = 'charmonizer.c';
63 }
64 else {
65 0 $CORE_SOURCE_DIR = catdir( @BASE_PATH, 'core' );
66 0 $TEST_SOURCE_DIR = catdir( @BASE_PATH, 'test' );
67 0 $CHARMONIZER_C = catfile( $COMMON_SOURCE_DIR, 'charmonizer.c' );
68 }
69  
70 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my ( $class, %args ) = @_;
72 0 $args{include_dirs} = [ $CORE_SOURCE_DIR, $XS_SOURCE_DIR ];
73 $args{clownfish_params} = {
74 0 autogen_header => _autogen_header(),
75 include => [], # Don't use default includes.
76 source => [ $CORE_SOURCE_DIR, $TEST_SOURCE_DIR ],
77 modules => [
78 {
79 name => 'Clownfish',
80 parcels => [ 'Clownfish' ],
81 make_target => 'core_objects',
82 c_source_dirs => [ $XS_SOURCE_DIR ],
83 },
84 {
85 name => 'Clownfish::Test',
86 parcels => [ 'TestClownfish' ],
87 make_target => 'test_objects',
88 },
89 ],
90 };
91 0 my $self = $class->SUPER::new( recursive_test_files => 1, %args );
92  
93 # Fix for MSVC: Although the generated XS should be C89-compliant, it
94 # must be compiled in C++ mode like the rest of the code due to a
95 # mismatch between the sizes of the C++ bool type and the emulated bool
96 # type. (The XS code is compiled with Module::Build's extra compiler
97 # flags, not the Clownfish cflags.)
98 0 ▶ if ($Config{cc} =~ /^cl\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Clownfish::Build::Config{"cc"} =~ /^cl\b/) 0 0 0
99 0 my $extra_cflags = $self->extra_compiler_flags;
100 0 push @$extra_cflags, '/TP';
101 0 $self->extra_compiler_flags(@$extra_cflags);
102 }
103  
104 0 $self->charmonizer_params( create_makefile => 1 );
105 0 $self->charmonizer_params( charmonizer_c => $CHARMONIZER_C );
106  
107 0 return $self;
108 }
109  
110 0 ▶sub _run_make {
Subroutine _run_make: not called CC=6 SCAR=37.4
111 0 my ( $self, %params ) = @_;
112 0 my @command = @{ $params{args} };
113 0 my $dir = $params{dir};
114 0 my $current_directory = getcwd();
115 0 ▶ chdir $dir if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 0 0 0
116 0 unshift @command, 'CC=' . $self->config('cc');
117 0 ▶ if ( $self->config('cc') =~ /^cl\b/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->config('cc') =~ /^cl\b/) { } 0 0 0
elsif ($^O =~ /mswin/i) { } 0 0 0
118 0 unshift @command, "-f", "Makefile.MSVC";
119 }
120 elsif ( $^O =~ /mswin/i ) {
121 0 unshift @command, "-f", "Makefile.MinGW";
122 }
123 0 unshift @command, "$Config{make}";
124 0 ▶ system(@command) and confess("$Config{make} failed");
Branch: 1 branch
BranchTrueFalseTotal
system @command and confess(qq[$Clownfish::Build::Config{"make"} failed]) 0 0 0
125 0 ▶ chdir $current_directory if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 0 0 0
126 }
127  
128 1 ▶sub ACTION_cfc {
Subroutine ACTION_cfc: called CC=3 SCAR=20.0
Pod undocumented
129 1 my $self = shift;
130 1 ▶ return if $IS_CPAN_DIST;
Branch: 1 branch
BranchTrueFalseTotal
if $IS_CPAN_DIST 1 0 1
131 0 my $old_dir = getcwd();
132 0 chdir($CFC_DIR);
133 0 ▶ if ( !-f 'Build' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "Build") 0 0 0
134 0 print "\nBuilding Clownfish compiler... \n";
135 0 system("$^X Build.PL");
136 0 system("$^X Build code");
137 0 print "\nFinished building Clownfish compiler.\n\n";
138 }
139 0 chdir($old_dir);
140 }
141  
142 1 ▶sub ACTION_code {
Subroutine ACTION_code: called CC=3 SCAR=16.5
Pod undocumented
143 1 my $self = shift;
144  
145 1 $self->SUPER::ACTION_code;
146  
147 1 $self->cf_copy_include_file( 'XSBind.h' );
148  
149 # Check whether 'use Clownfish::Test' succeeds. If this fails, it is
150 # probably caused by a failure to find symbols from Clownfish.so,
151 # indicating a build problem. In this case, make the build fail, so
152 # we get the full build log on CPAN Testers. Also print contents of
153 # the generated Makefile.
154 1 my $error = system("$^X -Mblib -MClownfish::Test -e1");
155 1 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 1 1
156 0 print STDERR "Build succeeded, but 'use Clownfish::Test' failed.\n";
157 0 ▶ if ($ENV{AUTOMATED_TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"AUTOMATED_TESTING"}) 0 0 0
158 0 my $makefile = do { local(@ARGV, $/) = 'Makefile'; <> };
159 0 print STDERR "\nContents of Makefile:\n$makefile";
160 }
161 0 die;
162 }
163 }
164  
165 1 ▶sub ACTION_clownfish {
Subroutine ACTION_clownfish: called CC=1 SCAR=0.0
Pod undocumented
166 1 my $self = shift;
167  
168 1 $self->depends_on('cfc');
169  
170 1 $self->SUPER::ACTION_clownfish;
171  
172 # Make sure to remove empty directory.
173 1 $self->add_to_cleanup( catdir( $LIB_DIR, 'Clownfish', 'Docs' ) );
174 }
175  
176 1 ▶sub ACTION_compile_custom_xs {
Subroutine ACTION_compile_custom_xs: called CC=4 SCAR=14.1
Pod undocumented
177 1 my $self = shift;
178  
179 1 $self->depends_on('charmony');
180  
181 # Add extra compiler flags from Charmonizer.
182 1 my $charm_cflags = $self->charmony('EXTRA_CFLAGS');
183 1 ▶ if ($charm_cflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charm_cflags) 1 0 1
184 1 my $cf_cflags = $self->clownfish_params('cflags');
185 1 ▶ if ($cf_cflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cf_cflags) { } 0 1 1
186 0 $cf_cflags .= " $charm_cflags";
187 }
188 else {
189 1 $cf_cflags = $charm_cflags;
190 }
191 1 $self->clownfish_params( cflags => $cf_cflags );
192 }
193  
194 # Add extra linker flags from Charmonizer.
195 1 my $charm_ldflags = $self->charmony('EXTRA_LDFLAGS');
196 1 ▶ if ($charm_ldflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charm_ldflags) 1 0 1
197 1 my $extra_ldflags = $self->extra_linker_flags;
198 1 push @$extra_ldflags, $self->split_like_shell($charm_ldflags);
199 1 $self->extra_linker_flags(@$extra_ldflags);
200 }
201  
202 1 $self->SUPER::ACTION_compile_custom_xs;
203 }
204  
205 0 ▶sub _valgrind_base_command {
Subroutine _valgrind_base_command: not called CC=1 SCAR=6.9
206 return
207 0 "PERL_DESTRUCT_LEVEL=2 CLOWNFISH_VALGRIND=1 valgrind "
208 . "--leak-check=yes "
209 . "--show-reachable=yes "
210 . "--dsymutil=yes "
211 . "--suppressions=../../devel/conf/cfruntime-perl.supp ";
212 }
213  
214 # Run the entire test suite under Valgrind.
215 #
216 # For this to work, the test suite must be run under a debugging Perl.
217 #
218 # A custom suppressions file will probably be needed -- use your judgment.
219 # To pass in one or more local suppressions files, provide a comma separated
220 # list like so:
221 #
222 # $ ./Build test_valgrind --suppressions=foo.supp,bar.supp
223 0 ▶sub ACTION_test_valgrind {
Subroutine ACTION_test_valgrind: not called CC=13 SCAR=52.0
Pod undocumented
224 0 my $self = shift;
225 # Debian's debugperl uses the Config.pm of the standard system perl
226 # so -DDEBUGGING won't be detected.
227 0 ▶ die "Must be run under a perl that was compiled with -DDEBUGGING"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config("ccflags") =~ /-D?DEBUGGING\b/ or $^X =~ /\bdebugperl\b/ 0 0 0
Condition0%0/3
$self->config("ccflags") =~ /-D?DEBUGGING\b/ or $^X =~ /\bdebugperl\b/
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->config("ccflags") =~ /-D?DEBUGGING\b/ or $^X =~ /\bdebugperl\b/
$self->config("ccflags") =~ /-D?DEBUGGING\b/ $^X =~ /\bdebugperl\b/
Truth table0%0/3
A or B
A= $self->config("ccflags") =~ /-D?DEBUGGING\b/B= $^X =~ /\bdebugperl\b/
ABresult
1X1
011
000
228 unless $self->config('ccflags') =~ /-D?DEBUGGING\b/
229 || $^X =~ /\bdebugperl\b/;
230 0 $self->depends_on('code');
231  
232 # Unbuffer STDOUT, grab test file names and suppressions files.
233 0 $|++;
234 0 my $t_files = $self->find_test_files; # not public M::B API, may fail
235 0 my $valgrind_command = $self->_valgrind_base_command;
236  
237 0 ▶ if ( my $local_supp = $self->args('suppressions') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $local_supp = $self->args("suppressions")) 0 0 0
238 0 for my $supp ( split( ',', $local_supp ) ) {
239 0 $valgrind_command .= "--suppressions=$supp ";
240 }
241 }
242  
243 # Iterate over test files.
244 0 my @failed;
245 0 for my $t_file (@$t_files) {
246  
247 # Run test file under Valgrind.
248 0 print "Testing $t_file...";
249 0 ▶ die "Can't find '$t_file'" unless -f $t_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $t_file 0 0 0
250 0 my $command = "$valgrind_command $^X -Mblib $t_file 2>&1";
251 0 my $output = "\n" . ( scalar localtime(time) ) . "\n$command\n";
252 0 $output .= `$command`;
253  
254 # Screen-scrape Valgrind output, looking for errors and leaks.
255 0 ▶ if ( $?
Branch: 1 branch
BranchTrueFalseTotal
if ($? or $output =~ /ERROR SUMMARY:\s+[^0\s]/ or $output =~ /definitely lost:\s+[^0\s]/ or $output =~ /possibly lost:\s+[^0\s]/ or $output =~ /still reachable:\s+[^0\s]/) { } 0 0 0
Condition0%0/12
$? or $output =~ /ERROR SUMMARY:\s+[^0\s]/ or $output =~ /definitely lost:\s+[^0\s]/ or $output =~ /possibly lost:\s+[^0\s]/ or $output =~ /still reachable:\s+[^0\s]/
l!l&&r!l&&!r
000
$? or $output =~ /ERROR SUMMARY:\s+[^0\s]/ or $output =~ /definitely lost:\s+[^0\s]/ or $output =~ /possibly lost:\s+[^0\s]/
l!l&&r!l&&!r
000
$? or $output =~ /ERROR SUMMARY:\s+[^0\s]/ or $output =~ /definitely lost:\s+[^0\s]/
l!l&&r!l&&!r
000
$? or $output =~ /ERROR SUMMARY:\s+[^0\s]/
l!l&&r!l&&!r
000
MC/DC0%0/5
$? or $output =~ /ERROR SUMMARY:\s+[^0\s]/ or $output =~ /definitely lost:\s+[^0\s]/ or $output =~ /possibly lost:\s+[^0\s]/ or $output =~ /still reachable:\s+[^0\s]/
$? $output =~ /ERROR SUMMARY:\s+[^0\s]/ $output =~ /definitely lost:\s+[^0\s]/ $output =~ /possibly lost:\s+[^0\s]/ $output =~ /still reachable:\s+[^0\s]/
Truth table0%0/6
A or B or C or D or E
A= $?B= $output =~ /ERROR SUMMARY:\s+[^0\s]/C= $output =~ /definitely lost:\s+[^0\s]/D= $output =~ /possibly lost:\s+[^0\s]/E= $output =~ /still reachable:\s+[^0\s]/
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
256 or $output =~ /ERROR SUMMARY:\s+[^0\s]/
257 or $output =~ /definitely lost:\s+[^0\s]/
258 or $output =~ /possibly lost:\s+[^0\s]/
259 or $output =~ /still reachable:\s+[^0\s]/ )
260 {
261 0 print " failed.\n";
262 0 push @failed, $t_file;
263 0 print "$output\n";
264 }
265 else {
266 0 print " succeeded.\n";
267 }
268 }
269  
270 # If there are failed tests, print a summary list.
271 0 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 0 0
272 0 print "\nFailed "
273 . scalar @failed . "/"
274 . scalar @$t_files
275 . " test files:\n "
276 . join( "\n ", @failed ) . "\n";
277 0 exit(1);
278 }
279 }
280  
281 0 ▶sub _autogen_header {
Subroutine _autogen_header: not called CC=1 SCAR=6.9
282 0 return <<"END_AUTOGEN";
283 ***********************************************
284  
285 !!!! DO NOT EDIT !!!!
286  
287 This file was auto-generated by Build.PL.
288  
289 ***********************************************
290  
291 Licensed to the Apache Software Foundation (ASF) under one or more
292 contributor license agreements. See the NOTICE file distributed with
293 this work for additional information regarding copyright ownership.
294 The ASF licenses this file to You under the Apache License, Version 2.0
295 (the "License"); you may not use this file except in compliance with
296 the License. You may obtain a copy of the License at
297  
298 http://www.apache.org/licenses/LICENSE-2.0
299  
300 Unless required by applicable law or agreed to in writing, software
301 distributed under the License is distributed on an "AS IS" BASIS,
302 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
303 See the License for the specific language governing permissions and
304 limitations under the License.
305 END_AUTOGEN
306 }
307  
308 # Run the cleanup targets for independent prerequisite builds.
309 0 ▶sub _clean_prereq_builds {
Subroutine _clean_prereq_builds: not called CC=3 SCAR=24.8
310 0 my $self = shift;
311 0 ▶ if ( -e $CFC_BUILD ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $CFC_BUILD) 0 0 0
312 0 my $old_dir = getcwd();
313 0 chdir $CFC_DIR;
314 0 ▶ system("$^X Build realclean")
Branch: 1 branch
BranchTrueFalseTotal
system "$^X Build realclean" and die "Clownfish clean failed" 0 0 0
315 and die "Clownfish clean failed";
316 0 chdir $old_dir;
317 }
318 }
319  
320 0 ▶sub ACTION_clean {
Subroutine ACTION_clean: not called CC=1 SCAR=6.9
Pod undocumented
321 0 my $self = shift;
322 0 _clean_prereq_builds($self);
323 0 $self->SUPER::ACTION_clean;
324 }
325  
326 0 ▶sub ACTION_dist {
Subroutine ACTION_dist: not called CC=8 SCAR=42.8
Pod undocumented
327 0 my $self = shift;
328  
329 0 ▶ die("Module::Build 0.40_11 is required for ./Build dist")
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Build::VERSION < "0.4011" 0 0 0
330 if $Module::Build::VERSION < 0.40_11;
331  
332 # Create POD.
333 0 $self->depends_on('clownfish');
334 0 rmtree("autogen");
335  
336 # We build our Perl release tarball from a subdirectory rather than from
337 # the top-level $REPOS_ROOT. Because some assets we need are outside this
338 # directory, we need to copy them in.
339 0 my %to_copy = (
340 '../../CHANGES' => 'CHANGES',
341 '../../CONTRIBUTING.md' => 'CONTRIBUTING.md',
342 '../../LICENSE' => 'LICENSE',
343 '../../NOTICE' => 'NOTICE',
344 '../../README.md' => 'README.md',
345 $CORE_SOURCE_DIR => 'cfcore',
346 $TEST_SOURCE_DIR => 'cftest',
347 $CHARMONIZER_C => 'charmonizer.c',
348 );
349 0 print "Copying files...\n";
350 0 ▶ while ( my ( $from, $to ) = each %to_copy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %to_copy) 0 0 0
351 0 ▶ confess("'$to' already exists") if -e $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to 0 0 0
352 0 ▶ system("cp -R $from $to") and confess("cp failed");
Branch: 1 branch
BranchTrueFalseTotal
system "cp -R $from $to" and confess("cp failed") 0 0 0
353 }
354 0 ▶ move( "MANIFEST", "MANIFEST.bak" ) or die "move() failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
move("MANIFEST", "MANIFEST.bak") or die "move() failed: $!" 0 0 0
355 0 $self->depends_on("manifest");
356 0 $self->SUPER::ACTION_dist;
357  
358 # Now that the tarball is packaged up, delete the copied assets.
359 0 rmtree($_) for values %to_copy;
360 0 unlink("META.yml");
361 0 unlink("META.json");
362 0 ▶ move( "MANIFEST.bak", "MANIFEST" ) or die "move() failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
move("MANIFEST.bak", "MANIFEST") or die "move() failed: $!" 0 0 0
363 }
364  
365 1 1;
366  
↑ Summary blib/lib/Clownfish.pm »