buildlib/Lucy/Build.pm

filter: Statementstmt 40.5% 47 / 116 Branchbran 8.3% 3 / 36 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 61.1% 11 / 18 Podpod 0.0% 0 / 8 totaltotal 30.5% 61 / 200 CC 27 SCAR 42.5
CC
27
Cov
30%
ACTION_test_valgrind
182.0
ACTION_dist
72.0
ACTION_semiclean
20.0
CRAP 70.1
↑ Summary buildlib/Lucy/Test/TestUtils.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 Lucy::Build;
20 1 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 Clownfish::CFC::Perl::Build
22 Clownfish::CFC::Perl::Build::Charmonic
23 1 );
24  
25 1 our $VERSION = '0.008000';
26 1 $VERSION = eval $VERSION;
27  
28 1 ▶use File::Spec::Functions qw( catdir catfile rel2abs updir );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use File::Path qw( rmtree );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use File::Copy qw( move );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Cwd qw( getcwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 my $LIB_DIR = 'lib';
36 1 my $IS_CPAN_DIST = -e 'cfcore';
37 1 my $CHARMONIZER_C;
38 1 ▶if ($IS_CPAN_DIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IS_CPAN_DIST) { } 1 0 1
39 1 $CHARMONIZER_C = 'charmonizer.c';
40 }
41 else {
42 0 $CHARMONIZER_C = catfile( updir(), 'common', 'charmonizer.c' );
43 }
44  
45 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
46 0 my $self = shift->SUPER::new( recursive_test_files => 1, @_ );
47  
48 # These compiler flags are only used to compile Perl-specific files
49 # with ExtUtils::CBuilder.
50 0 my $extra_cflags = $self->extra_compiler_flags;
51  
52 # Fix for MSVC: Although the generated XS should be C89-compliant, it
53 # must be compiled in C++ mode like the rest of the code due to a
54 # mismatch between the sizes of the C++ bool type and the emulated bool
55 # type. (The XS code is compiled with Module::Build's extra compiler
56 # flags, not the Clownfish cflags.)
57 0 ▶ if ($Config{cc} =~ /^cl\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lucy::Build::Config{"cc"} =~ /^cl\b/) 0 0 0
58 0 push @$extra_cflags, '/TP';
59 }
60  
61 0 ▶ if ( $ENV{LUCY_DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"LUCY_DEBUG"}) 0 0 0
62 0 push @$extra_cflags, '-DLUCY_DEBUG';
63 }
64  
65 0 $self->extra_compiler_flags(@$extra_cflags);
66  
67 0 $self->charmonizer_params( create_makefile => 1 );
68 0 $self->charmonizer_params( charmonizer_c => $CHARMONIZER_C );
69  
70 0 $self->clownfish_params( autogen_header => $self->autogen_header );
71  
72 0 return $self;
73 }
74  
75 0 ▶sub ACTION_copy_clownfish_includes {
Subroutine ACTION_copy_clownfish_includes: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my $self = shift;
77  
78 0 $self->SUPER::ACTION_copy_clownfish_includes;
79  
80 0 $self->cf_copy_include_file( qw( Lucy Util ToolSet.h ) );
81 }
82  
83 0 ▶sub _valgrind_base_command {
Subroutine _valgrind_base_command: not called CC=1 SCAR=6.9
84 return
85 0 "PERL_DESTRUCT_LEVEL=2 LUCY_VALGRIND=1 valgrind "
86 . "--leak-check=yes "
87 . "--show-reachable=yes "
88 . "--dsymutil=yes "
89 . "--suppressions=../devel/conf/lucyperl.supp ";
90 }
91  
92 # Run the entire test suite under Valgrind.
93 #
94 # For this to work, the test suite must be run under a debugging Perl.
95 #
96 # A custom suppressions file will probably be needed -- use your judgment.
97 # To pass in one or more local suppressions files, provide a comma separated
98 # list like so:
99 #
100 # $ ./Build test_valgrind --suppressions=foo.supp,bar.supp
101 0 ▶sub ACTION_test_valgrind {
Subroutine ACTION_test_valgrind: not called CC=13 SCAR=52.0
Pod undocumented
102 0 my $self = shift;
103 # Debian's debugperl uses the Config.pm of the standard system perl
104 # so -DDEBUGGING won't be detected.
105 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
106 unless $self->config('ccflags') =~ /-D?DEBUGGING\b/
107 || $^X =~ /\bdebugperl\b/;
108 0 $self->depends_on('code');
109  
110 # Unbuffer STDOUT, grab test file names.
111 0 $|++;
112 0 my $t_files = $self->find_test_files; # not public M::B API, may fail
113 0 my $valgrind_command = $self->_valgrind_base_command;
114  
115 0 ▶ if ( my $local_supp = $self->args('suppressions') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $local_supp = $self->args("suppressions")) 0 0 0
116 0 for my $supp ( split( ',', $local_supp ) ) {
117 0 $valgrind_command .= "--suppressions=$supp ";
118 }
119 }
120  
121 # Iterate over test files.
122 0 my @failed;
123 0 for my $t_file (@$t_files) {
124  
125 # Run test file under Valgrind.
126 0 print "Testing $t_file...";
127 0 ▶ die "Can't find '$t_file'" unless -f $t_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $t_file 0 0 0
128 0 my $command = "$valgrind_command $^X -Mblib $t_file 2>&1";
129 0 my $output = "\n" . ( scalar localtime(time) ) . "\n$command\n";
130 0 $output .= `$command`;
131  
132 # Screen-scrape Valgrind output, looking for errors and leaks.
133 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
134 or $output =~ /ERROR SUMMARY:\s+[^0\s]/
135 or $output =~ /definitely lost:\s+[^0\s]/
136 or $output =~ /possibly lost:\s+[^0\s]/
137 or $output =~ /still reachable:\s+[^0\s]/ )
138 {
139 0 print " failed.\n";
140 0 push @failed, $t_file;
141 0 print "$output\n";
142 }
143 else {
144 0 print " succeeded.\n";
145 }
146 }
147  
148 # If there are failed tests, print a summary list.
149 0 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 0 0
150 0 print "\nFailed "
151 . scalar @failed . "/"
152 . scalar @$t_files
153 . " test files:\n "
154 . join( "\n ", @failed ) . "\n";
155 0 exit(1);
156 }
157 }
158  
159 1 ▶sub ACTION_clownfish {
Subroutine ACTION_clownfish: called CC=1 SCAR=0.0
Pod undocumented
160 1 my $self = shift;
161  
162 1 $self->SUPER::ACTION_clownfish;
163  
164 # Make sure to remove empty directory.
165 1 $self->add_to_cleanup( catdir( $LIB_DIR, 'Lucy', 'Docs' ) );
166 }
167  
168 1 ▶sub ACTION_compile_custom_xs {
Subroutine ACTION_compile_custom_xs: called CC=3 SCAR=11.3
Pod undocumented
169 1 my $self = shift;
170  
171 1 $self->depends_on(qw( charmony ));
172  
173 # Add extra compiler flags from Charmonizer.
174 1 my $charm_cflags = $self->charmony('EXTRA_CFLAGS');
175 1 ▶ if ($charm_cflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charm_cflags) 1 0 1
176 1 my $cf_cflags = $self->clownfish_params('cflags');
177 1 ▶ if ($cf_cflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cf_cflags) { } 0 1 1
178 0 $cf_cflags .= " $charm_cflags";
179 }
180 else {
181 1 $cf_cflags = $charm_cflags;
182 }
183 1 $self->clownfish_params( cflags => $cf_cflags );
184 }
185  
186 1 $self->SUPER::ACTION_compile_custom_xs;
187 }
188  
189 0 ▶sub autogen_header {
Subroutine autogen_header: not called CC=1 SCAR=6.9
Pod undocumented
190 0 my $self = shift;
191 0 return <<"END_AUTOGEN";
192 ***********************************************
193  
194 !!!! DO NOT EDIT !!!!
195  
196 This file was auto-generated by Build.PL.
197  
198 ***********************************************
199  
200 Licensed to the Apache Software Foundation (ASF) under one or more
201 contributor license agreements. See the NOTICE file distributed with
202 this work for additional information regarding copyright ownership.
203 The ASF licenses this file to You under the Apache License, Version 2.0
204 (the "License"); you may not use this file except in compliance with
205 the License. You may obtain a copy of the License at
206  
207 http://www.apache.org/licenses/LICENSE-2.0
208  
209 Unless required by applicable law or agreed to in writing, software
210 distributed under the License is distributed on an "AS IS" BASIS,
211 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212 See the License for the specific language governing permissions and
213 limitations under the License.
214 END_AUTOGEN
215 }
216  
217 0 ▶sub ACTION_dist {
Subroutine ACTION_dist: not called CC=8 SCAR=42.8
Pod undocumented
218 0 my $self = shift;
219  
220 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
221 if $Module::Build::VERSION < 0.40_11;
222  
223 # Create POD.
224 0 $self->depends_on('pod');
225 0 rmtree("autogen");
226  
227 # We build our Perl release tarball from $REPOS_ROOT/perl, rather than
228 # from the top-level.
229 #
230 # Because some items we need are outside this directory, we need to copy a
231 # bunch of stuff. After the tarball is packaged up, we delete the copied
232 # directories.
233 0 my %to_copy = (
234 '../core' => 'cfcore',
235 '../test' => 'cftest',
236 '../modules' => 'modules',
237 '../devel' => 'devel',
238 '../lemon' => 'lemon',
239 '../common/sample/us_constitution' => 'sample/us_constitution',
240 '../CHANGES' => 'CHANGES',
241 '../CONTRIBUTING' => 'CONTRIBUTING',
242 '../LICENSE' => 'LICENSE',
243 '../NOTICE' => 'NOTICE',
244 '../README' => 'README',
245 $CHARMONIZER_C => 'charmonizer.c',
246 );
247 0 print "Copying files...\n";
248 0 ▶ while (my ($from, $to) = each %to_copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %to_copy) 0 0 0
249 0 ▶ confess("'$to' already exists") if -e $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to 0 0 0
250 0 ▶ system("cp -R $from $to") and confess();
Branch: 1 branch
BranchTrueFalseTotal
system "cp -R $from $to" and confess() 0 0 0
251 }
252  
253 0 ▶ move( "MANIFEST", "MANIFEST.bak" ) or die "move() failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
move("MANIFEST", "MANIFEST.bak") or die "move() failed: $!" 0 0 0
254 0 $self->depends_on('manifest');
255 0 $self->SUPER::ACTION_dist;
256  
257 # Clean up.
258 0 print "Removing copied files...\n";
259 0 rmtree($_) for values %to_copy;
260 0 unlink("META.yml");
261 0 unlink("META.json");
262 0 ▶ move( "MANIFEST.bak", "MANIFEST" ) or die "move() failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
move("MANIFEST.bak", "MANIFEST") or die "move() failed: $!" 0 0 0
263 }
264  
265 0 ▶sub ACTION_semiclean {
Subroutine ACTION_semiclean: not called CC=4 SCAR=30.0
Pod undocumented
266 0 my $self = shift;
267 0 print "Cleaning up most build files.\n";
268 my @candidates
269 0 = grep { $_ !~ /(charmonizer|^_charm|charmony|charmonize|snowstem)/ }
270 $self->cleanup;
271 0 for my $path ( map { glob($_) } @candidates ) {
272 0 ▶ next unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
273 0 rmtree($path);
274 0 ▶ confess("Failed to remove '$path'") if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
275 }
276 }
277  
278 1 1;
279  
280 __END__
↑ Summary buildlib/Lucy/Test/TestUtils.pm »