alienfile

filter: Statementstmt 38.8% 47 / 121 Branchbran 25.0% 9 / 36 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 42.1% 8 / 19 Podpod n/a totaltotal 36.9% 68 / 184 CC 29 SCAR 27.3
CC
29
Cov
36%
_arch_norm
52.9
__ANON__
20.0
__ANON__
12.0
CRAP 15.4
↑ Summary blib/lib/Alien/7zip.pm »
1 1 ▶use alienfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 # NOTE: you can set ALIEN_7ZIP_SHARE_PREFER to either:
4 #
5 # - "auto": try binary install if possible (default)
6 # - "source": try from-source install only
7 # - "binary": try from-binary install only
8  
9 # NOTE
10 # - 7zip provides the '7zz' binary on Unix-likes and the '7z.exe' binary on
11 # Windows.
12 # - p7zip is a fork which provides the '7z' binary on Unix-likes.
13 plugin 'Probe::CommandLine' => (
14 command => $_,
15 match => qr/7-Zip (?:\Q(z) \E)?([0-9\.]+)/,
16 version => qr/7-Zip (?:\Q(z) \E)?([0-9\.]+)/,
17 1 ) for qw( 7z.exe 7zz );
18  
19 0 ▶sub can_source {
Subroutine can_source: not called CC=1 SCAR=6.9
20 0 return 1;
21 }
22  
23 0 ▶sub do_source {
Subroutine do_source: not called CC=2 SCAR=17.9
24 0 plugin Download => (
25 filter => qr/^7z(\d+).*-src\.tar\.xz$/,
26 version => qr/^7z([0-9\.]+)/,
27 );
28 0 plugin Extract => 'tar.xz';
29 0 my $build_dir = 'CPP/7zip/Bundles/Alone2';
30 0 my $output_dir = '_o';
31 0 my $bin_name = '7zz';
32 0 patch [
33 '%{patch} -p1 < %{.install.patch}/0001-Add-Apple-define-for-header.patch'
34 ];
35 build [
36 [ '%{make}',
37 qw(-C), $build_dir,
38 qw(-f makefile.gcc),
39 "O=$output_dir",
40 ( $^O eq 'MSWin32' ? ('IS_MINGW=1') : () ),
41 ],
42 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 my ($build) = @_;
44 0 my $prefix = Path::Tiny::path($build->install_prop->{prefix});
45 0 my $output = Path::Tiny::path($build_dir, $output_dir);
46  
47 0 my $prefix_bin_name = $prefix->child('bin', $bin_name);
48 0 $prefix_bin_name->parent->mkpath;
49 0 File::Copy::Recursive::fcopy($output->child($bin_name), $prefix_bin_name);
50 }
51 0 ▶ ];
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
52 0 ▶ after build => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 my($build) = @_;
54 0 $build->runtime_prop->{'style'} = 'source';
55 0 ▶ if( $^O ne 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O ne 'MSWin32') { } 0 0 0
56 # on Unix-likes (linux, darwin)
57 0 $build->runtime_prop->{command} = '7zz';
58 } else {
59 # TODO not yet implemented
60 0 $build->runtime_prop->{command} = '7z.exe';
61 }
62 0 };
63 }
64  
65 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 # normalise architecture name
67 1 ▶sub _arch_norm {
Subroutine _arch_norm: called CC=8 SCAR=39.7
68 1 ▶ if( $Config{archname} =~ /x64|x86_64|amd64/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Build::Auto::X0::Alienfile::Config{"archname"} =~ /x64|x86_64|amd64/i) 1 0 1
69 1 return 'x86_64'
70 }
71 0 ▶ if( $Config{archname} =~ /x86|i686/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Build::Auto::X0::Alienfile::Config{"archname"} =~ /x86|i686/i) 0 0 0
72 0 return 'x86'
73 }
74 0 ▶ if( $Config{archname} =~ /darwin/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Build::Auto::X0::Alienfile::Config{"archname"} =~ /darwin/i) 0 0 0
75 0 my $cpu_brand = `sysctl -n machdep.cpu.brand_string`;
76 0 ▶ if( $cpu_brand =~ /Apple/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cpu_brand =~ /Apple/) { } 0 0 0
elsif ($cpu_brand =~ /Intel/) { } 0 0 0
77 0 return 'arm64'; # MacOS M1
78 } elsif( $cpu_brand =~ /Intel/ ) {
79 0 return 'x86_64'; # MacOS Intel
80 }
81 }
82 0 ▶ if( $Config{archname} =~ /aarch64/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Build::Auto::X0::Alienfile::Config{"archname"} =~ /aarch64/i) 0 0 0
83 0 return 'arm64'
84 }
85 0 ▶ if( $Config{archname} =~ /arm-linux-gnueabihf/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Build::Auto::X0::Alienfile::Config{"archname"} =~ /arm-linux-gnueabihf/i) 0 0 0
86 0 return 'armhf'; # 32-bit ARM hard float
87 }
88 }
89  
90 1 my @binary_variants = (
91 # 64-bit Windows x64
92 { os => 'MSWin32', arch => 'x86_64', filter => qr/7z(\d+)\Q-x64.msi\E/, format => '.msi', },
93 # 32-bit Windows x86
94 { os => 'MSWin32', arch => 'x86' , filter => qr/7z(\d+)\Q.msi\E/, format => '.msi', },
95 # 64-bit Linux x86-64
96 { os => 'linux' , arch => 'x86_64', filter => qr/7z(\d+)\Q-linux-x64.tar.xz\E/, format => '.tar.xz', },
97 # 32-bit Linux x86
98 { os => 'linux' , arch => 'x86' , filter => qr/7z(\d+)\Q-linux-x86.tar.xz\E/, format => '.tar.xz', },
99 # 64-bit Linux arm64
100 { os => 'linux' , arch => 'arm64' , filter => qr/7z(\d+)\Q-linux-arm64.tar.xz\E/, format => '.tar.xz', },
101 # 32-bit Linux arm
102 { os => 'linux' , arch => 'armhf' , filter => qr/7z(\d+)\Q-linux-arm.tar.xz\E/, format => '.tar.xz', },
103 # macOS (arm64 / x86-64)
104 { os => 'darwin', arch => qr/^(x86_64|arm64)$/, filter => qr/7z(\d+)\Q-mac.tar.xz\E/, format => '.tar.xz', },
105 );
106  
107 1 my ($binary_release_name_re, $binary_release_format);
108 1 ▶sub can_binary {
Subroutine can_binary: called CC=5 SCAR=16.5
109 1 my $arch = _arch_norm();
110 1 ▶ print STDERR "<os, arch> = < $^O, $arch >\n" if $arch;
Branch: 1 branch
BranchTrueFalseTotal
if $arch 1 0 1
111 1 for my $variant (@binary_variants) {
112 3 ▶ if( $^O =~ $variant->{os} && $arch =~ $variant->{arch} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /$variant->{"os"}/ and $arch =~ /$variant->{"arch"}/) 1 2 3
Condition66%2/3
$^O =~ /$variant->{"os"}/ and $arch =~ /$variant->{"arch"}/
!ll&&!rl&&r
201
MC/DC50%1/2
$^O =~ /$variant->{"os"}/ and $arch =~ /$variant->{"arch"}/
$^O =~ /$variant->{"os"}/ $arch =~ /$variant->{"arch"}/
Truth table66%2/3
A and B
A= $^O =~ /$variant->{"os"}/B= $arch =~ /$variant->{"arch"}/
ABresult
0X0
100
111
113 1 $binary_release_name_re = $variant->{filter};
114 1 $binary_release_format = $variant->{format};
115 1 return;
116 }
117 }
118  
119 0 die "No binary packages available for this configuration";
120 }
121  
122 1 ▶sub do_binary {
Subroutine do_binary: called CC=3 SCAR=20.3
123 1 plugin Download => (
124 filter => $binary_release_name_re,
125 version => qr/^7z([0-9\.]+)/,
126 );
127 1 ▶ if( $binary_release_format eq '.msi' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($binary_release_format eq '.msi') { } 0 1 1
elsif ($binary_release_format eq '.tar.xz') { } 1 0 1
128 0 ▶ extract sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 my ($build) = @_;
130  
131 0 my $msi = Path::Tiny::path($build->install_prop->{download})->canonpath;
132 0 my $cwd = Path::Tiny->cwd->canonpath;
133  
134 0 Alien::Build::CommandSequence->new([
135 qw(msiexec /a),
136 $msi,
137 "TARGETDIR=$cwd",
138 '/qn'
139 ])->execute($build);
140 0 };
141  
142 0 ▶ patch sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
143 0 my $cwd = Path::Tiny->cwd;
144 0 $_->remove for $cwd->children( qr/\.msi$/ );
145 0 my $_7zip = $cwd->child('Files/7-Zip');
146 0 $_->remove for $_7zip->children( qr/\.chm$|History\.txt|readme\.txt/ );
147 0 my $bin_dir = $cwd->child('bin');
148 0 $bin_dir->mkpath;
149 0 File::Copy::Recursive::rmove( "$_7zip/*", $bin_dir );
150 0 $_7zip->remove_tree;
151 0 ▶ $_7zip->parent->remove_tree unless $_7zip->parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $_7zip->parent->children 0 0 0
152 0 };
153 0 plugin 'Build::Copy';
154 0 ▶ after build => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
155 0 my($build) = @_;
156 0 $build->runtime_prop->{'style'} = 'binary';
157 # on MSWin32
158 0 $build->runtime_prop->{command} = '7z.exe';
159 0 };
160 } elsif( $binary_release_format eq '.tar.xz' ) {
161 1 plugin Extract => 'tar.xz';
162 0 ▶ patch sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
163 0 my $cwd = Path::Tiny->cwd;
164 # remove History.txt, readme.txt, MANUAL/
165 0 $_->remove_tree for $cwd->children( qr/MANUAL|History\.txt|readme\.txt/ );
166  
167 0 my $bin_dir = $cwd->child('bin');
168 0 $bin_dir->mkpath;
169 # Move 7zz|7zzs into bin/ (if exist)
170 0 File::Copy::Recursive::rmove( "$_", $bin_dir ) for $cwd->children( qr/^(7zz|7zzs)$/ );
171 1 };
172 1 plugin 'Build::Copy';
173 0 ▶ after build => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
174 0 my($build) = @_;
175 0 $build->runtime_prop->{'style'} = 'binary';
176 # on Unix-likes (linux, darwin)
177 0 $build->runtime_prop->{command} = '7zz';
178 1 };
179 }
180 }
181  
182 1 ▶sub _fix_share_version {
Subroutine _fix_share_version: called CC=1 SCAR=5.1
183 meta->around_hook(
184 0 ▶ prefer => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
185 0 my $orig = shift;
186 0 my $build = shift;
187 0 my $data = $orig->($build, @_);
188  
189 0 for my $item (@{ $data->{list} }) {
190 # insert a dot after the first 2 digits
191 0 $item->{version} =~ s/^(\d{2})(\d.*)$/$1.$2/;
192 }
193  
194 0 $data;
195 },
196 1 );
197 }
198  
199 1 ▶share {
Subroutine __ANON__: called CC=8 SCAR=23.2
200 1 requires 'Path::Tiny';
201 1 requires 'File::Copy::Recursive';
202 1 requires 'Alien::Build::CommandSequence';
203  
204 1 ▶ $ENV{ALIEN_7ZIP_SHARE_PREFER} ||= 'auto';
Condition50%1/2
$ENV{"ALIEN_7ZIP_SHARE_PREFER"} ||= "auto"
l!l
01
MC/DC0%0/1
$ENV{"ALIEN_7ZIP_SHARE_PREFER"} ||= "auto"
$ENV{"ALIEN_7ZIP_SHARE_PREFER"}
Truth table50%1/2
A
A= $ENV{"ALIEN_7ZIP_SHARE_PREFER"}
Aresult
11
00
205  
206 1 start_url 'https://www.7-zip.org/download.html';
207 1 _fix_share_version();
208  
209 1 my $release_types = {
210 source => {
211 'can' => \&can_source,
212 'do' => \&do_source,
213 },
214 binary => {
215 'can' => \&can_binary,
216 'do' => \&do_binary,
217 },
218 };
219  
220 1 ▶ if( $ENV{ALIEN_7ZIP_SHARE_PREFER} eq 'auto' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'ALIEN_7ZIP_SHARE_PREFER'} eq 'auto') { } 1 0 1
elsif (exists $$release_types{$ENV{'ALIEN_7ZIP_SHARE_PREFER'}}) { } 0 0 0
221 1 my $which_type;
222 1 my @types = qw(binary source);
223 1 for my $type (@types) {
224 1 eval { $release_types->{$type}{can}->() };
225 1 my $catch = $@;
226 1 ▶ if( $catch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($catch) 0 1 1
227 0 warn "Unable to install release type $type: $catch";
228 0 next;
229 }
230  
231 1 $which_type = $type;
232 1 $release_types->{$type}{do}->();
233 1 last;
234 }
235  
236 1 ▶ if( ! $which_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $which_type) 0 1 1
237 0 die "Unable to install from release types: @types";
238 }
239 } elsif( exists $release_types->{ $ENV{ALIEN_7ZIP_SHARE_PREFER} } ) {
240 0 $release_types->{ $ENV{ALIEN_7ZIP_SHARE_PREFER} }{$_}->() for qw(can do);
241 } else {
242 0 die "Unknown value for ALIEN_7ZIP_SHARE_PREFER: $ENV{ALIEN_7ZIP_SHARE_PREFER}";
243 }
244 1 };
245  
246 1 ▶sys {
Subroutine __ANON__: called CC=1 SCAR=2.6
247 0 ▶ meta->after_hook( probe => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
248 0 my($build) = @_;
249 0 $build->runtime_prop->{'style'} = 'system';
250 1 });
251 1 };
↑ Summary blib/lib/Alien/7zip.pm »