blib/lib/auto/share/dist/Shipwright/bin/shipwright-builder

filter: Statementstmt 12.6% 64 / 508 Branchbran 1.8% 5 / 272 Conditioncond 0.0% 0 / 109 MC/DCmcdc 0.0% 0 / 61 Subroutinesub 44.7% 17 / 38 Podpod n/a totaltotal 8.7% 86 / 988 CC 136 SCAR 62.2
CC
136
Cov
8%
install
1318.7
_install
992.0
__ANON__
240.0
CRAP 504.7
« blib/lib/Shipwright/Script/List.pm ↑ Summary blib/lib/Shipwright/Backend/Base.pm »
1 #!/usr/bin/env perl
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use lib 'inc';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec::Functions qw/catfile catdir splitdir rel2abs path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Copy::Recursive qw/rmove rcopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Find qw/find/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Cwd qw/getcwd/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Shipwright::Util::CleanINC;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 my $build_base = getcwd;
20 2 my $inc_lib = join '/', splitdir($build_base), 'inc';
21  
22 2 ▶@ARGV = get_default_builder_options() unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 2 2
23  
24 2 my %args;
25  
26 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶confess "unknown option"
Branch: 1 branch
BranchTrueFalseTotal
unless &GetOptions(\%args, "install-base=s", "perl=s", "skip=s", "flags=s", "skip-test", "skip-test-except-final", "only-test", "skip-man-pages", "force", "clean", "name=s", "help", "advanced-help", "noclean", "only=s", "with=s", "noclean-after-install", "make=s", "branches=s", "verbose", "as=s", "no-install-base") 0 2 2
28 unless GetOptions(
29 \%args, 'install-base=s',
30 'perl=s', 'skip=s',
31 'flags=s', 'skip-test',
32 'skip-test-except-final', 'only-test',
33 'skip-man-pages', 'force',
34 'clean', 'name=s',
35 'help', 'advanced-help',
36 'noclean', 'only=s',
37 'with=s', 'noclean-after-install',
38 'make=s', 'branches=s',
39 'verbose', 'as=s',
40 'no-install-base',
41 );
42  
43 2 my $USAGE = <<'END';
44 run: ./bin/shipwright-builder
45  
46 Commonly used options:
47
48 --install-base Where this vessel should be built. Defaults to
49 a directory inside your system's default 'temp'
50 directory. (Note that vessels are relocatable
51 once built)
52 Ex: --install-base /home/local/mydist
53 --no-install-base install to the default directory for each dist
54 --skip-test Don't run any tests at all
55 --skip-test-except-final Only run tests for the final package built
56 --skip-man-pages Don't install man pages for perl modules
57 --force Install this vessel, even if some tests fail
58 --advanced-help Show additional command-line options you're
59 less likely to use.
60 --verbose more output to stdout.
61  
62  
63  
64 END
65  
66 2 my $ADVANCED_USAGE = <<END;
67  
68 Less commonly needed options:
69 --help Print this usage
70 --skip Dists we don't want to install, comma-separated
71 Ex: --skip perl,Module-Build
72 --perl Which perl to use for the to be installed vessel
73 If this vessel includes a perl build, shipwright will
74 use that by default. Otherwise, it will default to the
75 perl used to run this script.
76 Ex: --perl /usr/bin/perl
77 --only Skip all dists except those in this comma-separated list
78 Ex: --only perl,Module-Build
79 --name The name of the project. used to create a better named dir if
80 install_base is not supplied
81 Ex: --name mydist
82 --flags Set shipwright build flags we need, comma-separated
83 Ex: --flags mysql,standalone
84  
85 --only-test Test for the installed dists
86 We use this to be sure everything is ok after successful
87 installation. This option requires that you specify
88 --install-base if no __install_base from a previous
89 Shipwright run is available.
90 --clean Remove vestiges of a previous build from a vessel
91 --noclean Don't automatically run a "clean" pass before building
92 --with Skip a distribution from the vessel, using one specified on
93 the commandline instead.
94 Ex: --with svn=dir:/home/foo/svn
95 'svn' is the dist name, 'dir:/home/foo/svn' is its source code,
96 in the format of a Shipwright source distribution.
97 --make The path of your make command, default is \$ENV{SHIPWRIGHT_MAKE}
98 Ex: --make /usr/bin/make
99 --branches Specify the branch of a given package in the vessel you want
100 to build.
101 Ex: --branches Foo=trunk,Bar=2.0
102 --as for multi-arch dists, you can use this to specify the arch name.
103 By default it's the uname.
104 END
105  
106 2 ▶if ( $args{'help'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"help"}) 1 1 2
107 1 print $USAGE;
108 1 exit 0;
109 }
110  
111 1 ▶if ( $args{'advanced-help'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"advanced-help"}) 1 0 1
112 1 print $ADVANCED_USAGE;
113 1 exit 0;
114 }
115  
116 0 ▶unless ( -d 'shipwright' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "shipwright") 0 0 0
117 0 print
118 "$0 expects to be run in a directory with a 'shipwright' subdirectory\n";
119 0 exit -1;
120 }
121  
122 0 ▶my $bin_quote = is_on_windows() ? q{"} : q{'};
Branch: 1 branch
BranchTrueFalseTotal
is_on_windows() ? : 0 0 0
123 0 my $bin_ext = $Config{_exe};
124  
125 0 ▶$args{skip} = { map { $_ => 1 } split /\s*,\s*/, $args{skip} || '' };
Condition0%0/2
$args{'skip'} || ''
l!l
00
MC/DC0%0/1
$args{'skip'} || ''
$args{'skip'}
Truth table0%0/2
A
A= $args{'skip'}
Aresult
11
00
126 $args{flags} = {
127 default => 1,
128 0 ▶ map { $_ => 1 } split /\s*,\s*/, $args{flags} || ''
Condition0%0/2
$args{'flags'} || ''
l!l
00
MC/DC0%0/1
$args{'flags'} || ''
$args{'flags'}
Truth table0%0/2
A
A= $args{'flags'}
Aresult
11
00
129 };
130  
131 0 ▶$args{with} = { map { split /=/ } split /\s*,\s*/, $args{with} || '' };
Condition0%0/2
$args{'with'} || ''
l!l
00
MC/DC0%0/1
$args{'with'} || ''
$args{'with'}
Truth table0%0/2
A
A= $args{'with'}
Aresult
11
00
132 0 ▶$args{branches} = { map { split /=/ } split /\s*,\s*/, $args{branches} || '' };
Condition0%0/2
$args{'branches'} || ''
l!l
00
MC/DC0%0/1
$args{'branches'} || ''
$args{'branches'}
Truth table0%0/2
A
A= $args{'branches'}
Aresult
11
00
133  
134 $args{make} ||=
135 $ENV{SHIPWRIGHT_MAKE}
136 0 ▶ || which('make')
Condition0%0/14
$args{"make"} ||= $ENV{"SHIPWRIGHT_MAKE"} || which("make") || which("dmake") || which("nmake") || "make"
l!l&&r!l&&!r
000
$ENV{'SHIPWRIGHT_MAKE'} || which('make') || which('dmake') || which('nmake') || 'make'
l!l
00
$ENV{"SHIPWRIGHT_MAKE"} or which("make") or which("dmake") or which("nmake")
l!l&&r!l&&!r
000
$ENV{"SHIPWRIGHT_MAKE"} or which("make") or which("dmake")
l!l&&r!l&&!r
000
$ENV{"SHIPWRIGHT_MAKE"} or which("make")
l!l&&r!l&&!r
000
MC/DC0%0/5
$args{"make"} ||= $ENV{"SHIPWRIGHT_MAKE"} || which("make") || which("dmake") || which("nmake") || "make"
$args{"make"} $ENV{"SHIPWRIGHT_MAKE"} which("make") which("dmake") which("nmake")
Truth table0%0/6
A ||= B or C or D or E
A= $args{"make"}B= $ENV{"SHIPWRIGHT_MAKE"}C= which("make")D= which("dmake")E= which("nmake")
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
137 || which('dmake')
138 || which('nmake')
139 || 'make';
140 $args{make} = $bin_quote . $args{make} . $bin_quote
141 if $args{make} =~ /\s/
142 0 ▶ && $args{make} !~ /^$bin_quote/;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"make"} =~ /\s/ and not $args{"make"} =~ /^$bin_quote/ 0 0 0
Condition0%0/3
$args{"make"} =~ /\s/ and not $args{"make"} =~ /^$bin_quote/
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"make"} =~ /\s/ and not $args{"make"} =~ /^$bin_quote/
$args{"make"} =~ /\s/ not $args{"make"} =~ /^$bin_quote/
Truth table0%0/3
A and not(B)
A= $args{"make"} =~ /\s/B= not $args{"make"} =~ /^$bin_quote/
ABresult
0X0
100
111
143  
144 0 ▶if ( is_on_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_on_windows()) { } 0 0 0
145 0 ▶ $args{as} ||= 'MSWin';
Condition0%0/2
$args{"as"} ||= "MSWin"
l!l
00
MC/DC0%0/1
$args{"as"} ||= "MSWin"
$args{"as"}
Truth table0%0/2
A
A= $args{"as"}
Aresult
11
00
146 }
147 else {
148 0 my $uname = `uname 2>/dev/null`;
149 0 chomp $uname;
150 0 ▶ $args{as} ||= $uname || 'default';
Condition0%0/5
$args{"as"} ||= $uname || "default"
l!l&&r!l&&!r
000
$uname || 'default'
l!l
00
MC/DC0%0/2
$args{"as"} ||= $uname || "default"
$args{"as"} $uname
Truth table0%0/3
A ||= B
A= $args{"as"}B= $uname
ABresult
1X1
011
000
151 }
152  
153 0 ▶if ( $args{only} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"only"}) 0 0 0
154 0 $args{only} = { map { $_ => 1 } split /\s*,\s*/, $args{only} };
155 }
156  
157 0 ▶unless ( $args{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"name"}) 0 0 0
158 0 ▶ if ( $build_base =~ m{([-.\w]+)[\\/]([.\d]+)$} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($build_base =~ m[([-.\w]+)[\\/]([.\d]+)$]) { } 0 0 0
elsif ($build_base =~ /([-.\w]+)$/) { } 0 0 0
159 0 $args{name} = "$1-$2";
160 }
161 elsif ( $build_base =~ m{([-.\w]+)$} ) {
162 0 $args{name} = $1;
163 }
164 }
165  
166 0 ▶unless ( $args{'no-install-base'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"no-install-base"}) 0 0 0
167 0 ▶ $args{'install-base'} = get_install_base() unless $args{'install-base'};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"install-base"} 0 0 0
168  
169 0 ▶ unless ( $args{'install-base'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"install-base"}) 0 0 0
170 0 my $dir = tempdir( 'vessel_' . $args{name} . '-XXXXXX', TMPDIR => 1 );
171 0 $args{'install-base'} = catdir( $dir, $args{name} );
172 0 print "no default install-base, will set it to $args{'install-base'}\n";
173 }
174  
175 # replace prefix ~ with real home dir
176 0 $args{'install-base'} =~ s/^~/(getpwuid $<)[7]/e;
177  
178 # remove last / or \
179 0 $args{'install-base'} =~ s{[/\\]$}{};
180 }
181  
182 0 my ( $installed, $installed_file );
183 0 my $installed_hash = {};
184 0 ▶unless ( $args{'no-install-base'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"no-install-base"}) 0 0 0
185 $installed_file =
186 0 catfile( $args{'install-base'}, "$args{as}_installed.yml" );
187 0 ▶ if ( -e $installed_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $installed_file) { } 0 0 0
188 $installed = YAML::Tiny->read(
189 0 catfile( $args{'install-base'}, "$args{as}_installed.yml" ) );
190 0 ▶ if ( ref $installed->[0] eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $installed->[0] eq 'ARRAY') { } 0 0 0
elsif (ref $installed->[0] eq 'HASH') { } 0 0 0
191 0 $installed_hash = { map { $_ => 0 } @{ $installed->[0] } };
192 }
193 elsif ( ref $installed->[0] eq 'HASH' ) {
194 0 $installed_hash = $installed->[0];
195 }
196 else {
197 0 warn "invalid $args{as}_installed.yml";
198 }
199 }
200 else {
201 0 $installed = YAML::Tiny->new;
202 }
203 0 $args{'install-base'} = rel2abs( $args{'install-base'} );
204 }
205  
206 # YAML::Tiny objects are array based.
207 0 my $order = ( YAML::Tiny->read( catfile( 'shipwright', 'order.yml' ) ) )->[0];
208 0 my $version = ( YAML::Tiny->read( catfile( 'shipwright', 'version.yml' ) ) )->[0];
209  
210 0 my ( $flags, $ktf, $branches );
211  
212 0 ▶if ( -e catfile( 'shipwright', 'flags.yml' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile("shipwright", "flags.yml")) 0 0 0
213 0 $flags = ( YAML::Tiny->read( catfile( 'shipwright', 'flags.yml' ) ) )->[0];
214 }
215  
216 0 ▶$flags ||= {};
Condition0%0/2
$flags ||= {}
l!l
00
MC/DC0%0/1
$flags ||= {}
$flags
Truth table0%0/2
A
A= $flags
Aresult
11
00
217  
218 0 ▶if ( -e catfile( 'shipwright', 'known_test_failures.yml' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile("shipwright", "known_test_failures.yml")) 0 0 0
219 0 $ktf =
220 ( YAML::Tiny->read( catfile( 'shipwright', 'known_test_failures.yml' ) ) )
221 ->[0];
222 }
223  
224 0 ▶$ktf ||= {};
Condition0%0/2
$ktf ||= {}
l!l
00
MC/DC0%0/1
$ktf ||= {}
$ktf
Truth table0%0/2
A
A= $ktf
Aresult
11
00
225  
226 0 ▶if ( -e catfile( 'shipwright', 'branches.yml' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile("shipwright", "branches.yml")) 0 0 0
227 0 ▶ $branches =
Condition0%0/2
'YAML::Tiny'->read(catfile('shipwright', 'branches.yml'))->[0] || {}
l!l
00
MC/DC0%0/1
'YAML::Tiny'->read(catfile('shipwright', 'branches.yml'))->[0] || {}
'YAML::Tiny'->read(catfile('shipwright', 'branches.yml'))->[0]
Truth table0%0/2
A
A= 'YAML::Tiny'->read(catfile('shipwright', 'branches.yml'))->[0]
Aresult
11
00
228 ( YAML::Tiny->read( catfile( 'shipwright', 'branches.yml' ) ) )->[0]
229 || {};
230 0 for my $name ( keys %{ $args{branches} } ) {
231 die 'no branch name ' . $args{branches}->{$name} . " for $name"
232 0 unless grep { $_ eq $args{branches}->{$name} }
233 0 ▶ @{ $branches->{$name} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $args{"branches"}{$name};} @{$branches->{$name} or [];} 0 0 0
Condition0%0/2
$branches->{$name} || []
l!l
00
MC/DC0%0/1
$branches->{$name} || []
$branches->{$name}
Truth table0%0/2
A
A= $branches->{$name}
Aresult
11
00
234 }
235 }
236  
237 # fill not specified but mandatory flags
238 0 ▶if ( $flags->{__mandatory} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{"__mandatory"}) 0 0 0
239 0 for my $list ( values %{ $flags->{__mandatory} } ) {
240 0 ▶ next unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 0 0 0
241 0 ▶ next if grep { $args{flags}{$_} } @$list;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$args{"flags"}{$_};} @$list 0 0 0
242 0 $args{flags}{ $list->[0] }++;
243 }
244 }
245  
246 # calculate the real order
247 0 ▶if ( $args{only} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'only'}) { } 0 0 0
248 0 @$order = grep { $args{only}->{$_} } @$order;
249 }
250 else {
251 @$order =
252 grep {
253 0 ( $flags->{$_} ? ( grep { $args{flags}{$_} } @{ $flags->{$_} } ) : 1 )
254 0 ▶ && !$args{skip}->{$_}
Branch: 1 branch
BranchTrueFalseTotal
$flags->{$_} ? : 0 0 0
Condition0%0/3
($flags->{$_} ? grep({$args{'flags'}{$_};} @{$$flags{$_};}) : 1) && !$args{'skip'}{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
($flags->{$_} ? grep({$args{'flags'}{$_};} @{$$flags{$_};}) : 1) && !$args{'skip'}{$_}
($flags->{$_} ? grep({$args{'flags'}{$_};} @{$$flags{$_};}) : 1) !$args{'skip'}{$_}
Truth table0%0/3
A && not(B)
A= ($flags->{$_} ? grep({$args{'flags'}{$_};} @{$$flags{$_};}) : 1)B= !$args{'skip'}{$_}
ABresult
0X0
100
111
255 } @$order;
256 }
257  
258 # remove the already installed ones
259 0 my @tmporder = @$order;
260 0 $order = [];
261 0 for my $item ( @tmporder ) {
262 0 ▶ if ( exists $installed_hash->{$item} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $installed_hash->{$item}) { } 0 0 0
263 0 ▶ my $installed_version = $installed_hash->{$item} || 0;
Condition0%0/2
$installed_hash->{$item} || 0
l!l
00
MC/DC0%0/1
$installed_hash->{$item} || 0
$installed_hash->{$item}
Truth table0%0/2
A
A= $installed_hash->{$item}
Aresult
11
00
264 my $branch =
265 defined $args{branches}{$item}
266 ? $args{branches}{$item}
267 0 ▶ : $branches->{$item}[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'branches'}{$item} ? : 0 0 0
268 0 my $current_version = $version->{$item}{$branch};
269 0 ▶ if ( defined $current_version
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_version and $installed_version ne $current_version) 0 0 0
Condition0%0/3
defined $current_version and $installed_version ne $current_version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current_version and $installed_version ne $current_version
defined $current_version $installed_version ne $current_version
Truth table0%0/3
A and B
A= defined $current_versionB= $installed_version ne $current_version
ABresult
0X0
100
111
270 && $installed_version ne $current_version )
271 {
272 0 push @$order, $item;
273 }
274 }
275 else {
276 0 push @$order, $item;
277 }
278 }
279  
280 0 my $log;
281 0 my $build_log_file = rel2abs('build.log');
282 0 my $system_cmd_pipe = '';
283 0 ▶unless ( is_on_windows() || $args{'verbose'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_on_windows() or $args{"verbose"}) 0 0 0
Condition0%0/3
is_on_windows() or $args{"verbose"}
l!l&&r!l&&!r
000
MC/DC0%0/2
is_on_windows() or $args{"verbose"}
is_on_windows() $args{"verbose"}
Truth table0%0/3
A or B
A= is_on_windows()B= $args{"verbose"}
ABresult
1X1
011
000
284 0 $system_cmd_pipe = " >>$build_log_file 2>&1";
285 }
286  
287 0 ▶if ( $args{'only-test'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'only-test'}) { } 0 0 0
elsif ($args{'clean'}) { } 0 0 0
288 0 ▶ open $log, '>', 'test.log' or confess $!;
Branch: 1 branch
BranchTrueFalseTotal
open $log, ">", "test.log" or confess($!) 0 0 0
289  
290 0 test();
291 }
292 elsif ( $args{'clean'} ) {
293 0 clean();
294 }
295 else {
296 0 ▶ if ( -e '__need_clean' && !$args{noclean} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "__need_clean" and not $args{"noclean"}) 0 0 0
Condition0%0/3
-e "__need_clean" and not $args{"noclean"}
!ll&&!rl&&r
000
MC/DC0%0/2
-e "__need_clean" and not $args{"noclean"}
-e "__need_clean" not $args{"noclean"}
Truth table0%0/3
A and not(B)
A= -e "__need_clean"B= not $args{"noclean"}
ABresult
0X0
100
111
297 0 print "seems it has been built before, need to clean first\n";
298 0 clean();
299 }
300 0 ▶ if (@$order) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$order) { } 0 0 0
301 0 install();
302 }
303 else {
304 0 print "all dists are installed already\n";
305 }
306 }
307  
308 0 ▶sub install {
Subroutine install: not called CC=38 SCAR=71.8
309  
310 # for install
311 0 ▶ open $log, '>', $build_log_file or confess $!;
Branch: 1 branch
BranchTrueFalseTotal
open $log, ">", $build_log_file or confess($!) 0 0 0
312  
313 # set clean flag again
314 0 ▶ if ( $args{'noclean-after-install'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"noclean-after-install"}) 0 0 0
315 0 ▶ open my $tmp_fh, '>', '__need_clean' or confess $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $tmp_fh, ">", "__need_clean" or confess($!) 0 0 0
316 0 close $tmp_fh;
317 }
318  
319 0 ▶ process_tmp_dists() if keys %{ $args{with} };
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$args{"with"};} 0 0 0
320  
321 # some perl distribution( e.g. on fedora ) doesn't have CPAN module
322 # so we put it in eval block
323 0 eval {
324 0 require CPAN;
325  
326 # don't bother people no CPAN::Config since it's not a problem
327 0 require CPAN::Config;
328  
329 # we don't want any prereqs any more!
330 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
331 0 $CPAN::Config->{prerequisites_policy} = 'ignore';
332 };
333  
334 # this dirty hack means that ExtUtils::AutoInstall won't try to recurse and run cpan
335 0 $ENV{'PERL5_CPANPLUS_IS_RUNNING'} = 1;
336 0 $ENV{'AUTOMATED_TESTING'} = 1; # Term::ReadLine::Perl and others
337 # use this to not prompt
338 0 $ENV{PERL_MM_USE_DEFAULT} = 1;
339 0 $ENV{PERL_MM_OPT} = '';
340 0 $ENV{MODULEBUILDRC} = '';
341  
342 0 ▶ mkdir 'dists' unless -e 'dists';
Branch: 1 branch
BranchTrueFalseTotal
unless -e "dists" 0 0 0
343  
344 0 ▶ unless ( $args{perl} && -e $args{perl} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"perl"} and -e $args{"perl"}) 0 0 0
Condition0%0/3
$args{"perl"} and -e $args{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"perl"} and -e $args{"perl"}
$args{"perl"} -e $args{"perl"}
Truth table0%0/3
A and B
A= $args{"perl"}B= -e $args{"perl"}
ABresult
0X0
100
111
345 0 my $perl = catfile( $args{'install-base'}, 'bin', 'perl' );
346 0 ▶ $args{perl} = -e $perl ? $perl : $^X;
Branch: 1 branch
BranchTrueFalseTotal
-e $perl ? : 0 0 0
347 }
348  
349 $args{perl} = $bin_quote . $args{perl} . $bin_quote
350 if $args{perl} =~ /\s/
351 0 ▶ && $args{perl} !~ /^$bin_quote/;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"perl"} =~ /\s/ and not $args{"perl"} =~ /^$bin_quote/ 0 0 0
Condition0%0/3
$args{"perl"} =~ /\s/ and not $args{"perl"} =~ /^$bin_quote/
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"perl"} =~ /\s/ and not $args{"perl"} =~ /^$bin_quote/
$args{"perl"} =~ /\s/ not $args{"perl"} =~ /^$bin_quote/
Truth table0%0/3
A and not(B)
A= $args{"perl"} =~ /\s/B= not $args{"perl"} =~ /^$bin_quote/
ABresult
0X0
100
111
352  
353 0 ▶ if ( $args{'no-install-base'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'no-install-base'}) { } 0 0 0
354 0 for my $dist (@$order) {
355 0 _install( $dist, $log );
356 0 ▶ if ( $dist =~ /^perl/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist =~ /^perl/) 0 0 0
357 0 my $perl = catfile( $args{'install-base'}, 'bin', 'perl' );
358 0 ▶ $args{perl} = -e $perl ? $perl : $^X;
Branch: 1 branch
BranchTrueFalseTotal
-e $perl ? : 0 0 0
359 }
360  
361 0 chdir $build_base;
362 }
363 0 print "install finished\n";
364 }
365 else {
366 0 ▶ open my $fh, '>', '__install_base'
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "__install_base" or confess("can't write to __install_base: $!") 0 0 0
367 or confess "can't write to __install_base: $!";
368 0 print $fh $args{'install-base'};
369 0 close $fh;
370  
371 {
372  
373 0 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
374 $ENV{DYLD_LIBRARY_PATH} =
375 catdir( $args{'install-base'}, 'lib' ) . ':'
376 0 . $ENV{DYLD_LIBRARY_PATH};
377 $ENV{LD_LIBRARY_PATH} =
378 catdir( $args{'install-base'}, 'lib' ) . ':'
379 0 . $ENV{LD_LIBRARY_PATH};
380 0 _set_perl5lib();
381  
382 $ENV{PATH} =
383 catdir( $args{'install-base'}, 'sbin' ) . ':'
384 . catdir( $args{'install-base'}, 'bin' ) . ':'
385 . catdir( $args{'install-base'}, 'usr', 'sbin' ) . ':'
386 . catdir( $args{'install-base'}, 'usr', 'bin' ) . ':'
387 0 . $ENV{PATH};
388 0 $ENV{LDFLAGS} .= ' -L' . catdir( $args{'install-base'}, 'lib' );
389 0 $ENV{CFLAGS} .= ' -I' . catdir( $args{'install-base'}, 'include' );
390 }
391  
392 0 ▶ mkpath $args{'install-base'} unless -e $args{'install-base'};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $args{"install-base"} 0 0 0
393  
394 mkdir catdir( $args{'install-base'}, 'etc' )
395 0 ▶ unless -e catdir( $args{'install-base'}, 'etc' );
Branch: 1 branch
BranchTrueFalseTotal
unless -e catdir($args{"install-base"}, "etc") 0 0 0
396 mkdir catdir( $args{'install-base'}, 'tools' )
397 0 ▶ unless -e catdir( $args{'install-base'}, 'tools' );
Branch: 1 branch
BranchTrueFalseTotal
unless -e catdir($args{"install-base"}, "tools") 0 0 0
398  
399 0 for ( 'shipwright-script-wrapper', 'shipwright-perl-wrapper' ) {
400 rcopy( catfile( 'etc', $_ ),
401 0 catfile( $args{'install-base'}, 'etc', $_ ) );
402 }
403  
404 0 for ( 'shipwright-utility', 'shipwright-source-bash',
405 'shipwright-source-tcsh' )
406 {
407 rcopy( catfile( 'etc', $_ ),
408 0 catfile( $args{'install-base'}, 'tools', $_ ) );
409 }
410  
411 chmod oct 755,
412 0 catfile( $args{'install-base'}, 'tools', 'shipwright-utility' );
413  
414 # remove lib it's symbolic link
415 0 for my $r ('lib') {
416 0 my $dir = catdir( $args{'install-base'}, $r );
417 0 ▶ unlink $dir if -l $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -l $dir 0 0 0
418 }
419  
420 # remove (usr/)?s?bin if it's an install from start
421 0 ▶ unless ( keys %$installed_hash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %$installed_hash) 0 0 0
422 0 for my $r (
423 'bin', 'sbin',
424 catdir( 'usr', 'bin' ),
425 catdir( 'usr', 'sbin' ),
426 )
427 {
428 0 my $dir = catdir( $args{'install-base'}, $r );
429 0 ▶ next unless -e $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
430 0 rmtree($dir);
431 }
432 }
433  
434 0 for my $dist (@$order) {
435 0 _install( $dist, $log );
436 0 _record( $dist, $log );
437 0 ▶ if ( $dist =~ /^perl/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist =~ /^perl/) 0 0 0
438 0 my $perl = catfile( $args{'install-base'}, 'bin', 'perl' );
439 0 ▶ $args{perl} = -e $perl ? $perl : $^X;
Branch: 1 branch
BranchTrueFalseTotal
-e $perl ? : 0 0 0
440 0 _set_perl5lib();
441 }
442 0 chdir $build_base;
443 }
444  
445 mkdir catdir( $args{'install-base'}, 'bin' )
446 0 ▶ unless -e catdir( $args{'install-base'}, 'bin' );
Branch: 1 branch
BranchTrueFalseTotal
unless -e catdir($args{"install-base"}, "bin") 0 0 0
447  
448 # in case wrappers are overwritten by accident
449 0 for ( 'shipwright-script-wrapper', 'shipwright-perl-wrapper' ) {
450 rcopy( catfile( 'etc', $_ ),
451 0 catfile( $args{'install-base'}, 'etc', $_ ) );
452 }
453  
454 0 my $cwd = getcwd;
455 0 chdir $args{'install-base'};
456 0 ▶ open my $tmp_fh, '>', '__as',
Branch: 1 branch
BranchTrueFalseTotal
open my $tmp_fh, ">", "__as" or confess(qq[can't wriite to $args{"install-base"}/__as: $!]) 0 0 0
457 or confess "can't wriite to $args{'install-base'}/__as: $!";
458 0 print $tmp_fh $args{as};
459 0 close $tmp_fh;
460  
461 0 mkdir 'as';
462 0 my $as_dir = catdir( 'as', $args{as} );
463 0 mkdir $as_dir;
464  
465 0 ▶ unless ( is_on_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_on_windows()) 0 0 0
466 0 for my $r ( 'lib', 'bin', 'sbin' ) {
467 0 ▶ next unless -e $r;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $r 0 0 0
468 0 my $dir = catdir( $as_dir, $r );
469 0 rmove( $r, catdir( $as_dir, $r ) );
470  
471 0 ▶ if ( $r !~ /bin/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r =~ /bin/) 0 0 0
472 0 symlink $dir, $r;
473 }
474 }
475  
476 # in usr dir
477 0 my $usr_dir = catdir( $as_dir, 'usr' );
478 0 mkdir $usr_dir;
479 0 for my $r ( 'bin', 'sbin' ) {
480 0 ▶ next unless -e catdir( 'usr', $r );
Branch: 1 branch
BranchTrueFalseTotal
unless -e catdir("usr", $r) 0 0 0
481 0 rmove( catdir( 'usr', $r ), catdir( $usr_dir, $r ) );
482 }
483 0 chdir $cwd;
484  
485 0 wrap_bin($log);
486 }
487  
488 0 print "install finished, the dists are at $args{'install-base'}\n";
489 0 print $log "install finished, the dists are at $args{'install-base'}\n";
490 }
491 }
492  
493 0 ▶sub _install {
Subroutine _install: not called CC=31 SCAR=69.0
494 0 my $dir = shift;
495 0 my $log = shift;
496  
497 0 ▶ if ( $args{with}{$dir} && -e catdir( 'tmp_dists', $dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'with'}{$dir} and -e catdir('tmp_dists', $dir)) { } 0 0 0
Condition0%0/3
$args{"with"}{$dir} and -e catdir("tmp_dists", $dir)
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"with"}{$dir} and -e catdir("tmp_dists", $dir)
$args{"with"}{$dir} -e catdir("tmp_dists", $dir)
Truth table0%0/3
A and B
A= $args{"with"}{$dir}B= -e catdir("tmp_dists", $dir)
ABresult
0X0
100
111
498 0 chdir catdir( 'tmp_dists', $dir );
499 }
500 else {
501 0 ▶ if ($branches) {
Branch: 1 branch
BranchTrueFalseTotal
if ($branches) 0 0 0
502 0 ▶ my $branch = $args{branches}{$dir} || $branches->{$dir}[0];
Condition0%0/3
$args{'branches'}{$dir} || $branches->{$dir}[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'branches'}{$dir} || $branches->{$dir}[0]
$args{'branches'}{$dir} $branches->{$dir}[0]
Truth table0%0/3
A || B
A= $args{'branches'}{$dir}B= $branches->{$dir}[0]
ABresult
1X1
011
000
503  
504 # If no branch is specified but the vendor dir is there,
505 # assume we should use it
506 # XXX TODO - this will fail on old shipwright sources
507 # which have a vendor directory inside the dist.
508 0 ▶ if ( !$branch && -d catdir( 'sources', $dir, 'vendor' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $branch and -d catdir("sources", $dir, "vendor")) 0 0 0
Condition0%0/3
not $branch and -d catdir("sources", $dir, "vendor")
!ll&&!rl&&r
000
MC/DC0%0/2
not $branch and -d catdir("sources", $dir, "vendor")
not $branch -d catdir("sources", $dir, "vendor")
Truth table0%0/3
not(A) and B
A= not $branchB= -d catdir("sources", $dir, "vendor")
ABresult
0X0
100
111
509 0 $branch = 'vendor';
510 }
511 0 my $dist_dir = catdir( 'dists', $dir );
512 0 ▶ rmtree($dist_dir) if -e $dist_dir;
Branch: 1 branch
BranchTrueFalseTotal
if -e $dist_dir 0 0 0
513 0 ▶ rcopy( catdir( 'sources', $dir, split /\//, $branch ), $dist_dir )
Branch: 1 branch
BranchTrueFalseTotal
rcopy(catdir("sources", $dir, split(m[/], $branch, 0)), $dist_dir) or confess("copy sources/$dir/$branch to dists/$dir failed: $!") 0 0 0
514 or confess "copy sources/$dir/$branch to dists/$dir failed: $!";
515 }
516 0 chdir catdir( 'dists', $dir );
517 }
518  
519 0 ▶ my $skip_test = $args{'skip-test'} || $args{'skip-test-except-final'};
Condition0%0/3
$args{'skip-test'} || $args{'skip-test-except-final'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'skip-test'} || $args{'skip-test-except-final'}
$args{'skip-test'} $args{'skip-test-except-final'}
Truth table0%0/3
A || B
A= $args{'skip-test'}B= $args{'skip-test-except-final'}
ABresult
1X1
011
000
520  
521 0 ▶ if ( $dir eq $order->[-1] && $args{'skip-test-except-final'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq $order->[-1] and $args{"skip-test-except-final"}) 0 0 0
Condition0%0/3
$dir eq $order->[-1] and $args{"skip-test-except-final"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dir eq $order->[-1] and $args{"skip-test-except-final"}
$dir eq $order->[-1] $args{"skip-test-except-final"}
Truth table0%0/3
A and B
A= $dir eq $order->[-1]B= $args{"skip-test-except-final"}
ABresult
0X0
100
111
522  
523 # do not skip our main dist's test
524 0 $skip_test = 0;
525 }
526  
527 0 print "building $dir\n";
528  
529 0 ▶ if ( -e catfile( '..', '..', 'scripts', $dir, 'build.pl' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile('..', '..', 'scripts', $dir, 'build.pl')) { } 0 0 0
530 0 print $log "found build.pl for $dir, will install $dir using that\n";
531 my $cmd = join ' ',
532 $args{perl},
533 '-MShipwright::Util::CleanINC',
534 catfile( '..', '..', 'scripts', $dir, 'build.pl' ),
535 '--install-base' => $args{'install-base'},
536 0 ▶ '--flags' => join( ',', keys %{ $args{flags} } ),
Branch: 3 branches
BranchTrueFalseTotal
$skip_test ? : 0 0 0
$args{'force'} ? : 0 0 0
$args{'clean'} ? : 0 0 0
537 $skip_test ? '--skip-test' : (), $args{'force'} ? '--force' : (),
538 0 $args{'clean'} ? '--clean' : ();
539 0 system("$cmd $system_cmd_pipe");
540 0 ▶ if ( $? >> 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? >> 8) 0 0 0
541 0 ▶ print $log "build $dir failed"
Branch: 1 branch
BranchTrueFalseTotal
$? == -1 ? : 0 0 0
542 . (
543 $? == -1
544 ? ": $!"
545 : ( ' with value ' . ( $? >> 8 ) )
546 ) . "\n";
547 0 my $error =
548 "build $dir failed, the last output of build.log is:\n" . "\t"
549 . _get_log();
550 0 confess $error;
551 }
552 }
553 else {
554 0 my $cmds;
555 0 ▶ if ( -e catfile( '..', '..', 'scripts', $dir, 'build' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile('..', '..', 'scripts', $dir, 'build')) { } 0 0 0
556 0 print $log "found build for $dir, will install $dir using that\n";
557 0 $cmds = cmds( catfile( '..', '..', 'scripts', $dir, 'build' ) );
558 }
559 else {
560 0 print $log "no build for $dir, will detect\n";
561 0 $cmds = detect_cmds( '.' );
562 }
563  
564 0 for (@$cmds) {
565 0 my ( $type, $cmd ) = @$_;
566 0 ▶ next if $type eq 'clean' && $args{'noclean-after-install'};
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "clean" and $args{"noclean-after-install"} 0 0 0
Condition0%0/3
$type eq "clean" and $args{"noclean-after-install"}
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "clean" and $args{"noclean-after-install"}
$type eq "clean" $args{"noclean-after-install"}
Truth table0%0/3
A and B
A= $type eq "clean"B= $args{"noclean-after-install"}
ABresult
0X0
100
111
567  
568 0 ▶ if ( $skip_test && $type eq 'test' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_test and $type eq "test") 0 0 0
Condition0%0/3
$skip_test and $type eq "test"
!ll&&!rl&&r
000
MC/DC0%0/2
$skip_test and $type eq "test"
$skip_test $type eq "test"
Truth table0%0/3
A and B
A= $skip_testB= $type eq "test"
ABresult
0X0
100
111
569 0 print $log "skip build $type part in $dir\n";
570 0 next;
571 }
572  
573 0 print $log "build $type part in $dir with cmd: $cmd\n";
574  
575 0 print $log "running shipwright build command: $cmd\n";
576 0 system("$cmd $system_cmd_pipe");
577 0 ▶ if ( $? >> 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? >> 8) { } 0 0 0
578 0 ▶ print $log "build $dir $type failed"
Branch: 1 branch
BranchTrueFalseTotal
$? == -1 ? : 0 0 0
579 . (
580 $? == -1
581 ? ": $!"
582 : ( ' with value ' . ( $? >> 8 ) )
583 ) . "\n";
584 0 ▶ if ( $type eq 'test' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "test") 0 0 0
585 0 ▶ if ( $args{force} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'force'}) { } 0 0 0
elsif (eval "$ktf->{$dir}") { } 0 0 0
586 0 print $log
587 "although tests failed, will install anyway since we have force arg\n";
588 0 next;
589 }
590 ## no critic
591 elsif ( eval "$ktf->{$dir}" ) {
592 0 print $log
593 "although tests failed, will install anyway since it's a known failure\n";
594 0 next;
595 }
596 }
597  
598 0 ▶ if ( $type ne 'clean' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "clean") 0 0 0
599  
600 # clean is trivial, we'll just ignore if 'clean' fails
601 0 my $error =
602 "build $dir $type part failed, last output of build.log is:\n"
603 . "\t"
604 . _get_log();
605 0 confess $error;
606 }
607 }
608 else {
609 0 print $log "build $dir $type part succeeded!\n";
610 }
611 }
612 }
613  
614 0 print $log "build $dir succeeded\n";
615 0 ▶ print '=' x 80, "\n" if $args{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"verbose"} 0 0 0
616 }
617  
618 0 ▶sub wrap_bin {
Subroutine wrap_bin: not called CC=2 SCAR=17.9
619 0 my $log = shift;
620  
621 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=15 SCAR=54.8
622 0 my $file = $_;
623  
624 0 ▶ return unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
625  
626 0 my $wrap_dir = $File::Find::dir;
627 0 $wrap_dir =~ s!as/$args{as}/!!;
628  
629 0 my $wrap_file = catfile( $wrap_dir, $file );
630 0 my $tmp = $File::Find::dir;
631 0 $tmp =~ s/\Q$args{'install-base'}\E//g;
632 my $wrapped_depth =
633 scalar( splitdir($File::Find::dir) ) -
634 0 scalar( splitdir( $args{'install-base'} ) );
635  
636 0 ▶ mkdir $wrap_dir unless -d $wrap_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $wrap_dir 0 0 0
637  
638 # return if it's been wrapped already
639 0 ▶ if ( -l $wrap_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $wrap_file) 0 0 0
640 0 print $log "seems $file has been already wrapped, skipping\n";
641 0 return;
642 }
643  
644 0 my $type;
645 0 ▶ if ( -T $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-T $file) 0 0 0
646 0 ▶ open my $fh, '<', $file or confess "can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or confess("can't open ${file}: $!") 0 0 0
647 0 my $shebang = <$fh>;
648 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shebang and $shebang =~ m[ \Q$args{"install-base"}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+) |\benv\s+(\w+) ]x) 0 0 0
Condition0%0/3
defined $shebang and $shebang =~ m[ \Q$args{"install-base"}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+) |\benv\s+(\w+) ]x
!ll&&!rl&&r
000
MC/DC0%0/2
defined $shebang and $shebang =~ m[ \Q$args{"install-base"}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+) |\benv\s+(\w+) ]x
defined $shebang $shebang =~ m[ \Q$args{"install-base"}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+) |\benv\s+(\w+) ]x
Truth table0%0/3
A and B
A= defined $shebangB= $shebang =~ m[ \Q$args{"install-base"}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+) |\benv\s+(\w+) ]x
ABresult
0X0
100
111
649 defined($shebang)
650 && $shebang =~ m{
651 \Q$args{'install-base'}\E(?:/|\\)(?:s?bin)(?:/|\\)(\w+)
652 |\benv\s+(\w+)
653 }x
654 )
655 {
656 0 ▶ $type = $1 || $2;
Condition0%0/3
$1 || $2
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 || $2
$1 $2
Truth table0%0/3
A || B
A= $1B= $2
ABresult
1X1
011
000
657 }
658 }
659  
660 # if we have this $type(e.g. perl) installed and have that specific wrapper,
661 # then link to it, else link to the normal one
662 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($type and -e catfile('..', 'bin', $type) || -e catfile(('..') x $wrapped_depth, 'bin', $type) and -e catfile(('..') x $wrapped_depth, 'etc', "shipwright-$type-wrapper")) { } 0 0 0
Condition0%0/9
$type and -e catfile("..", "bin", $type) || -e catfile(("..") x $wrapped_depth, "bin", $type) and -e catfile(("..") x $wrapped_depth, "etc", "shipwright-$type-wrapper")
!ll&&!rl&&r
000
$type and -e catfile("..", "bin", $type) || -e catfile(("..") x $wrapped_depth, "bin", $type)
!ll&&!rl&&r
000
-e catfile("..", "bin", $type) or -e catfile(("..") x $wrapped_depth, "bin", $type)
l!l&&r!l&&!r
000
MC/DC0%0/4
$type and -e catfile("..", "bin", $type) || -e catfile(("..") x $wrapped_depth, "bin", $type) and -e catfile(("..") x $wrapped_depth, "etc", "shipwright-$type-wrapper")
$type -e catfile("..", "bin", $type) -e catfile(("..") x $wrapped_depth, "bin", $type) -e catfile(("..") x $wrapped_depth, "etc", "shipwright-$type-wrapper")
Truth table0%0/6
A and B or C and D
A= $typeB= -e catfile("..", "bin", $type)C= -e catfile(("..") x $wrapped_depth, "bin", $type)D= -e catfile(("..") x $wrapped_depth, "etc", "shipwright-$type-wrapper")
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
663 $type
664 && ( -e catfile( '..', 'bin', $type )
665 || -e catfile( ('..') x $wrapped_depth, 'bin', $type ) )
666 && -e catfile(
667 ('..') x $wrapped_depth,
668 'etc', "shipwright-$type-wrapper"
669 )
670 )
671 {
672 0 ▶ symlink catfile( '..', 'etc', "shipwright-$type-wrapper" ) =>
Branch: 1 branch
BranchTrueFalseTotal
symlink catfile("..", "etc", "shipwright-$type-wrapper"), $wrap_file or confess($!) 0 0 0
673 $wrap_file
674 or confess $!;
675 }
676 else {
677  
678 0 ▶ symlink catfile( '..', 'etc', 'shipwright-script-wrapper' ) =>
Branch: 1 branch
BranchTrueFalseTotal
symlink catfile("..", "etc", "shipwright-script-wrapper"), $wrap_file or confess($!) 0 0 0
679 $wrap_file
680 or confess $!;
681 }
682 0 chmod oct 755, $wrap_file;
683 0 };
684  
685 my @dirs =
686 0 grep { -e $_ }
687 0 map { catdir( $args{'install-base'}, 'as', $args{as}, $_ ) } 'bin',
688 'sbin',
689 catdir( 'usr', 'bin' ), catdir( 'usr', 'sbin' );
690 0 ▶ find( { wanted => $sub, follow => 1 }, @dirs ) if @dirs;
Branch: 1 branch
BranchTrueFalseTotal
if @dirs 0 0 0
691  
692 }
693  
694 0 ▶sub substitute {
Subroutine substitute: not called CC=9 SCAR=45.0
695 0 my $text = shift;
696 0 ▶ return unless $text;
Branch: 1 branch
BranchTrueFalseTotal
unless $text 0 0 0
697  
698 0 ▶ if ( $args{'no-install-base'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'no-install-base'}) { } 0 0 0
699 0 $text =~ s/\s+\S*%%INSTALL_BASE%%\S*/ /g;
700 0 ▶ if ( $text =~ /Build\.PL/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /Build\.PL/) 0 0 0
701 0 $text =~ s/--install_path//g;
702 }
703 }
704 else {
705 0 my $install_base = $args{'install-base'};
706 0 $text =~ s/%%INSTALL_BASE%%/$install_base/g;
707 }
708  
709 0 ▶ my $perl = -e $args{perl} ? $args{perl} : $^X;
Branch: 1 branch
BranchTrueFalseTotal
-e $args{'perl'} ? : 0 0 0
710  
711 0 my $perl_archname;
712 0 ▶ if ( is_on_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_on_windows()) { } 0 0 0
713 0 $perl_archname = `$perl -MConfig -e "print \$Config{archname}"`;
714 }
715 else {
716 0 $perl_archname = `$perl -MConfig -e 'print \$Config{archname}'`;
717 }
718 0 $text =~ s/%%PERL%%/$perl -I$inc_lib -MShipwright::Util::CleanINC/g;
719 0 $text =~ s/%%PERL_ARCHNAME%%/$perl_archname/g;
720 0 $text =~ s/%%MODULE_BUILD_EXTRA%%//g;
721 0 $text =~ s/%%MAKE%%/$args{make}/g;
722  
723 0 ▶ if ( is_on_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_on_windows()) { } 0 0 0
724 0 `$perl -I$inc_lib -MShipwright::Util::CleanINC -e"eval { require Pod::Man}; if (\$@) { exit 1} else { exit 0 }" `;
725 }
726 else {
727 0 `$perl -I$inc_lib -MShipwright::Util::CleanINC -e'eval { require Pod::Man}; if (\$@) { exit 1} else { exit 0 }' `;
728 }
729 0 my $no_podman = $? >> 8;
730 0 ▶ if ( $no_podman || $args{'skip-man-pages'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_podman or $args{'skip-man-pages'}) { } 0 0 0
Condition0%0/3
$no_podman or $args{"skip-man-pages"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$no_podman or $args{"skip-man-pages"}
$no_podman $args{"skip-man-pages"}
Truth table0%0/3
A or B
A= $no_podmanB= $args{"skip-man-pages"}
ABresult
1X1
011
000
731 0 $text =~
732 s/%%MODULE_BUILD_BEFORE_BUILD_PL%%/-MShipwright::Util::PatchModuleBuild/;
733 0 $text =~
734 s/%%MODULE_BUILD_BEFORE_BUILD%%/-MShipwright::Util::PatchModuleBuild/;
735 0 $text =~
736 s/%%MAKEMAKER_CONFIGURE_EXTRA%%/INSTALLMAN1DIR=none INSTALLMAN3DIR=none/;
737 }
738 else {
739 0 $text =~ s/%%MAKEMAKER_CONFIGURE_EXTRA%%//;
740 0 $text =~ s/%%MODULE_BUILD_BEFORE_BUILD_PL%%//;
741 0 $text =~ s/%%MODULE_BUILD_BEFORE_BUILD%%//;
742 }
743  
744 0 return $text;
745 }
746  
747 0 ▶sub test {
Subroutine test: not called CC=2 SCAR=17.9
748 0 my $cmds = cmds( catfile( 't', 'test' ) );
749 0 for (@$cmds) {
750 0 my ( $type, $cmd ) = @$_;
751 0 print $log "run tests $type part with cmd: $cmd\n";
752  
753 # the return of system is not so uselful, so omit it
754 0 system($cmd);
755 }
756 }
757  
758 0 ▶sub cmds {
Subroutine cmds: not called CC=8 SCAR=42.8
759 0 my $file = shift;
760  
761 0 my @cmds;
762  
763 0 ▶ if ( ref $file eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $file eq 'ARRAY') { } 0 0 0
elsif (-e $file) { } 0 0 0
764 0 @cmds = @$file;
765 }
766 elsif ( -e $file ) {
767 0 ▶ open my $fh, '<', $file or confess "$!: $file";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or confess("$!: $file") 0 0 0
768 0 @cmds = <$fh>;
769 0 close $fh;
770 0 chomp @cmds;
771 }
772  
773 0 @cmds = map { substitute($_) } @cmds;
774  
775 0 my $return = [];
776 0 for (@cmds) {
777 0 my ( $type, $cmd );
778 0 ▶ next unless /\S/ && /^(?!#)/; # skip commented and blank lines
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ and /^(?!#)/ 0 0 0
Condition0%0/3
/\S/ and /^(?!#)/
!ll&&!rl&&r
000
MC/DC0%0/2
/\S/ and /^(?!#)/
/\S/ /^(?!#)/
Truth table0%0/3
A and B
A= /\S/B= /^(?!#)/
ABresult
0X0
100
111
779  
780 0 ▶ if (/^(\S+):\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\S+):\s*(.*)/) { } 0 0 0
781 0 $type = $1;
782 0 $cmd = $2;
783 }
784 else {
785 0 $type = '';
786 0 $cmd = $_;
787 }
788 0 push @$return, [ $type, $cmd ];
789 }
790  
791 0 return $return;
792 }
793  
794 0 ▶sub clean {
Subroutine clean: not called CC=4 SCAR=30.0
795 0 ▶ open my $log, '>', 'clean.log' or confess $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $log, ">", "clean.log" or confess($!) 0 0 0
796  
797 0 rmtree('tmp_dists');
798 0 print $log "removed tmp_dists\n";
799  
800 0 ▶ if ($branches) {
Branch: 1 branch
BranchTrueFalseTotal
if ($branches) { } 0 0 0
801 0 rmtree('dists');
802 0 print $log "removed dists\n";
803 }
804 else {
805 0 for my $dist (@$order) {
806 0 _clean( $dist, $log );
807 0 chdir $build_base;
808 }
809 }
810  
811 0 unlink '__need_clean';
812 }
813  
814 0 ▶sub _clean {
Subroutine _clean: not called CC=7 SCAR=40.3
815 0 my $dir = shift;
816 0 my $log = shift;
817  
818 0 my $cmd;
819 0 chdir catdir( 'dists', $dir );
820  
821 0 ▶ if ( -e catfile( '..', '..', 'scripts', $dir, 'build.pl' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile('..', '..', 'scripts', $dir, 'build.pl')) { } 0 0 0
822 0 print $log "Using build.pl to clean $dir\n";
823 $cmd = join ' ', $args{perl},
824 "-I $inc_lib",
825 '-MShipwright::Util::CleanINC',
826 catfile( '..', '..', 'scripts', $dir, 'build.pl' ),
827 '--install-base' => $args{'install-base'},
828 0 '--flags' => join( ',', keys %{ $args{flags} } ),
829 '--clean';
830 }
831 else {
832 0 my $cmds;
833 0 ▶ if ( -e catfile( '..', '..', 'scripts', $dir, 'build' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile('..', '..', 'scripts', $dir, 'build')) { } 0 0 0
834 0 print $log "found build for $dir, will install $dir using that\n";
835 0 $cmds = cmds( catfile( '..', '..', 'scripts', $dir, 'build' ) );
836 }
837 else {
838 0 print $log "no build for $dir, will detect\n";
839 0 $cmds = detect_cmds( '.' );
840 }
841  
842 0 for (@$cmds) {
843 0 my ( $type, $c ) = @$_;
844 0 ▶ if ( $type eq 'clean' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "clean") 0 0 0
845 0 $cmd = $c;
846 0 last;
847 }
848 }
849 }
850  
851 0 ▶ if ( system($cmd) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (system $cmd) { } 0 0 0
852 0 print $log "clean $dir failed.\n";
853 }
854 else {
855 0 print $log "clean $dir succeeded.\n";
856 }
857  
858 0 ▶ print '=' x 80, "\n" if $args{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"verbose"} 0 0 0
859 }
860  
861 0 ▶sub get_install_base {
Subroutine get_install_base: not called CC=2 SCAR=17.9
862 0 ▶ if ( open my $fh, '<', '__install_base' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "__install_base") 0 0 0
863 0 my $install_base = <$fh>;
864 0 close $fh;
865 0 chomp $install_base;
866 0 return $install_base;
867 }
868 }
869  
870 0 ▶sub get_default_builder_options {
Subroutine get_default_builder_options: not called CC=5 SCAR=34.0
871 0 my @argv;
872 0 ▶ if ( open my $fh, '<', '__default_builder_options' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "__default_builder_options") 0 0 0
873 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
874 0 chomp;
875 0 ▶ next if /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/ 0 0 0
876 0 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
877 0 push @argv, $_;
878 }
879 0 close $fh;
880 }
881 0 return @argv;
882 }
883  
884 0 ▶sub process_tmp_dists {
Subroutine process_tmp_dists: not called CC=4 SCAR=30.0
885 0 mkdir 'tmp_dists';
886  
887 0 for my $name ( keys %{ $args{with} } ) {
888 0 my $cmd = cmd( $name, $args{with}{$name} );
889 0 ▶ if ( ref $cmd eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cmd eq 'CODE') { } 0 0 0
890 0 $cmd->run();
891 }
892 else {
893 0 ▶ system($cmd) && confess "$cmd failed";
Branch: 1 branch
BranchTrueFalseTotal
system $cmd and confess("$cmd failed") 0 0 0
894 }
895 }
896 }
897  
898 # this's a simpler version compared to shipwright's source part, only
899 # dir, svn, svk and git are supported currently.
900 # warn: dist in svn and svk must be a dir instead of a compressed file.
901  
902 0 ▶sub cmd {
Subroutine cmd: not called CC=5 SCAR=34.0
903 0 my ( $name, $source ) = @_;
904  
905 0 ▶ if ( $source =~ s/^dir(ectory)?://i ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($source =~ s/^dir(ectory)?://i) { } 0 0 0
elsif ($source =~ /^svn:/i) { } 0 0 0
elsif ($source =~ m[^(//|svk:)]i) { } 0 0 0
elsif ($source =~ /^git:/i) { } 0 0 0
906 0 ▶ return sub { rcopy( $source, catdir( 'tmp_dists', $name ) ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
907 }
908 elsif ( $source =~ /^svn:/i ) {
909 0 $source =~ s{^svn:(?!//)}{}i;
910 0 return "svn export $source tmp_dists/$name";
911 }
912 elsif ( $source =~ m{^(//|svk:)}i ) {
913 0 $source =~ s/^svk://i;
914 0 return "svk co $source tmp_dists/$name";
915 }
916 elsif ( $source =~ m{^git:}i ) {
917 0 $source =~ s{^git:(?!//)}{}i;
918 0 return "git clone $source tmp_dists/$name";
919 }
920  
921 0 return;
922 }
923  
924 0 ▶sub _record {
Subroutine _record: not called CC=3 SCAR=24.8
925 0 my $dist = shift;
926 my $branch =
927 defined $args{branches}{$dist}
928 ? $args{branches}{$dist}
929 0 ▶ : $branches->{$dist}[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'branches'}{$dist} ? : 0 0 0
930 0 ▶ $branch ||= 'vendor';
Condition0%0/2
$branch ||= "vendor"
l!l
00
MC/DC0%0/1
$branch ||= "vendor"
$branch
Truth table0%0/2
A
A= $branch
Aresult
11
00
931 0 my $current_version = $version->{$dist}{$branch};
932 0 $installed->[0]{$dist} = $current_version;
933 0 $installed->write($installed_file);
934 }
935  
936 0 ▶sub is_on_windows {
Subroutine is_on_windows: not called CC=1 SCAR=6.9
937 0 return $^O =~ /MSWin/;
938 }
939  
940 0 ▶sub which {
Subroutine which: not called CC=6 SCAR=37.4
941 0 my $name = shift;
942  
943 0 my $path;
944  
945 LINE:
946 0 for my $dir ( path() ) {
947 0 my $p = catfile( $dir, $name );
948  
949 # XXX any other names need to try?
950 0 my @try = grep { -x } ( $p, $p . $bin_ext );
951 0 for my $try (@try) {
952 0 $path = $try;
953 0 last LINE;
954 }
955 }
956  
957 0 ▶ return unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 0 0
958 0 ▶ if ( $path =~ /\s/ && $path !~ /^$bin_quote/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\s/ and not $path =~ /^$bin_quote/) 0 0 0
Condition0%0/3
$path =~ /\s/ and not $path =~ /^$bin_quote/
!ll&&!rl&&r
000
MC/DC0%0/2
$path =~ /\s/ and not $path =~ /^$bin_quote/
$path =~ /\s/ not $path =~ /^$bin_quote/
Truth table0%0/3
A and not(B)
A= $path =~ /\s/B= not $path =~ /^$bin_quote/
ABresult
0X0
100
111
959 0 $path = $bin_quote . $path . $bin_quote;
960 }
961  
962 0 return $path;
963 }
964  
965 0 ▶sub _get_perl_arch {
Subroutine _get_perl_arch: not called CC=3 SCAR=24.8
966 0 ▶ my $arch_command = -e $args{perl} ? $args{perl} : $^X;
Branch: 1 branch
BranchTrueFalseTotal
-e $args{'perl'} ? : 0 0 0
967 0 ▶ if ( is_on_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_on_windows()) { } 0 0 0
968 0 $arch_command .= q{ -MConfig -e "print $Config{archname}" };
969 }
970 else {
971 0 $arch_command .= q{ -MConfig -e 'print $Config{archname}'};
972 }
973 0 return `$arch_command`;
974 }
975  
976 0 ▶sub _set_perl5lib {
Subroutine _set_perl5lib: not called CC=1 SCAR=6.9
977 $ENV{PERL5LIB} = join(
978 ':',
979 catdir( 'blib', 'lib' ),
980 catdir( 'blib', 'arch' ),
981 $inc_lib, #BLIB COMES FIRST TO PLEASE MODULE::BUILD
982 catdir( $args{'install-base'}, 'lib', 'perl5', _get_perl_arch() ),
983 catdir( $args{'install-base'}, 'lib', 'perl5', 'site_perl' ),
984 catdir( $args{'install-base'}, 'lib', 'perl5' ),
985 catdir(
986 $args{'install-base'}, 'as',
987 $args{as}, 'lib',
988 'perl5', _get_perl_arch()
989 ),
990 catdir(
991 $args{'install-base'}, 'as',
992 $args{as}, 'lib',
993 'perl5', 'site_perl'
994 ),
995 0 catdir( $args{'install-base'}, 'as', $args{as}, 'lib', 'perl5' ),
996 );
997 }
998  
999 0 ▶sub _get_log {
Subroutine _get_log: not called CC=4 SCAR=30.0
1000 0 ▶ my $number = shift || 20;
Condition0%0/2
shift() || 20
l!l
00
MC/DC0%0/1
shift() || 20
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1001 0 require Tie::File;
1002 0 ▶ if ( tie my @array, 'Tie::File', $build_log_file, autochomp => 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tie my @array, 'Tie::File', $build_log_file, 'autochomp', 0) { } 0 0 0
1003 0 ▶ $number = @array if $number > @array;
Branch: 1 branch
BranchTrueFalseTotal
if $number > @array 0 0 0
1004 0 return join "\t", grep { defined } @array[ -1 * $number .. -1 ];
1005 }
1006 else {
1007 0 warn "failed to open $build_log_file";
1008 0 return;
1009 }
1010 }
1011  
1012 0 ▶sub detect_cmds {
Subroutine detect_cmds: not called CC=5 SCAR=34.0
1013 0 my $dir = shift;
1014 0 ▶ if ( -f catfile( $dir, 'Build.PL' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f catfile($dir, "Build.PL")) 0 0 0
1015 0 print $log "detected Module::Build build system\n";
1016 0 return cmds(
1017 [
1018 'configure: %%PERL%% %%MODULE_BUILD_BEFORE_BUILD_PL%% Build.PL --install_base=%%INSTALL_BASE%% --install_path lib=%%INSTALL_BASE%%/lib/perl5 --install_path arch=%%INSTALL_BASE%%/lib/perl5',
1019 'make: %%PERL%% %%MODULE_BUILD_BEFORE_BUILD%% Build',
1020 'test: %%PERL%% %%MODULE_BUILD_BEFORE_BUILD%% Build test',
1021 'install: %%PERL%% %%MODULE_BUILD_BEFORE_BUILD%% Build install',
1022 'clean: %%PERL%% %%MODULE_BUILD_BEFORE_BUILD%% Build realclean',
1023 ]
1024 );
1025 }
1026 0 ▶ if ( -f catfile( $dir, 'Makefile.PL' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f catfile($dir, "Makefile.PL")) 0 0 0
1027 0 print $log "detected ExtUtils::MakeMaker build system\n";
1028 0 return cmds(
1029 [
1030 'configure: %%PERL%% Makefile.PL LIB=%%INSTALL_BASE%%/lib/perl5/ PREFIX=%%INSTALL_BASE%% INSTALLSITEARCH=%%INSTALL_BASE%%/lib/perl5 INSTALLARCHLIB=%%INSTALL_BASE%%/lib/perl5 %%MAKEMAKER_CONFIGURE_EXTRA%%',
1031 'make: %%MAKE%%',
1032 'test: %%MAKE%% test',
1033 'install: %%MAKE%% install',
1034 'clean: %%MAKE%% clean',
1035 ]
1036 );
1037 }
1038 0 ▶ if ( -f catfile( $dir, 'configure' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f catfile($dir, "configure")) 0 0 0
1039 0 print $log "detected autoconf build system\n";
1040 0 return cmds(
1041 [
1042 'configure: ./configure --prefix=%%INSTALL_BASE%%',
1043 'make: %%MAKE%%',
1044 'install: %%MAKE%% install',
1045 'clean: %%MAKE%% clean',
1046 ]
1047 );
1048 }
1049 0 ▶ if ( -f catfile( $dir, 'configure.cmake' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f catfile($dir, 'configure.cmake')) { } 0 0 0
1050 0 print $log "detected cmake build system\n";
1051 0 return cmds(
1052 [
1053 'configure: cmake . -DCMAKE_INSTALL_PREFIX==%%INSTALL_BASE%%',
1054 'make: %%MAKE%%',
1055 'install: %%MAKE%% install',
1056 'clean: %%MAKE%% clean',
1057 ]
1058 );
1059 }
1060 else {
1061 0 die "unknown build system for $dir";
1062 }
1063 }
1064  
« blib/lib/Shipwright/Script/List.pm ↑ Summary blib/lib/Shipwright/Backend/Base.pm »