scripts/buildaperl

filter: Statementstmt 24.5% 38 / 155 Branchbran 4.4% 4 / 90 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 17.3% 52 / 299 CC 3 SCAR 12.6
CC
3
Cov
15%
mysystem
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« scripts/patchaperlup ↑ Summary scripts/apc-overview »
1 #!/usr/bin/perl -w
2  
3  
4 3 ▶# line 4
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 use File::Path qw(mkpath rmtree);
11 3  
12 our %Opt;
13 3  
14 our $Id = q$Id: buildaperl 294 2008-02-22 10:42:30Z k $;
15 3  
16 my $DEFAULT_CONFIG = "-Dinstallusrbinperl=n -Uversiononly -Doptimize=-g ".
17 "-des -Duse64bitint -Dusedevel";
18 3 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%main::Opt, "apcdir=s", "branch=s", "config=s", "h!", "noconfigure!", "noinstall!", "notest!", "prefix=s", "remo!", "start=s", "target=s", "verbose!", "version!", "writedotpatch!") or die Usage() 3 0 3
19 GetOptions(
20 \%Opt,
21 "apcdir=s",
22 "branch=s",
23 "config=s",
24 "h!",
25 "noconfigure!",
26 "noinstall!",
27 "notest!",
28 "prefix=s",
29 "remo!",
30 "start=s",
31 "target=s",
32 "verbose!",
33 "version!",
34 "writedotpatch!",
35 ) or die Usage();
36 3 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"h"}) 2 1 3
37 2 if ($Opt{h}) {
38 2 print Usage();
39 exit;
40 }
41 1 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"version"}) 1 0 1
42 1 if ($Opt{version}) {
43 1 print $Id, "\n";
44 exit;
45 }
46 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
@ARGV == 1 or die Usage() 0 0 0
47 @ARGV == 1 or die Usage();
48 2 ▶ 
Subroutine Usage: called CC=1 SCAR=0.0
49 2 sub Usage {
50 qq{"Usage: $0 [options] version
51 [--config=...] # Configure options except --prefix; default:
52 $DEFAULT_CONFIG
53 [--apcdir=...] # where to find APC; defaults to "APC"
54 [--branch=...] # where to install: perl, maint-5.6, etc.
55 [--h] # this help message
56 [--noconfigure!] # Run without ./Configure
57 [--notest] # Run without make test
58 [--noinstall] # Run without ./installperl
59 [--prefix=...] # prefix of the inst directory; default ./installed-perls
60 [--remo] # remove source dir at the end
61 [--start] # start argument to patchaperlup
62 [--target=...] # e.g. miniperl
63 [--verbose] # noise
64 [--writedotpatch!] # write the .patch file for PERL_PATCHLEVEL
65  
66 Version may be '\@', '5.7.0\@', '5.7.0\@7100', '\@7100', etc.
67  
68 }; #
69 }
70 0  
71 our @SYSTEMTIMES;
72 sub mysystem ($);
73 0 ▶ 
Condition0%0/2
$main::Opt{"branch"} ||= "perl"
l!l
00
MC/DC0%0/1
$main::Opt{"branch"} ||= "perl"
$main::Opt{"branch"}
Truth table0%0/2
A
A= $main::Opt{"branch"}
Aresult
11
00
74 $Opt{branch} ||= "perl";
75 0 ▶ 
Condition0%0/2
$main::Opt{"apcdir"} ||= "APC"
l!l
00
MC/DC0%0/1
$main::Opt{"apcdir"} ||= "APC"
$main::Opt{"apcdir"}
Truth table0%0/2
A
A= $main::Opt{"apcdir"}
Aresult
11
00
76 $Opt{apcdir} ||= "APC";
77 3 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
78 0 use Cwd;
79 0 ▶my $pwd = cwd;
Condition0%0/2
$main::Opt{"prefix"} ||= "$pwd/installed-perls"
l!l
00
MC/DC0%0/1
$main::Opt{"prefix"} ||= "$pwd/installed-perls"
$main::Opt{"prefix"}
Truth table0%0/2
A
A= $main::Opt{"prefix"}
Aresult
11
00
80 $Opt{prefix} ||= "$pwd/installed-perls";
81 0 ▶ 
Condition0%0/3
$main::Opt{"config"} ||= $DEFAULT_CONFIG
l!l&&r!l&&!r
000
MC/DC0%0/2
$main::Opt{"config"} ||= $DEFAULT_CONFIG
$main::Opt{"config"} $DEFAULT_CONFIG
Truth table0%0/3
A ||= B
A= $main::Opt{"config"}B= $DEFAULT_CONFIG
ABresult
1X1
011
000
82 $Opt{config} ||= $DEFAULT_CONFIG;
83 0  
84 my($arg) = shift;
85 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg and $arg =~ /\@/) 0 0 0
Condition0%0/3
$arg and $arg =~ /\@/
!ll&&!rl&&r
000
MC/DC0%0/2
$arg and $arg =~ /\@/
$arg $arg =~ /\@/
Truth table0%0/3
A and B
A= $argB= $arg =~ /\@/
ABresult
0X0
100
111
86 0 unless ($arg && $arg =~ /\@/) {
87 die "$0: argument must contain an \@";
88 }
89 0  
90 0 ▶my($baseperl,$patchlevel) = $arg =~ /^([^\@]*)@(\d*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $baseperl 0 0 0
91 0 ▶die "baseperl not defined" unless defined $baseperl;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $patchlevel 0 0 0
92 0 ▶die "patchlevel not defined" unless defined $patchlevel;
Branch: 1 branch
BranchTrueFalseTotal
if length $patchlevel and !$patchlevel > 0 0 0 0
Condition0%0/3
length $patchlevel and !$patchlevel > 0
!ll&&!rl&&r
000
MC/DC0%0/2
length $patchlevel and !$patchlevel > 0
length $patchlevel !$patchlevel > 0
Truth table0%0/3
A and not(B)
A= length $patchlevelB= !$patchlevel > 0
ABresult
0X0
100
111
93 die "patchlevel not > 0" if length $patchlevel && ! $patchlevel > 0;
94 3 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
95 0 use Perl::Repository::APC;
96 my $apc = Perl::Repository::APC->new($Opt{apcdir});
97  
98 0 # determine simultaneously $baseperl and $patchlevel
99 3 ▶my $diffdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 0 use Perl::Repository::APC::BAP;
101 my $bap = Perl::Repository::APC::BAP->new($apc);
102 0 # This may die:
103 0 ($baseperl,my $nextperl,my $firstpatch,$patchlevel,my $dir)=$bap->translate($Opt{branch},$baseperl,$patchlevel);
104 warn "Info: Target $baseperl\@$patchlevel, firstpatch $firstpatch, nextperl $nextperl, ".
105 0 ▶ "branch $Opt{branch}\n";
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /-diffs$/) { } 0 0 0
106 0 if ($dir =~ /-diffs$/) {
107 $diffdir = "$Opt{apcdir}/$dir";
108 0 } else {
109 $diffdir = "$Opt{apcdir}/$dir/diffs";
110 0 }
111 0 my $upto_arg = " --upto='$patchlevel'";
112 0 my($branch_letter) = substr($Opt{branch},0,1);
113 0 ▶my $target_dir = "perl-$branch_letter-$baseperl\@$patchlevel";
Branch: 1 branch
BranchTrueFalseTotal
if -e $target_dir 0 0 0
114 die "Directory $target_dir exists but would be needed for building. Giving up "
115 if -e $target_dir;
116 0  
117 my($src,$bdir,$start_arg);
118 0  
119 0 ▶my $ptempdir = tempdir( "psrc-XXXX", DIR => ".", CLEANUP => 1);
Branch: 1 branch
BranchTrueFalseTotal
if ($baseperl eq '0') { } 0 0 0
120 0 if ($baseperl eq "0") {
121 0 $src = "";
122 0 ▶ $bdir = File::Spec->catdir($ptempdir,"emptydir");
Branch: 1 branch
BranchTrueFalseTotal
mkdir $bdir or die "Could not create ${bdir}: $!" 0 0 0
123 0 mkdir $bdir or die "Could not create $bdir: $!";
124 $start_arg = " --start='0'";
125 0 ▶} else {
Branch: 1 branch
BranchTrueFalseTotal
my $tarball = $apc->tarball($baseperl) or die "Could not determine tarball for $baseperl" 0 0 0
126 0 ▶ my $tarball = $apc->tarball($baseperl) or die "Could not determine tarball for $baseperl";
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($tarball) or -e $tarball) { } 0 0 0
Condition0%0/3
"File::Spec"->file_name_is_absolute($tarball) or -e $tarball
l!l&&r!l&&!r
000
MC/DC0%0/2
"File::Spec"->file_name_is_absolute($tarball) or -e $tarball
"File::Spec"->file_name_is_absolute($tarball) -e $tarball
Truth table0%0/3
A or B
A= "File::Spec"->file_name_is_absolute($tarball)B= -e $tarball
ABresult
1X1
011
000
127 if (File::Spec->file_name_is_absolute($tarball)
128 ||
129 -e $tarball
130 0 ) {
131 $src = $tarball;
132 } else {
133 0 # before Perl::Repository::APC 1.276 we only returned the basename
134 $src = "$Opt{apcdir}/$baseperl/$tarball";
135 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless -f $src 0 0 0
136 0 ▶ die "src[$src] not found" unless -f $src;
Branch: 1 branch
BranchTrueFalseTotal
open my $TAR, "tar -tzf $src |" or die 0 0 0
137 0 open my $TAR, "tar -tzf $src |" or die;
138 0 my $exbdir = <$TAR>;
139 0 chomp $exbdir;
140 0 $exbdir =~ s|^\./||;
141 0 $exbdir =~ s|/.*$||;
142 0 close $TAR;
143 $bdir = File::Spec->catdir($ptempdir,$exbdir);
144 0  
145 0 my $apcsrc = File::Spec->abs2rel($src);
146 0 ▶ my $cwd = Cwd::cwd();
Branch: 1 branch
BranchTrueFalseTotal
chdir $ptempdir or die "Could not chdir to '${ptempdir}': $!" 0 0 0
147 0 chdir $ptempdir or die "Could not chdir to '$ptempdir': $!";
148 0 my $relsrc = File::Spec->catdir($cwd,$apcsrc);
149 0 ▶ mysystem "tar -xzf $relsrc";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or die "Could not chdir to '${cwd}': $!" 0 0 0
150 chdir $cwd or die "Could not chdir to '$cwd': $!";
151 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
$main::Opt{'start'} ? : 0 0 0
152 $start_arg = $Opt{start} ? " --start='$Opt{start}'" : " --start='$firstpatch'";
153 }
154 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
$main::Opt{'verbose'} ? : 0 0 0
155 0 my $verbose_switch = $Opt{verbose} ? "--verbose " : "";
156 0 ▶my $branch_arg = " --branch='$Opt{branch}'";
Branch: 1 branch
BranchTrueFalseTotal
$main::Opt{'writedotpatch'} ? : 0 0 0
157 0 my $writedotpatch_switch = $Opt{writedotpatch} ? " --writedotpatch" : "";
158 0 $0 = "buildaperl:$branch_arg$upto_arg$start_arg";
159 mysystem "patchaperlup $verbose_switch$branch_arg$writedotpatch_switch".
160 " --perldir='$bdir' --diffdir='$diffdir'$upto_arg$start_arg";
161  
162 # concurrency disallowed intentionally: it makes no sense that two
163 # processes build the exact same perl (yes, there may be exceptions
164 0 ▶# and then we will have to revisit this)
Branch: 1 branch
BranchTrueFalseTotal
rename $bdir, $target_dir or die "Could not rename to $target_dir" 0 0 0
165 0 ▶rename $bdir, $target_dir or die "Could not rename to $target_dir";
Branch: 1 branch
BranchTrueFalseTotal
rmdir $ptempdir or die "Could not remove temporary directory '${ptempdir}': $!" 0 0 0
166 0 rmdir $ptempdir or die "Could not remove temporary directory '$ptempdir': $!";
167 0 ▶system "chmod -R u+w $target_dir";
Branch: 1 branch
BranchTrueFalseTotal
chdir $target_dir or die "Could not chdir to $target_dir" 0 0 0
168 0 ▶chdir $target_dir or die "Could not chdir to $target_dir";
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"branch"} eq "perl" and -e "patchlevel.h" and $patchlevel >= 18749) 0 0 0
Condition0%0/6
$main::Opt{"branch"} eq "perl" and -e "patchlevel.h" and $patchlevel >= 18749
!ll&&!rl&&r
000
$main::Opt{"branch"} eq "perl" and -e "patchlevel.h"
!ll&&!rl&&r
000
MC/DC0%0/3
$main::Opt{"branch"} eq "perl" and -e "patchlevel.h" and $patchlevel >= 18749
$main::Opt{"branch"} eq "perl" -e "patchlevel.h" $patchlevel >= 18749
Truth table0%0/4
A and B and C
A= $main::Opt{"branch"} eq "perl"B= -e "patchlevel.h"C= $patchlevel >= 18749
ABCresult
0XX0
10X0
1100
1111
169 if ($Opt{branch} eq "perl" &&
170 -e "patchlevel.h" &&
171 $patchlevel >= 18749
172 0 ▶ ) {
Branch: 1 branch
BranchTrueFalseTotal
0 == system($^X, "-x", "patchlevel.h", "patchaperlup:$branch_arg$upto_arg$start_arg") or die 0 0 0
173 0==system($^X,
174 "-x",
175 "patchlevel.h",
176 "patchaperlup:$branch_arg$upto_arg$start_arg",
177 ) or die;
178 }
179 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::Opt{"noconfigure"}) 0 0 0
180 unless ($Opt{noconfigure}) {
181 0 ▶ my $absprefix = File::Spec->file_name_is_absolute($Opt{prefix}) ?
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($main::Opt{'prefix'}) ? : 0 0 0
182 0 $Opt{prefix} : File::Spec->catfile($pwd,$Opt{prefix});
183 0 mkpath "$absprefix/$Opt{branch}";
184 0 ▶ my $tempdir = tempdir( "pXXXXXX", DIR => "$absprefix/$Opt{branch}");
Branch: 1 branch
BranchTrueFalseTotal
chmod 0755, $tempdir or die "Could not chmod to mode 0755 on directory '${tempdir}': $!" 0 0 0
185 chmod 0755, $tempdir or die "Could not chmod to mode 0755 on directory '$tempdir': $!";
186  
187 0 ▶ # too many versions come without a wince/perl.ico:
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "MANIFEST") 0 0 0
188 0 if (open my $fh, "MANIFEST") {
189 0 ▶ my @manifest = <$fh>;
Branch: 1 branch
BranchTrueFalseTotal
if (grep {m[^wince/perl\.ico\s];} @manifest and not -f "wince/perl.ico") 0 0 0
Condition0%0/3
grep {m[^wince/perl\.ico\s];} @manifest and not -f "wince/perl.ico"
!ll&&!rl&&r
000
MC/DC0%0/2
grep {m[^wince/perl\.ico\s];} @manifest and not -f "wince/perl.ico"
grep {m[^wince/perl\.ico\s];} @manifest not -f "wince/perl.ico"
Truth table0%0/3
A and not(B)
A= grep {m[^wince/perl\.ico\s];} @manifestB= not -f "wince/perl.ico"
ABresult
0X0
100
111
190 if (grep { /^wince\/perl\.ico\s/ } @manifest
191 0 and not -f "wince/perl.ico") {
192 0 ▶ close $fh;
Branch: 1 branch
BranchTrueFalseTotal
chmod 0644, "MANIFEST" or die "Could not chmod 0644 MANIFEST: $!" 0 0 0
193 0 ▶ chmod 0644, "MANIFEST" or die "Could not chmod 0644 MANIFEST: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", "MANIFEST" or die "Could not open >MANIFEST: $!" 0 0 0
194 0 open $fh, ">", "MANIFEST" or die "Could not open >MANIFEST: $!";
195 0 print $fh grep { ! /^wince\/perl\.ico\s/ } @manifest;
196 close $fh;
197 }
198 }
199  
200 0 # here we do not need $target_dir, because branch is visible in directory
201 0 mysystem "sh Configure -Dprefix=$tempdir/perl-$baseperl\@$patchlevel $Opt{config}";
202 0 ▶ my $target = "";
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"target"}) 0 0 0
203 0 if ($Opt{target}) {
204 $target = " $Opt{target}";
205 0 }
206 0 ▶ my $makeout = "";
Branch: 1 branch
BranchTrueFalseTotal
open my $make, "make$target 2>&1 |" or die 0 0 0
207 0 ▶ open my($make), "make$target 2>&1 |" or die;
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $make)) 0 0 0
208 0 while (<$make>) {
209 0 print;
210 $makeout .= $_;
211 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless (close $make) 0 0 0
212 0 unless (close $make) {
213 my $ret = $?;
214 0 ▶ # if ($makeout =~ /No rule to make target.*built-in/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($makeout =~ /(?:no rule to make target|don't know how to make).*built-in/i) { } 0 0 0
215 0 if ($makeout =~ /(?:no rule to make target|don't know how to make).*built-in/i) {
216 print "\aWARNING: Running 'make' failed. It produced the infamous
217 <built-in> error that old perls have with new gccs. I'll work around this
218 in the makefiles now and retry. If you do not like that, hit ^C and FIXME.
219 0 Sleeping 5 seconds...\n";
220 sleep 5;
221 0 {
222 0 local @ARGV = qw( makefile x2p/makefile);
223 0 ▶ local $^I = "~";
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 0 0 0
224 0 ▶ while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
unless /<(built-in|command line)>/ 0 0 0
225 print unless /<(built-in|command line)>/;
226 }
227 0 }
228 mysystem "make$target";
229 0 } else {
230 die "make failed with ret[$ret]";
231 }
232 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Opt{"notest"} 0 0 0
233 0 ▶ mysystem "make test" unless $Opt{notest};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Opt{"noinstall"} 0 0 0
234 mysystem "LD_LIBRARY_PATH=. ./perl installperl" unless $Opt{noinstall};
235 }
236 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"remo"}) 0 0 0
237 0 if ($Opt{remo}){
238 0 chdir $pwd;
239 0 my $rmtree = $target_dir;
240 0 warn "Removing $rmtree\n";
241 rmtree $rmtree;
242 }
243 0 ▶ 
Subroutine mysystem: not called CC=3 SCAR=24.8
244 0 sub mysystem ($) {
245 0 my $system = shift;
246 0 warn "Running $system\n";
247 0 my $start = time;
248 0 $ENV{LANG} = "C"; # we rely on system messages!
249 0 ▶ my $ret = system($system);
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret == 0) 0 0 0
250 0 unless ($ret==0) {
251 0 my $cwd = cwd;
252 Carp::confess("system[$system] failed with ret[$ret] in cwd[$cwd]");
253 0 }
254 0 ▶ push @SYSTEMTIMES, $system, time-$start;
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @main::SYSTEMTIMES) 0 0 0
255 0 for (my $i = 0; $i < @SYSTEMTIMES; $i+=2){
256 printf "%3d secs for[%s]\n", @SYSTEMTIMES[$i+1, $i];
257 }
258 }
259  
260 __END__
« scripts/patchaperlup ↑ Summary scripts/apc-overview »