Build.PL

filter: Statementstmt 14.4% 69 / 479 Branchbran 4.1% 9 / 216 Conditioncond 2.3% 1 / 43 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 22.5% 14 / 62 Podpod n/a totaltotal 11.2% 93 / 826 SCAR 93.4
CC
126
Cov
11%
test_in_docker
552.0
install
132.0
_debian_package
110.0
CRAP 11429.9
« blib/lib/Doit.pm ↑ Summary lib/Doit.pm »
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3  
4 #
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2017,2018,2019,2020,2021,2022 Slaven Rezic. All rights reserved.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
13 #
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use lib "$FindBin::RealBin/lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Cwd qw(realpath getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Doit;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Doit::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Doit::Util qw(in_directory);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 my $doit = Doit->init;
28  
29 1 my $Build_PL_file_contents = do {
30 1 ▶ open my $fh, '<', 'Build.PL'
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "Build.PL" or &error("Error opening Build.PL: $!") 0 1 1
31 or error "Error opening Build.PL: $!";
32 1 local $/ = undef;
33 1 <$fh>;
34 };
35 1 my $Build_PL_md5hex = md5_hex $Build_PL_file_contents;
36  
37 1 for (@ARGV) {
38 3 ▶ if (/^[^-].*=.*/) { # looks like oldfashioned option without leading dash (e.g. "installdirs=vendor")
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^-].*=.*/) 0 3 3
39 0 s/^/--/;
40 }
41 }
42  
43 1 ▶if (basename($0) eq 'Build.PL') {
Branch: 1 branch
BranchTrueFalseTotal
if (basename($0) eq "Build.PL") 0 1 1
44 0 _Build_PL_mode();
45 }
46  
47 # Check if Build is up-to-date (md5 check, no timestamp check)
48 {
49 1 ▶ open my $fh, '<', $0
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $0 or &error("Can't open $0: $!") 0 1 1
50 or error "Can't open $0: $!";
51 1 my $shebang = <$fh>;
52 1 my $md5_line = <$fh>;
53 1 ▶ if (my($old_md5hex) = $md5_line =~ m{^# MD5: (\S+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($old_md5hex) = $md5_line =~ /^# MD5: (\S+)/) { } 1 0 1
54 1 ▶ if ($old_md5hex ne $Build_PL_md5hex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_md5hex ne $Build_PL_md5hex) 0 1 1
55 0 my $perl;
56 0 ▶ if (($perl) = $shebang =~ m{^#!\s*(.*)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (($perl) = $shebang =~ /^#!\s*(.*)/) { } 0 0 0
57 # parsed it
58 } else {
59 0 warning "Cannot parse perl interpreter path out of '$shebang', fallback to 'perl'";
60 0 $perl = "perl";
61 }
62 0 error "Build.PL changed, please run '$perl Build.PL' again";
63 }
64 } else {
65 0 error "Unexpected: no MD5 found in '$md5_line'";
66 }
67 }
68  
69 1 require Getopt::Long;
70 1 my %opt = (verbose => 0, uninst => 0, destdir => '', create_packlist => 1);
71 1 $Build_PL::ARGV=$Build_PL::ARGV if 0; # cease -w
72 1 @ARGV = (@$Build_PL::ARGV, @ARGV);
73 1 ▶if ($ENV{PERL_MB_OPT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERL_MB_OPT"}) 0 1 1
74 0 require Text::ParseWords;
75 0 push @ARGV, Text::ParseWords::shellwords($ENV{PERL_MB_OPT});
76 }
77 Getopt::Long::GetOptions(
78 1 ▶ \%opt,
Branch: 1 branch
BranchTrueFalseTotal
&Getopt::Long::GetOptions(\%opt, "allow_mb_mismatch=i", "config=s%", "create_packlist=i", "destdir=s", "installdirs=s", "install_base=s", "install_path=s%", "prefix=s", "uninst:1", "verbose:1", "versionlib=s", "version=s", "extra_compiler_flags=s", "extra_linker_flags=s") or &error("usage: $0 [options]") 0 1 1
79 'allow_mb_mismatch=i',
80 'config=s%',
81 'create_packlist=i',
82 'destdir=s',
83 'installdirs=s',
84 'install_base=s',
85 'install_path=s%',
86 'prefix=s',
87 'uninst:1',
88 'verbose:1',
89 'versionlib=s',
90 'version=s',
91 # The following are just ignored, but currently set by cover
92 'extra_compiler_flags=s',
93 'extra_linker_flags=s',
94 )
95 or error "usage: $0 [options]";
96  
97 1 ▶my $action = shift || 'build';
Condition50%1/2
shift @ARGV || 'build'
l!l
10
MC/DC0%0/1
shift @ARGV || 'build'
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
98 1 $action =~ s/-/_/g;
99 1 ▶if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 0 1 1
100 0 error "No arguments allowed";
101 }
102 {
103 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
104 1 &$action;
105 }
106  
107 sub build {
108 0 ▶ build_libs();
Subroutine build: not called CC=1 SCAR=6.9
109 0 manifypods();
110 }
111  
112 sub build_libs {
113 0 ▶ $doit->make_path('blib/lib');
Subroutine build_libs: not called CC=4 SCAR=26.9
114 0 $doit->make_path('blib/arch'); # not used, but keep ExtUtils::Install quiet
115 0 require File::Find;
116 0 my @pm_files;
117 1 ▶ File::Find::find(sub { no warnings 'once'; push @pm_files, $File::Find::name if /\.(pm|pod)$/ && -f $_ }, "lib");
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine __ANON__: not called CC=3 SCAR=18.1
Branch: 1 branch
BranchTrueFalseTotal
if /\.(pm|pod)$/ and -f $_ 0 0 0
Condition0%0/3
/\.(pm|pod)$/ and -f $_
!ll&&!rl&&r
000
MC/DC0%0/2
/\.(pm|pod)$/ and -f $_
/\.(pm|pod)$/ -f $_
Truth table0%0/3
A and B
A= /\.(pm|pod)$/B= -f $_
ABresult
0X0
100
111
118 0 for my $file (@pm_files) {
119 0 my $dest = 'blib/'.$file;
120 0 ▶ if (!-e $dest || -M $dest > -M $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $dest or -M $dest > -M $file) 0 0 0
Condition0%0/3
not -e $dest or -M $dest > -M $file
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $dest or -M $dest > -M $file
not -e $dest -M $dest > -M $file
Truth table0%0/3
not(A) or B
A= not -e $destB= -M $dest > -M $file
ABresult
1X1
011
000
121 0 $doit->make_path(dirname($dest));
122 0 $doit->copy($file, $dest);
123 }
124 }
125 }
126  
127 sub manifypods {
128 # Handles only Pods in .pod files (which is the case in the Doit distribution)
129 0 ▶ require File::Find;
Subroutine manifypods: not called CC=2 SCAR=16.5
130 0 require Pod::Man;
131 0 ▶ my $mansep = $^O =~ m{^(MSWin32|cygwin)$} ? '.' : '::';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /^(MSWin32|cygwin)$/ ? : 0 0 0
132 File::Find::find
133 ({
134 wanted => sub {
135 0 ▶ if (-f $_ && /\.pod$/) {
Subroutine __ANON__: not called CC=8 SCAR=40.5
Branch: 1 branch
BranchTrueFalseTotal
if (-f $_ and /\.pod$/) 0 0 0
Condition0%0/3
-f $_ and /\.pod$/
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ and /\.pod$/
-f $_ /\.pod$/
Truth table0%0/3
A and B
A= -f $_B= /\.pod$/
ABresult
0X0
100
111
136 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
137 0 my $pod = $File::Find::name;
138 0 my $section = 3; # no scripts yet, so we can hardcode here
139 0 my %options = (section => $section);
140 0 (my $man = $pod) =~ s{^lib.}{};
141 0 $man =~ s{/+}{$mansep}g;
142 0 $man =~ s{\.pod$}{.$Config{"man${section}ext"}};
143 0 $man = "blib/man$section/$man";
144 0 ▶ if (!-e $man || -M $man > -M $pod || -M $man > -M "Build") {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $man or -M $man > -M $pod or -M $man > -M "Build") 0 0 0
Condition0%0/6
not -e $man or -M $man > -M $pod or -M $man > -M "Build"
l!l&&r!l&&!r
000
not -e $man or -M $man > -M $pod
l!l&&r!l&&!r
000
MC/DC0%0/3
not -e $man or -M $man > -M $pod or -M $man > -M "Build"
not -e $man -M $man > -M $pod -M $man > -M "Build"
Truth table0%0/4
not(A) or B or C
A= not -e $manB= -M $man > -M $podC= -M $man > -M "Build"
ABCresult
1XX1
01X1
0011
0000
145 0 $doit->make_path(dirname($man));
146 0 my $parser = Pod::Man->new(%options);
147 0 ▶ if ($doit->is_dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doit->is_dry_run) { } 0 0 0
148 0 info "$pod -> $man (dry-run)";
149 } else {
150 0 info "$pod -> $man";
151 0 ▶ $parser->parse_from_file($pod, $man)
Branch: 1 branch
BranchTrueFalseTotal
$parser->parse_from_file($pod, $man) or &error("Could not install $man") 0 0 0
152 or error "Could not install $man";
153 }
154 0 $doit->chmod(0644, $man); # XXX should this be changeable? like $PERM_RW in Makefile.PL?
155 }
156 }
157 },
158 0 no_chdir => 1,
159 },
160 "lib");
161 }
162  
163 sub clean {
164 0 ▶ $doit->remove_tree('blib');
Subroutine clean: not called CC=1 SCAR=6.9
165 }
166  
167 0 ▶sub realclean { &clean }
Subroutine realclean: not called CC=1 SCAR=6.9
168  
169 sub test {
170 1 ▶ local $ENV{PERL_DL_NONLAZY} = 1;
Subroutine test: called CC=1 SCAR=0.0
171 1 require File::Glob;
172 1 require File::Spec;
173 1 $doit->system($^X, "-MExtUtils::Command::MM", "-MTest::Harness", "-e", 'undef *Test::Harness::Switches; test_harness(0, "blib/lib", "blib/arch")', File::Glob::bsd_glob(File::Spec->catfile("t", "*.t")));
174 # $doit->system(_prove_path(), '-b', 't'); # use right perl?
175 }
176  
177 sub test_xt {
178 0 ▶ $doit->system(_prove_path(), '-b', 'xt'); # use right perl?
Subroutine test_xt: not called CC=1 SCAR=6.9
179 }
180  
181 sub test_installed {
182 0 ▶ my $t_dir = "$FindBin::RealBin/t";
Subroutine test_installed: not called CC=2 SCAR=17.9
183 0 ▶ chdir "/"
Branch: 1 branch
BranchTrueFalseTotal
chdir "/" or &error("Cannot chdir to /: $!") 0 0 0
184 or error "Cannot chdir to /: $!";
185 0 $doit->system(_prove_path(), $t_dir);
186 }
187  
188 sub test_in_docker {
189 0 ▶ my $distro_spec = $ENV{DISTRO_SPEC}; # XXX this should be a proper option!
Subroutine test_in_docker: not called CC=23 SCAR=63.1
190 0 ▶ if (!$distro_spec || $distro_spec !~ m{^.*:.*$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distro_spec and $distro_spec =~ /^.*:.*$/) 0 0 0
Condition0%0/3
$distro_spec and $distro_spec =~ /^.*:.*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$distro_spec and $distro_spec =~ /^.*:.*$/
$distro_spec $distro_spec =~ /^.*:.*$/
Truth table0%0/3
A and B
A= $distro_specB= $distro_spec =~ /^.*:.*$/
ABresult
0X0
100
111
191 0 error "Please set DISTRO_SPEC environment variable to something like 'debian:jessie'";
192 }
193 0 my $more_testing = $ENV{XXX_MORE_TESTING}; # XXX this will be a proper option in future!
194 0 ▶ Doit::Log::set_label("[$distro_spec" . ($more_testing ? " (more)" : "") . "]");
Branch: 1 branch
BranchTrueFalseTotal
$more_testing ? : 0 0 0
195 0 for my $tool (qw(docker)) {
196 0 $doit->qx('which', $tool); # existence check
197 }
198 0 require File::Temp;
199 0 my $dir = File::Temp::tempdir("Doit_test_in_docker_XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
200 0 my $dockerfile = <<"EOF";
201 FROM $distro_spec
202  
203 EOF
204 0 ▶ if ($ENV{XXX_INVALIDATE_CACHE}) { # XXX this will be a proper option in future!
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"XXX_INVALIDATE_CACHE"}) 0 0 0
205 0 _add_Dockerfile_invalidate_cmd(\$dockerfile);
206 }
207 0 my $add_opts = {};
208 0 $dockerfile .= _fix_Dockerfile_for_dist($distro_spec, $add_opts);
209 0 ▶ if ($distro_spec =~ m{^centos:}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($distro_spec =~ /^centos:/) { } 0 0 0
elsif ($distro_spec =~ /^alpine(:|$)/) { } 0 0 0
210 ######################################################################
211 # CentOS
212 # From https://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F
213 0 ▶ if ($distro_spec =~ m{:6$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($distro_spec =~ /:6$/) { } 0 0 0
elsif ($distro_spec =~ /:7$/) { } 0 0 0
elsif ($distro_spec =~ /:8$/) { } 0 0 0
214 0 $dockerfile .= <<"EOF";
215 RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
216 EOF
217 } elsif ($distro_spec =~ m{:7$}) {
218 0 $dockerfile .= <<"EOF";
219 RUN yum -y install epel-release
220 EOF
221 } elsif ($distro_spec =~ m{:8$}) {
222 0 $dockerfile .= <<"EOF";
223 RUN yum -y install epel-release
224 EOF
225 } else {
226 0 info "No EPEL support for $distro_spec";
227 }
228 0 $dockerfile .= <<"EOF";
229 RUN yum -y install \\
230 sudo \\
231 rsync \\
232 "perl(ExtUtils::MakeMaker)" \\
233 "perl(Digest::MD5)" \\
234 "perl(Test::More)" \\
235 make \\
236 git
237  
238 EOF
239 0 ▶ if ($distro_spec =~ m{:8$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro_spec =~ /:8$/) 0 0 0
240 # Requires also PowerTools repo additionally to EPEL
241 0 $dockerfile .= <<"EOF";
242 RUN dnf -y install 'dnf-command(config-manager)'
243 RUN yum config-manager --set-enabled PowerTools
244 EOF
245 }
246 0 $dockerfile .= <<"EOF";
247 RUN yum -y install \\
248 "perl(IPC::Run)"
249 EOF
250 0 ▶ if ($distro_spec !~ m{:8$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distro_spec =~ /:8$/) 0 0 0
251 # Currently not available in CentOS8
252 0 $dockerfile .= <<"EOF";
253 RUN yum -y install \\
254 "perl(Net::OpenSSH)"
255 EOF
256 }
257 0 ▶ if ($distro_spec =~ m{:6$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro_spec =~ /:6$/) { } 0 0 0
258 0 $dockerfile .= <<"EOF";
259 RUN curl -L https://cpanmin.us | perl - App::cpanminus
260  
261 # Not available as an RPM
262 RUN cpanm --quiet --notest CPAN::Meta
263 EOF
264 } else {
265 0 $dockerfile .= <<"EOF";
266 RUN yum -y install \\
267 "perl(CPAN::Meta)"
268 EOF
269 }
270 0 ▶ if ($more_testing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more_testing) 0 0 0
271 0 $dockerfile .= <<"EOF";
272 RUN yum -y install \\
273 "perl(Capture::Tiny)" \\
274 "perl(Term::ANSIColor)" \\
275 "perl(BSD::Resource)" \\
276 "perl(CPAN::Meta::Validator)" \\
277 "perl(LWP::UserAgent)" \\
278 file
279  
280 ENV TRAVIS 1
281 ENV DOIT_TEST_WITH_SUDO 1
282  
283 EOF
284 0 ▶ if ($distro_spec =~ m{:6$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro_spec =~ /:6$/) { } 0 0 0
285 0 $dockerfile .= <<"EOF";
286 # Term::ANSIColor exists, but is too old (no colorstrip function)
287 RUN cpanm --quiet --notest "Term::ANSIColor~>=2.01"
288  
289 RUN yum -y install python34-pip
290  
291 EOF
292 } else {
293 0 $dockerfile .= <<"EOF";
294 RUN yum -y install python3-pip
295 EOF
296 }
297 }
298 } elsif ($distro_spec =~ m{^alpine(:|$)}) {
299 0 $dockerfile .= <<"EOF";
300 RUN apk update
301 # perl-utils for prove
302 # shadow for useradd
303 RUN apk add sudo rsync git perl perl-utils make shadow
304 EOF
305 0 ▶ if ($more_testing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more_testing) 0 0 0
306 0 $dockerfile .= <<"EOF";
307 RUN apk add py3-pip
308  
309 #ENV TRAVIS 1
310 ENV DOIT_TEST_WITH_SUDO 1
311  
312 EOF
313 }
314  
315 } else {
316 ######################################################################
317 # Debian-like (Debian, Ubuntu, LinuxMint ...)
318 0 ▶ my @packages = (
Branch: 1 branch
BranchTrueFalseTotal
$distro_spec eq 'ubuntu:precise' ? : 0 0 0
319 'libipc-run-perl',
320 ($distro_spec eq 'ubuntu:precise' ? () : 'libnet-openssh-perl'),
321 'sudo',
322 'rsync',
323 'git',
324 );
325 0 my $packages_spec = join(" \\\n", map { " $_" } @packages);
326 0 ▶ if ($distro_spec =~ m{^(ubuntu:precise)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro_spec =~ /^(ubuntu:precise)$/) 0 0 0
327 # See https://gist.github.com/dergachev/f5da514802fcbbb441a1
328 0 $dockerfile .= <<'EOF'
329 RUN sed -i.bak -r 's/(archive|security).ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
330 EOF
331 }
332 0 $dockerfile .= <<"EOF";
333 ENV DEBIAN_FRONTEND noninteractive
334  
335 RUN apt-get$add_opts->{apt_get_update_opts} update && apt-get install -y --no-install-recommends \\
336 $packages_spec
337  
338 EOF
339 0 ▶ if ($more_testing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($more_testing) 0 0 0
340 0 ▶ my @more_packages = (
Branch: 1 branch
BranchTrueFalseTotal
$distro_spec eq 'ubuntu:precise' ? : 0 0 0
341 'libbsd-resource-perl',
342 'libcapture-tiny-perl',
343 'libcpan-meta-perl',
344 'libwww-perl',
345 'perl-modules',
346 'locales',
347 'file',
348 ($distro_spec eq 'ubuntu:precise' ? () : 'python3-pip'),
349 );
350 0 my $more_packages_spec = join(" \\\n", map { " $_" } @more_packages);
351 0 $dockerfile .= <<"EOF";
352 RUN apt-get install -y --no-install-recommends \\
353 $more_packages_spec
354  
355 ENV TRAVIS 1
356 ENV DOIT_TEST_WITH_SUDO 1
357  
358 EOF
359 }
360 }
361  
362 0 for my $env_key (qw(HARNESS_OPTIONS)) {
363 0 ▶ if (defined $ENV{$env_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{$env_key}) 0 0 0
364 0 $dockerfile .= <<"EOF";
365 ENV $env_key "$ENV{$env_key}"
366 EOF
367 }
368 }
369  
370 0 $doit->write_binary("$dir/Dockerfile", $dockerfile);
371 in_directory {
372 0 ▶ (my $tag = $distro_spec) =~ s{:}{-}g;
Subroutine __ANON__: not called CC=1 SCAR=6.9
373 0 $tag = 'doit-test-' . $tag;
374 0 $doit->system(qw(docker build -t), $tag, qw(.));
375 0 $doit->system(
376 qw(docker run), '-v', "$FindBin::RealBin:/data:ro", $tag,
377 'sh', '-c', 'rsync -a --no-owner --no-group --exclude=blib "--exclude=Doit-*.tar.gz" /data/ /tmp/Doit/ && cd /tmp/Doit && perl Build.PL && ./Build && ./Build generate_META_json && ./Build test && ./Build test_xt && ./Build dist_install_and_test'
378 );
379 0 } $dir;
380  
381 0 Doit::Log::set_label(undef);
382 }
383  
384 # Run docker-based tests on a number of Linux distributions:
385 # the stable ones of Debian, Ubuntu and CentOS, and some
386 # older versions of these distributions.
387 sub test_standard {
388 0 ▶ Doit::Log::set_label("[local]");
Subroutine test_standard: not called CC=5 SCAR=34.0
389 0 $doit->system($^X, 'Build.PL');
390 0 $doit->system('./Build');
391 0 $doit->system('./Build', 'test');
392 0 Doit::Log::set_label(undef);
393 0 for my $distro_spec ('ubuntu:jammy', 'debian:bullseye', 'ubuntu:focal', 'debian:buster', 'ubuntu:bionic', 'centos:7', 'debian:stretch', 'debian:jessie', 'ubuntu:xenial', 'ubuntu:precise', 'centos:6', 'alpine:latest') {
394 0 local $ENV{DISTRO_SPEC} = $distro_spec;
395 0 for my $more_testing (0, 1) {
396 0 ▶ next if $more_testing && $distro_spec eq 'centos:6'; # centos:6 is unmaintained since Nov 2020, and some yum operations don't work anymore. See also https://support.plesk.com/hc/en-us/articles/360017922619-After-November-30th-2020-updating-system-packages-on-Plesk-server-with-CentOS-6-fails-Cannot-find-a-valid-baseurl-for-repo-base
Branch: 1 branch
BranchTrueFalseTotal
if $more_testing and $distro_spec eq "centos:6" 0 0 0
Condition0%0/3
$more_testing and $distro_spec eq "centos:6"
!ll&&!rl&&r
000
MC/DC0%0/2
$more_testing and $distro_spec eq "centos:6"
$more_testing $distro_spec eq "centos:6"
Truth table0%0/3
A and B
A= $more_testingB= $distro_spec eq "centos:6"
ABresult
0X0
100
111
397 0 local $ENV{XXX_MORE_TESTING} = $more_testing;
398 0 $doit->system('./Build', 'test_in_docker');
399 }
400 }
401 }
402  
403 sub test_kwalitee (;$) {
404 0 ▶ my($distdir) = @_;
Subroutine test_kwalitee: not called CC=3 SCAR=24.8
405 # If cwd is used then more tests fail,
406 # because META files are not available here.
407 0 ▶ $distdir = $FindBin::RealBin if !defined $distdir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $distdir 0 0 0
408  
409 0 ▶ if (eval { require Test::Kwalitee; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Test::Kwalitee; 1 } }) { } 0 0 0
410 in_directory {
411 0 ▶ local $ENV{RELEASE_TESTING} = 1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
412 0 eval { $doit->system($^X, '-MTest::More', '-MTest::Kwalitee=kwalitee_ok', '-e', 'kwalitee_ok(qw(-has_manifest -has_meta_yml)); done_testing') };
413 0 } $distdir;
414 } else {
415 0 warning "Test::Kwalitee is not installed";
416 }
417 }
418  
419 sub test_pod (;$) {
420 0 ▶ my($distdir) = @_;
Subroutine test_pod: not called CC=3 SCAR=24.8
421 0 ▶ $distdir = $FindBin::RealBin if !defined $distdir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $distdir 0 0 0
422  
423 0 ▶ if (eval { require Test::Pod; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Test::Pod; 1 } }) { } 0 0 0
424 in_directory {
425 0 ▶ eval { $doit->system($^X, '-MTest::Pod', '-e', 'all_pod_files_ok()') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
426 0 } $distdir;
427 } else {
428 0 warning "Test::Pod is not installed";
429 }
430 }
431  
432 sub test_cpan_versions {
433 0 ▶ my($distdir) = @_;
Subroutine test_cpan_versions: not called CC=2 SCAR=17.9
434  
435 0 ▶ if ($doit->which("cpan_check_versions")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doit->which('cpan_check_versions')) { } 0 0 0
436 in_directory {
437 0 ▶ $doit->system('cpan_check_versions', '-remote');
Subroutine __ANON__: not called CC=1 SCAR=6.9
438 0 } $distdir;
439 } else {
440 0 warning <<EOF;
441 No cpan_check_versions found in PATH, cannot check for properly
442 incremented VERSIONs. Please check git://github.com/eserte/srezic-misc.git
443 EOF
444 }
445 }
446  
447 sub git_checks {
448 0 ▶ $doit->add_component('git');
Subroutine git_checks: not called CC=5 SCAR=34.0
449  
450 0 my $status = $doit->git_short_status;
451 0 ▶ if ($status eq '<<') {
Branch: 1 branch
BranchTrueFalseTotal
if ($status eq "<<") 0 0 0
452 0 error 'Working directory has uncomitted changes: ' . `git status`;
453 }
454 0 ▶ if ($status eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($status eq "*") 0 0 0
455 0 error 'Working directory has files not under git control (and not in .gitignore or .git/info/exclude): ' . `git status`;
456 }
457  
458 0 my $Doit_VERSION = _get_Doit_VERSION();
459  
460 0 my $out = $doit->info_qx(qw(git tag -l), $Doit_VERSION);
461 0 ▶ if (defined $out && $out ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out and $out ne "") 0 0 0
Condition0%0/3
defined $out and $out ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $out and $out ne ""
defined $out $out ne ""
Truth table0%0/3
A and B
A= defined $outB= $out ne ""
ABresult
0X0
100
111
462 0 error "A git tag $Doit_VERSION already exists";
463 }
464 }
465  
466 sub distdir {
467 0 ▶ my(%options) = @_;
Subroutine distdir: not called CC=6 SCAR=37.4
468 0 my $temporary = delete $options{temporary};
469 0 ▶ error "Unhandled options: " . join(" ", %options) if %options;
Branch: 1 branch
BranchTrueFalseTotal
if %options 0 0 0
470  
471 0 require File::Temp;
472 0 my $tempdir = File::Temp::tempdir("Doit_distdir_XXXXXXXX", TMPDIR => 1, CLEANUP => $temporary);
473 0 my $Doit_VERSION = _get_Doit_VERSION();
474 0 my $distdir = "$tempdir/Doit-$Doit_VERSION";
475 0 $doit->mkdir($distdir);
476 0 for my $line (split /\0/, $doit->info_qx({quiet=>1}, 'git', 'ls-files', '-z')) {
477 0 ▶ next if ($line =~ m{^( \.travis\.yml
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^( \.travis\.yml | \.?appveyor\.yml | \.gitignore )$/x 0 0 0
478 | \.?appveyor\.yml
479 | \.gitignore
480 )$}x);
481 # XXX maybe implement also MANIFEST.SKIP?
482 0 my $dirname = dirname $line;
483 0 ▶ if ($dirname ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirname ne ".") 0 0 0
484 0 $doit->make_path("$distdir/$dirname");
485 }
486 0 $doit->copy($line, "$distdir/$dirname/");
487 }
488  
489 0 generate_META_json("$distdir/META.json");
490 0 generate_META_yml("$distdir/META.yml" );
491  
492 0 test_kwalitee($distdir);
493 0 test_pod($distdir);
494  
495 # If not temporary, then it is assumed that the
496 # interactive distdir action is called, and
497 # provide information to the user.
498 0 ▶ if (!$temporary) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($temporary) 0 0 0
499 0 info "Distribution directory is $distdir";
500 }
501  
502 0 $distdir;
503 }
504  
505 sub dist {
506 0 ▶ if (!$ENV{DOIT_TEST_SKIP_SOME_CHECKS}) {
Subroutine dist: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DOIT_TEST_SKIP_SOME_CHECKS"}) 0 0 0
507 0 git_checks();
508 }
509 # else skip because Doit version is usually not incremented in
510 # this phase and the git tag already exists
511  
512  
513 0 my $tarfile = _get_tarfilename();
514 0 ▶ if (-e $tarfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $tarfile) 0 0 0
515 0 error "$tarfile already exists";
516 }
517 0 my $distdir = distdir(temporary => 1);
518  
519 0 ▶ if (!$ENV{DOIT_TEST_SKIP_SOME_CHECKS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DOIT_TEST_SKIP_SOME_CHECKS"}) 0 0 0
520 0 test_cpan_versions($distdir);
521 }
522 # else because versions of all Doit modules are usually not
523 # incremented in this phase
524  
525 in_directory {
526 # Note: tar cfvz C:/... ... does not seem to work on Windows
527 # (for all or some tar versions?). Error message is:
528 # tar (child): Cannot connect to C: resolve failed
529 # So create in cwd first, and move to final location.
530 0 ▶ $doit->system('tar', 'cfvz', basename($tarfile), basename($distdir));
Subroutine __ANON__: not called CC=1 SCAR=6.9
531 0 $doit->move(basename($tarfile), $tarfile);
532 0 } "$distdir/..";
533 }
534  
535 sub dist_install_and_test {
536 0 ▶ local $ENV{DOIT_TEST_SKIP_SOME_CHECKS} = 1; # XXX is there a better interface?
Subroutine dist_install_and_test: not called CC=2 SCAR=17.9
537 0 my $tarfile = _get_tarfilename();
538 0 ▶ if (!-e $tarfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $tarfile) 0 0 0
539 0 dist();
540 }
541 0 require File::Temp;
542 0 my $dir = File::Temp::tempdir("Doit_dist_install_and_test_XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
543 0 my $Doit_VERSION = _get_Doit_VERSION();
544 in_directory {
545 # Note: see above for tar under Windows problems
546 0 ▶ $doit->move($tarfile, basename($tarfile));
Subroutine __ANON__: not called CC=1 SCAR=6.9
547 0 $doit->system('tar', 'xfz', basename($tarfile));
548 in_directory {
549 0 ▶ $doit->system($^X, 'Build.PL');
Subroutine __ANON__: not called CC=2 SCAR=17.9
550 0 ▶ my @Build = $^O eq 'MSWin32' ? ($^X, 'Build') : ('./Build');
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
551 0 $doit->system(@Build);
552 0 $doit->system(@Build, 'test');
553 0 $doit->system(@Build, 'install');
554 0 $doit->system(@Build, 'test-installed');
555 0 } "Doit-$Doit_VERSION";
556 0 } $dir;
557 }
558  
559 sub dist_install_with_cpanm {
560 0 ▶ my $tarfile = _get_tarfilename();
Subroutine dist_install_with_cpanm: not called CC=2 SCAR=17.9
561 0 ▶ if (!-e $tarfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $tarfile) 0 0 0
562 0 dist();
563 }
564 0 $doit->system('cpanm', $tarfile);
565 0 test_installed();
566 }
567  
568 sub look {
569 0 ▶ my $distdir = distdir(temporary => 1);
Subroutine look: not called CC=1 SCAR=6.9
570 in_directory {
571 0 ▶ info "Spawning $ENV{SHELL} in $distdir...";
Subroutine __ANON__: not called CC=1 SCAR=6.9
572 0 local $ENV{DOIT_BUILD_SHELL_LEVEL} = $ENV{DOIT_BUILD_SHELL_LEVEL};
573 0 $ENV{DOIT_BUILD_SHELL_LEVEL}++;
574 0 $doit->system($ENV{SHELL});
575 0 } $distdir;
576 }
577  
578 sub cover {
579 0 ▶ $doit->system(_cover_path(), '--test');
Subroutine cover: not called CC=1 SCAR=6.9
580 }
581  
582 sub show_cover {
583 0 ▶ cover();
Subroutine show_cover: not called CC=3 SCAR=24.8
584 0 ▶ my $browser = $^O eq 'darwin' ? 'open' : $doit->which('xdg-open') ? 'xdg-open' : 'firefox';
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'darwin' ? : 0 0 0
$doit->which('xdg-open') ? : 0 0 0
585 0 $doit->system($browser, "$FindBin::RealBin/cover_db/coverage.html");
586 }
587  
588 sub install {
589 0 ▶ build();
Subroutine install: not called CC=11 SCAR=48.8
590 # XXX check if test suite was run?
591  
592 # MOD_INSTALL = $(ABSPERLRUN) -MExtUtils::Install -e 'install([ from_to => {@ARGV}, verbose => '\''$(VERBINST)'\'', uninstall_shadows => '\''$(UNINST)'\'', dir_mode => '\''$(PERM_DIR)'\'' ]);' --
593 # $(MOD_INSTALL) \
594  
595 # for a perl install:
596 # read "$(PERL_ARCHLIB)/auto/$(FULLEXT)/.packlist" \
597 # write "$(DESTINSTALLARCHLIB)/auto/$(FULLEXT)/.packlist" \
598 # "$(INST_LIB)" "$(DESTINSTALLPRIVLIB)" \
599 # "$(INST_ARCHLIB)" "$(DESTINSTALLARCHLIB)" \
600 # "$(INST_BIN)" "$(DESTINSTALLBIN)" \
601 # "$(INST_SCRIPT)" "$(DESTINSTALLSCRIPT)" \
602 # "$(INST_MAN1DIR)" "$(DESTINSTALLMAN1DIR)" \
603 # "$(INST_MAN3DIR)" "$(DESTINSTALLMAN3DIR)"
604  
605 # for a site install:
606 # read "$(SITEARCHEXP)/auto/$(FULLEXT)/.packlist" \
607 # write "$(DESTINSTALLSITEARCH)/auto/$(FULLEXT)/.packlist" \
608 # "$(INST_LIB)" "$(DESTINSTALLSITELIB)" \
609 # "$(INST_ARCHLIB)" "$(DESTINSTALLSITEARCH)" \
610 # "$(INST_BIN)" "$(DESTINSTALLSITEBIN)" \
611 # "$(INST_SCRIPT)" "$(DESTINSTALLSITESCRIPT)" \
612 # "$(INST_MAN1DIR)" "$(DESTINSTALLSITEMAN1DIR)" \
613 # "$(INST_MAN3DIR)" "$(DESTINSTALLSITEMAN3DIR)"
614
615 0 require Data::Dumper;
616 0 require ExtUtils::Install;
617 0 my $FULLEXT = 'Doit';
618 0 my $INST_LIB = 'blib/lib';
619 0 my $INST_ARCHLIB = 'blib/arch';
620 0 my $INST_BIN = 'blib/bin';
621 0 my $INST_SCRIPT = 'blib/script';
622 0 my $INST_MAN1DIR = 'blib/man1';
623 0 my $INST_MAN3DIR = 'blib/man3';
624 0 my $PERM_DIR = '755';
625 my @euii_args = (
626 from_to => {
627 (
628 $opt{install_base}
629 ?
630 (
631 read => "$Config{sitearchexp}/auto/$FULLEXT/.packlist",
632 ($opt{create_packlist} ? (write => "$opt{install_base}/lib/perl5/$Config{archname}/auto/$FULLEXT/.packlist") : ()),
633 $INST_LIB => "$opt{install_base}/lib/perl5",
634 $INST_ARCHLIB => "$opt{install_base}/lib/perl5",
635 $INST_BIN => "$opt{install_base}/bin",
636 $INST_SCRIPT => "$opt{install_base}/bin",
637 $INST_MAN1DIR => "$opt{install_base}/man/man1",
638 $INST_MAN3DIR => "$opt{install_base}/man/man3",
639 )
640 :
641 ($opt{installdirs}||'') eq 'core'
642 ?
643 (
644 read => "$Config{archlib}/auto/$FULLEXT/.packlist",
645 ($opt{create_packlist} ? (write => "$opt{destdir}$Config{installarchlib}/auto/$FULLEXT/.packlist") : ()),
646 $INST_LIB => "$opt{destdir}$Config{installprivlib}",
647 $INST_ARCHLIB => "$opt{destdir}$Config{installarchlib}",
648 $INST_BIN => "$opt{destdir}$Config{installbin}",
649 $INST_SCRIPT => "$opt{destdir}$Config{installscript}",
650 $INST_MAN1DIR => "$opt{destdir}$Config{installman1dir}",
651 $INST_MAN3DIR => "$opt{destdir}$Config{installman3dir}",
652 )
653 :
654 ($opt{installdirs}||'') eq 'vendor'
655 ?
656 (
657 read => "$Config{vendorlib}/auto/$FULLEXT/.packlist",
658 ($opt{create_packlist} ? (write => "$opt{destdir}$Config{installvendorarch}/auto/$FULLEXT/.packlist") : ()),
659 $INST_LIB => "$opt{destdir}$Config{installvendorlib}",
660 $INST_ARCHLIB => "$opt{destdir}$Config{installvendorarch}",
661 $INST_BIN => "$opt{destdir}$Config{installvendorbin}",
662 $INST_SCRIPT => "$opt{destdir}$Config{installvendorscript}",
663 $INST_MAN1DIR => "$opt{destdir}$Config{installvendorman1dir}",
664 $INST_MAN3DIR => "$opt{destdir}$Config{installvendorman3dir}",
665 )
666 : # default is site
667 (
668 read => "$Config{sitearchexp}/auto/$FULLEXT/.packlist",
669 ($opt{create_packlist} ? (write => "$opt{destdir}$Config{installsitearch}/auto/$FULLEXT/.packlist") : ()),
670 $INST_LIB => "$opt{destdir}$Config{installsitelib}",
671 $INST_ARCHLIB => "$opt{destdir}$Config{installsitearch}",
672 $INST_BIN => "$opt{destdir}$Config{installsitebin}",
673 $INST_SCRIPT => "$opt{destdir}$Config{installsitescript}",
674 $INST_MAN1DIR => "$opt{destdir}$Config{installsiteman1dir}",
675 $INST_MAN3DIR => "$opt{destdir}$Config{installsiteman3dir}",
676 )
677 )
678 },
679 verbose => $opt{verbose},
680 uninstall_shadows => $opt{uninst},
681 0 ▶ dir_mode => $PERM_DIR,
Branch: 7 branches
BranchTrueFalseTotal
$opt{'install_base'} ? : 0 0 0
$opt{'create_packlist'} ? : 0 0 0
($opt{'installdirs'} || '') eq 'core' ? : 0 0 0
$opt{'create_packlist'} ? : 0 0 0
($opt{'installdirs'} || '') eq 'vendor' ? : 0 0 0
$opt{'create_packlist'} ? : 0 0 0
$opt{'create_packlist'} ? : 0 0 0
Condition0%0/4
$opt{'installdirs'} || ''
l!l
00
$opt{'installdirs'} || ''
l!l
00
MC/DC0%0/1
$opt{'installdirs'} || ''
$opt{'installdirs'}
MC/DC0%0/1
$opt{'installdirs'} || ''
$opt{'installdirs'}
Truth table0%0/2
A
A= $opt{'installdirs'}
Aresult
11
00
Truth table0%0/2
A
A= $opt{'installdirs'}
Aresult
11
00
682 dry_run => $doit->is_dry_run,
683 );
684 0 my $euii_args_dump = Data::Dumper->new([{ @euii_args }],[qw()])->Indent(1)->Useqq(1)->Sortkeys(1)->Terse(1)->Dump;
685 0 info "Run ExtUtils::Install::install with parameters\n" . $euii_args_dump;
686 0 ExtUtils::Install::install([@euii_args]);
687 0 ▶ if ($doit->is_dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doit->is_dry_run) 0 0 0
688 0 info "(this was dry-run mode)";
689 }
690 }
691  
692 {
693 0 my $Doit_VERSION;
694  
695 sub _get_Doit_VERSION () {
696 0 ▶ return $Doit_VERSION if defined $Doit_VERSION;
Subroutine _get_Doit_VERSION: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
if defined $Doit_VERSION 0 0 0
697  
698 {
699 0 my $Doit_pm = $INC{"Doit.pm"};
700 0 ▶ open my $fh, $Doit_pm or die "Cannot open $Doit_pm: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $Doit_pm or die "Cannot open ${Doit_pm}: $!" 0 0 0
701 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
702 0 ▶ if (/\$VERSION\s*=\s*'(.*)'/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\$VERSION\s*=\s*'(.*)'/) 0 0 0
703 0 $Doit_VERSION = $1;
704 0 last;
705 }
706 }
707 0 ▶ if (!defined $Doit_VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Doit_VERSION) 0 0 0
708 0 error "Fatal: Cannot find \$VERSION in $Doit_pm";
709 }
710 }
711 0 ▶ if ($Doit_VERSION !~ m{^\d+\.[\d_]+$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Doit_VERSION =~ /^\d+\.[\d_]+$/) 0 0 0
712 0 error "Doit.pm VERSION $Doit_VERSION does not look as expected";
713 }
714 # Check also for numerical value of version
715 0 ▶ if (!defined $Doit::VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Doit::VERSION) 0 0 0
716 0 error "Unexpected: cannot find \$VERSION in loaded Doit.pm";
717 }
718 {
719 0 (my $Doit_numerical_version = $Doit_VERSION) =~ s{_}{}g;
720 0 ▶ if ($Doit_numerical_version != $Doit::VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Doit_numerical_version != $Doit::VERSION) 0 0 0
721 0 error "Unexpected: parsed version $Doit_VERSION is not numerically equal to loaded version $Doit::VERSION";
722 }
723 }
724 0 $Doit_VERSION;
725 }
726 }
727  
728 0 sub _get_tarfilename () {
729 0 ▶ my $Doit_VERSION = _get_Doit_VERSION();
Subroutine _get_tarfilename: not called CC=1 SCAR=6.9
730 0 getcwd . "/Doit-" . $Doit_VERSION . ".tar.gz";
731 }
732  
733 sub _generate_META ($;$) {
734 0 ▶ my($destfile, $meta_version) = @_;
Subroutine _generate_META: not called CC=4 SCAR=30.0
735  
736 0 require CPAN::Meta;
737 0 require ExtUtils::MakeMaker;
738 0 my $meta = CPAN::Meta->new({
739 name => 'Doit',
740 author => 'Slaven Rezic <srezic@cpan.org>',
741 abstract => 'a scripting framework',
742 license => 'perl',
743 version => MM->parse_version("$FindBin::RealBin/lib/Doit.pm"),
744 prereqs => {
745 configure => {
746 requires => {
747 'Digest::MD5' => 0,
748 'Exporter' => 5.57, # use Exporter "import"
749 'File::Path' => 2.0, # make_path
750 },
751 },
752 runtime => {
753 recommends => {
754 'IPC::Run' => 0,
755 'Net::OpenSSH' => 0,
756 },
757 requires => {
758 'perl' => 5.006,
759 'Exporter' => 5.57, # use Exporter "import"
760 'File::Path' => 2.07, # make_path
761 },
762 },
763 test => {
764 requires => {
765 'Test::More' => 0,
766 },
767 },
768 },
769 resources => {
770 repository => { url => 'git://github.com/eserte/Doit' },
771 },
772 generated_by => "Doit version " . _get_Doit_VERSION(),
773 });
774 0 ▶ if ($doit->is_dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doit->is_dry_run) { } 0 0 0
775 0 ▶ info "Would create $destfile" . (defined $meta_version ? " (version $meta_version)" : "") . " (dry-run)";
Branch: 1 branch
BranchTrueFalseTotal
defined $meta_version ? : 0 0 0
776 } else {
777 0 ▶ $meta->save($destfile, (defined $meta_version ? { version => $meta_version } : ()));
Branch: 1 branch
BranchTrueFalseTotal
defined $meta_version ? : 0 0 0
778 }
779 }
780  
781 sub generate_META_json (;$) {
782 0 ▶ my $destfile = shift || 'META.json';
Subroutine generate_META_json: not called CC=2 SCAR=17.9
Condition0%0/2
shift() || 'META.json'
l!l
00
MC/DC0%0/1
shift() || 'META.json'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
783 0 _generate_META $destfile;
784 }
785  
786 sub generate_META_yml (;$) {
787 0 ▶ my $destfile = shift || 'META.yml';
Subroutine generate_META_yml: not called CC=2 SCAR=17.9
Condition0%0/2
shift() || 'META.yml'
l!l
00
MC/DC0%0/1
shift() || 'META.yml'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
788 0 _generate_META $destfile, 1.4;
789 }
790  
791 # XXX the debian package build functionality should go into
792 # a separate Doit component
793  
794 sub debian_package {
795 0 ▶ _debian_package('--depends' => 'perl, libnet-openssh-perl, libipc-run-perl', '--add-distro-version' => '1');
Subroutine debian_package: not called CC=1 SCAR=6.9
796 }
797  
798 sub _debian_package {
799 0 ▶ my(%opts) = @_;
Subroutine _debian_package: not called CC=10 SCAR=47.0
800  
801 0 for my $tool (qw(dh-make-perl)) { # XXX maybe add git here?
802 0 $doit->qx('which', $tool); # existence check
803 }
804  
805 0 my $distdir = distdir(temporary => 1);
806  
807 0 my $version = delete $opts{'--version'};
808 0 my $add_distro_version = delete $opts{'--add-distro-version'};
809 0 ▶ if (!defined $version) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 0 0 0
810 0 chomp(my $git_describe = eval { $doit->info_qx('git', 'describe') }); # XXX what if this fails? Optionally made fatal?
811 0 ▶ if (defined $git_describe) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $git_describe) { } 0 0 0
812 0 ▶ if ($git_describe =~ m{^([0-9\._]+)$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($git_describe =~ /^([0-9\._]+)$/) { } 0 0 0
elsif ($git_describe =~ /^([0-9\._]+)-(\d+)-g(.*)/) { } 0 0 0
813 0 $version = $1;
814 } elsif ($git_describe =~ m{^([0-9\._]+)-(\d+)-g(.*)}) {
815 0 $version = $1."+git".$2."+".$3."-1"; # XXX make "1" configurable?
816 } else {
817 0 error "Cannot parse output from git describe: '$git_describe'";
818 }
819 0 $version =~ s{_}{-}; # replace "devel" version specifier
820 0 ▶ if ($add_distro_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_distro_version) 0 0 0
821 0 chomp(my $dist_id = $doit->qx({quiet=>1}, 'lsb_release', '-si'));
822 0 chomp(my $rel = $doit->qx({quiet=>1}, 'lsb_release', '-sr'));
823 0 ▶ if ($dist_id eq 'Debian') {
Branch: 3 branches
BranchTrueFalseTotal
if ($dist_id eq 'Debian') { } 0 0 0
elsif ($dist_id eq 'LinuxMint') { } 0 0 0
elsif ($dist_id eq 'Ubuntu') { } 0 0 0
824 0 $rel =~ s{^(\d+).*}{$1};
825 0 $version .= "+deb${rel}u${add_distro_version}";
826 } elsif ($dist_id eq 'LinuxMint') {
827 0 $version .= "+linuxmint${rel}u${add_distro_version}";
828 } elsif ($dist_id eq 'Ubuntu') {
829 0 $version .= "~ubuntu${rel}.${add_distro_version}";
830 } else {
831 0 error "No distro version support for '$dist_id'";
832 }
833 }
834 } else {
835 0 warning "No information using git-describe available --- use automatic version detection";
836 }
837 }
838  
839 0 my $deb;
840 in_directory {
841 0 ▶ $doit->system(qw(dh-make-perl --build --vcs none), (defined $version ? ('--version', $version) : ()), %opts);
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 0 0 0
842 0 require File::Glob;
843 0 my(@debs) = File::Glob::bsd_glob("$distdir/../*.deb");
844 0 ▶ if (@debs != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@debs != 1) 0 0 0
845 0 error "Expecting exactly one generated .deb, but got: <@debs>\n";
846 }
847 0 $deb = $debs[0];
848 0 } $distdir;
849 0 $doit->copy($deb, basename($deb));
850 0 print basename($deb), "\n";
851 }
852  
853 sub debian_package_with_docker {
854 0 ▶ my $distro_spec = $ENV{DISTRO_SPEC}; # XXX this should be a proper option!
Subroutine debian_package_with_docker: not called CC=7 SCAR=40.3
855 0 ▶ if (!$distro_spec || $distro_spec !~ m{^.*:.*$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distro_spec and $distro_spec =~ /^.*:.*$/) 0 0 0
Condition0%0/3
$distro_spec and $distro_spec =~ /^.*:.*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$distro_spec and $distro_spec =~ /^.*:.*$/
$distro_spec $distro_spec =~ /^.*:.*$/
Truth table0%0/3
A and B
A= $distro_specB= $distro_spec =~ /^.*:.*$/
ABresult
0X0
100
111
856 0 error "Please set DISTRO_SPEC environment variable to something like 'debian:jessie'";
857 }
858 0 for my $tool (qw(docker)) {
859 0 $doit->qx('which', $tool); # existence check
860 }
861  
862 # Cannot access directories outside of /Users when working
863 # with docker-machine @ Mac, see for an explanation:
864 # https://stackoverflow.com/questions/37673140/docker-volume-located-in-tmp-on-osx-empty
865 0 my $limited_volume_availability = $^O eq 'darwin';
866  
867 0 require File::Temp;
868 0 my $dir = File::Temp::tempdir("Doit_debian_package_docker_XXXXXXXX", TMPDIR => !$limited_volume_availability, CLEANUP => 1);
869 0 $dir = realpath $dir; # docker volumes have to be specified with absolute paths
870  
871 0 ▶ my $pkgdir = $limited_volume_availability ? "$FindBin::RealBin/pkg" : "/tmp";
Branch: 1 branch
BranchTrueFalseTotal
$limited_volume_availability ? : 0 0 0
872 0 ▶ if (!-d $pkgdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $pkgdir) 0 0 0
873 0 $doit->mkdir($pkgdir);
874 }
875  
876 0 my $use_workdir = $ENV{USE_WORKDIR}; # XXX this should be a proper option
877 0 ▶ if ($use_workdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_workdir) { } 0 0 0
878 # no --cvs-exclude --- git-describe has to work
879 0 $doit->system('rsync', '-a', '--exclude=blib', '.', $dir);
880 } else {
881 0 $doit->add_component('git');
882 0 $doit->git_repo_update(
883 repository => $FindBin::RealBin,
884 directory => $dir,
885 # no: we need the full history for correct git version calculation: clone_opts => [qw(--depth=1)],
886 );
887 }
888 in_directory {
889 0 ▶ my $dockerfile = <<"EOF";
Subroutine __ANON__: not called CC=3 SCAR=24.8
890 FROM $distro_spec
891 EOF
892 0 my $add_opts = {};
893 0 $dockerfile .= _fix_Dockerfile_for_dist($distro_spec, $add_opts);
894 0 $dockerfile .= <<"EOF";
895  
896 ENV DEBIAN_FRONTEND noninteractive
897  
898 RUN apt-get$add_opts->{apt_get_update_opts} update && apt-get install -y --no-install-recommends \\
899 dh-make-perl \\
900 lsb-release \\
901 git
902  
903 # XXX This is depending on the current perl module and should be configurable
904 RUN apt-get install -y --no-install-recommends \\
905 libipc-run-perl \\
906 libnet-openssh-perl
907  
908 EOF
909 0 for my $env_key (qw(DEBFULLNAME DEBEMAIL EMAIL)) {
910 0 ▶ if ($ENV{$env_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$env_key}) 0 0 0
911 0 $dockerfile .= <<"EOF";
912 ENV $env_key "$ENV{$env_key}"
913 EOF
914 }
915 }
916 0 $doit->write_binary("Dockerfile", $dockerfile);
917  
918 0 (my $label = $distro_spec) =~ s{:}{-}g;
919 0 $label = "doit-deb-$label";
920 0 $doit->system(qw(docker build -t), $label, qw(.));
921 0 $doit->system(
922 qw(docker run), '-v', "$dir:/data", '-v', "$pkgdir:/pkg", $label,
923 'sh', '-c', 'git config --global --add safe.directory /data && cd /data && perl Build.PL && ./Build debian_package && cp *.deb /pkg'
924 );
925 0 } $dir;
926 0 info "Package is available in $pkgdir";
927 }
928  
929 sub release {
930 0 ▶ my $Doit_VERSION = _get_Doit_VERSION();
Subroutine release: not called CC=10 SCAR=47.0
931 0 for my $existing_tag (split /\n/, $doit->info_qx({quiet=>1}, 'git', 'tag')) {
932 0 ▶ if ($Doit_VERSION eq $existing_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Doit_VERSION eq $existing_tag) 0 0 0
933 0 error "The version $Doit_VERSION is already tagged --- probably the release was already done";
934 }
935 }
936  
937 FIND_VERSION: {
938 0 ▶ open my $cfh, '<', 'Changes'
Branch: 1 branch
BranchTrueFalseTotal
open my $cfh, "<", "Changes" or &error("Can't open Changes: $!") 0 0 0
939 or error "Can't open Changes: $!";
940 0 ▶ while(<$cfh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $cfh)) 0 0 0
941 0 ▶ if (/^\Q$Doit_VERSION\E\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\Q$Doit_VERSION\E\s/) 0 0 0
942 0 last FIND_VERSION;
943 }
944 }
945 0 error "Cannot find version $Doit_VERSION in Changes";
946 }
947  
948 0 $doit->system('git', 'fetch');
949  
950 0 $doit->add_component('git');
951 0 my $git_status = $doit->git_short_status;
952 0 ▶ if ($git_status ne '' && $git_status ne '<') {
Branch: 1 branch
BranchTrueFalseTotal
if ($git_status ne "" and $git_status ne "<") 0 0 0
Condition0%0/3
$git_status ne "" and $git_status ne "<"
!ll&&!rl&&r
000
MC/DC0%0/2
$git_status ne "" and $git_status ne "<"
$git_status ne "" $git_status ne "<"
Truth table0%0/3
A and B
A= $git_status ne ""B= $git_status ne "<"
ABresult
0X0
100
111
953 0 error "Please check the git status";
954 }
955  
956 # XXX TODO: check first if the current version already exists at CPAN
957 0 my $tarfile = _get_tarfilename();
958 0 ▶ if (!-e $tarfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $tarfile) { } 0 0 0
959 0 dist();
960 } else {
961 0 info "Use existing tarball $tarfile";
962 }
963  
964 0 print STDERR "Upload $tarfile? (y/n) ";
965 0 ▶ if (!y_or_n()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&y_or_n()) 0 0 0
966 0 error "exiting release process";
967 }
968  
969 0 $doit->system('cpan-upload', basename($tarfile));
970  
971 0 $doit->system('git', 'tag', '-a', '-m', "* $Doit_VERSION", $Doit_VERSION);
972 0 $doit->system('git', 'push', 'origin', 'master', $Doit_VERSION);
973 }
974  
975 sub _prove_path {
976 0 ▶ my @directory_candidates = ($Config{bin}, dirname(realpath $^X));
Subroutine _prove_path: not called CC=4 SCAR=30.0
977 0 my @basename_candidates = ('prove', "prove$Config{version}");
978 my @candidates = map {
979 0 my $basename = $_;
980 map {
981 0 "$_/$basename";
982 } @directory_candidates;
983 } @basename_candidates;
984 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
985 0 unshift @candidates, map { "$_.bat"} @candidates;
986 }
987 0 for my $candidate (@candidates) {
988 0 ▶ if (-x $candidate) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x $candidate) 0 0 0
989 0 return $candidate;
990 }
991 }
992 0 error "No 'prove' for the current perl found";
993 }
994  
995 sub _cover_path {
996 0 ▶ my @candidates = ("$Config{bin}/cover");
Subroutine _cover_path: not called CC=4 SCAR=30.0
997 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
998 0 unshift @candidates, map { "$_.bat"} @candidates;
999 }
1000 0 for my $candidate (@candidates) {
1001 0 ▶ if (-x $candidate) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x $candidate) 0 0 0
1002 0 return $candidate;
1003 }
1004 }
1005 0 error "No 'cover' for the current perl found";
1006 }
1007  
1008 sub _Build_PL_mode {
1009 0 ▶ require Data::Dumper;
Subroutine _Build_PL_mode: not called CC=2 SCAR=17.9
1010 0 my $argv_serialized = "\n" . '$Build_PL::ARGV = ' . Data::Dumper->new([\@ARGV], [])->Indent(1)->Useqq(1)->Sortkeys(1)->Terse(1)->Dump . ";\n\n";
1011 {
1012 0 ▶ if (-l "Build") { # formerly this used to be a symlink
Branch: 1 branch
BranchTrueFalseTotal
if (-l "Build") 0 0 0
1013 0 $doit->unlink("Build");
1014 }
1015 0 my $preamble = <<"EOF";
1016 #! $Config{perlpath}
1017 # MD5: $Build_PL_md5hex
1018 EOF
1019 0 $preamble .= $argv_serialized;
1020 0 $doit->write_binary({quiet=>1}, 'Build', $preamble . qq{# line 1 "Build.PL"\n} . $Build_PL_file_contents);
1021 0 $doit->chmod(0755, 'Build');
1022 }
1023 0 exit;
1024 }
1025  
1026 # Return a string for adding to Dockerfile after the FROM line. Also
1027 # the 2nd parameter (which has to be an empty hashref) is filled with
1028 # further instructions to amend the Dockerfile (currently only
1029 # apt_get_update_opts).
1030 sub _fix_Dockerfile_for_dist {
1031 0 ▶ my($distro_spec, $add_opts_ref) = @_;
Subroutine _fix_Dockerfile_for_dist: not called CC=2 SCAR=17.9
1032 0 ▶ if ($distro_spec =~ m{^debian:(wheezy|7)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distro_spec =~ /^debian:(wheezy|7)$/) { } 0 0 0
1033 # https://unix.stackexchange.com/questions/508724/failed-to-fetch-jessie-backports-repository
1034 0 $add_opts_ref->{apt_get_update_opts} = ' -o Acquire::Check-Valid-Until=false'; # with leading space
1035 0 <<EOF;
1036 RUN echo 'deb [check-valid-until=no] http://archive.debian.org/debian wheezy main' > /etc/apt/sources.list
1037 RUN echo 'deb [check-valid-until=no] http://archive.debian.org/debian-security/ wheezy/updates main' >> /etc/apt/sources.list
1038 EOF
1039 } else {
1040 0 $add_opts_ref->{apt_get_update_opts} = '';
1041 0 '';
1042 }
1043 }
1044  
1045 sub _add_Dockerfile_invalidate_cmd {
1046 0 ▶ my $dockerfile_ref = shift;
Subroutine _add_Dockerfile_invalidate_cmd: not called CC=1 SCAR=6.9
1047 0 require POSIX;
1048 0 $$dockerfile_ref .= <<"EOF";
1049 # Just a hack to make sure that the following lines
1050 # are executed at least once a day
1051 0 RUN echo @{[ POSIX::strftime("%F", localtime) ]}
1052 EOF
1053 }
1054  
1055 # REPO BEGIN
1056 # REPO NAME y_or_n /home/eserte/src/srezic-repository
1057 # REPO MD5 146cfcf8f954555fe0117a55b0ddc9b1
1058  
1059 #=head2 y_or_n
1060 #
1061 #Accept user input. Return true on 'y', return false on 'n', otherwise
1062 #ask again.
1063 #
1064 #A default may be supplied as an optional argument:
1065 #
1066 # y_or_n 'y';
1067 # y_or_n 'n';
1068 #
1069 #=cut
1070  
1071 sub y_or_n (;$) {
1072 0 ▶ my $default = shift;
Subroutine y_or_n: not called CC=5 SCAR=34.0
1073 0 while () {
1074 0 chomp(my $yn = <STDIN>);
1075 0 ▶ if ($yn eq '' && defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yn eq "" and defined $default) 0 0 0
Condition0%0/3
$yn eq "" and defined $default
!ll&&!rl&&r
000
MC/DC0%0/2
$yn eq "" and defined $default
$yn eq "" defined $default
Truth table0%0/3
A and B
A= $yn eq ""B= defined $default
ABresult
0X0
100
111
1076 0 $yn = $default;
1077 }
1078 0 ▶ if (lc $yn eq 'y') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $yn eq 'y') { } 0 0 0
elsif (lc $yn eq 'n') { } 0 0 0
1079 0 return 1;
1080 } elsif (lc $yn eq 'n') {
1081 0 return 0;
1082 } else {
1083 0 print STDERR "Please answer y or n: ";
1084 }
1085 }
1086 }
1087 # REPO END
1088  
1089 __END__
« blib/lib/Doit.pm ↑ Summary lib/Doit.pm »