| 1 | # logic initially based on pp_simple.pl | ||||||||||||||||||||||||||||||||||
| 2 | # Should cache the Module::Scandeps result | ||||||||||||||||||||||||||||||||||
| 3 | # and then clean it up after using it. | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | package App::PP::Autolink; | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use English qw / -no_match_vars /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Which qw( which ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Capture::Tiny qw/ capture /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use List::Util 1.45 qw( uniq any first ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Find::Rule qw/ rule find /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Path::Tiny qw/ path /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | #use File::Temp qw/ tempfile /; | ||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Module::ScanDeps; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Env qw /@PATH/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Getopt::ArgvFile default=>1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Getopt::Long qw / GetOptionsFromArray :config pass_through /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 1 | our $VERSION = '2.15'; | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use constant CASE_INSENSITIVE_OS => ($^O eq 'MSWin32'); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 1 | my $RE_DLL_EXT = qr/\.$Config::Config{so}$/i; | |||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | if ($^O eq 'darwin') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | $RE_DLL_EXT = qr/\.($Config::Config{so}|bundle)$/i; | |||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 1 | my $ldd_exe = which('ldd'); | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | $self->{autolink_list_method} | ||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | = $^O eq 'MSWin32' ? 'get_autolink_list' | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 46 | : $^O eq 'darwin' ? 'get_autolink_list_macos' | ||||||||||||||||||||||||||||||||||
| 47 | : $ldd_exe ? 'get_autolink_list_ldd' | ||||||||||||||||||||||||||||||||||
| 48 | # objdump behaves differently on linux (centos at least) | ||||||||||||||||||||||||||||||||||
| 49 | : die 'Unable to generate autolink list'; | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | # slightly messy, but issues with pass_through and --no-x | ||||||||||||||||||||||||||||||||||
| 52 | 0 | $self->{no_execute_flag} = not grep {$_ eq '-x'} @args; | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | # Should trap any scandeps args (if diff from pp). | ||||||||||||||||||||||||||||||||||
| 55 | 0 | my @args_array = @args; | |||||||||||||||||||||||||||||||||
| 56 | 0 | my @argv_linkers; | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 0 | GetOptionsFromArray ( | |||||||||||||||||||||||||||||||||
| 59 | \@args_array, | ||||||||||||||||||||||||||||||||||
| 60 | "link|l=s" => \@argv_linkers, | ||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->{argv_linkers} = \@argv_linkers; | |||||||||||||||||||||||||||||||||
| 63 | 0 | $self->{args_to_pass_to_pp} = \@args_array; | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | # pp allows multiple .pl files. | ||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $script_fullname = $args[-1] or die 'no input file specified'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->{script_fullname} = $script_fullname; | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 0 | $self->{alien_sys_installs} = []; | |||||||||||||||||||||||||||||||||
| 70 | 0 | $self->{alien_deps} = []; | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub build { | ||||||||||||||||||||||||||||||||
|
Subroutine
build: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 76 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | local $ENV{PAR_PACKING} = 1 | ||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if not exists $ENV{PAR_PACKING}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | # for my own project, and since I'm the maintainer of both... | ||||||||||||||||||||||||||||||||||
| 81 | local $ENV{BDV_PP_BUILDING} = 1 | ||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if not exists $ENV{BDV_PP_BUILDING}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | # reassemble the arg list | ||||||||||||||||||||||||||||||||||
| 85 | 0 | my $argv_linkers = $self->{argv_linkers}; | |||||||||||||||||||||||||||||||||
| 86 | 0 | my $args_array = $self->{args_to_pass_to_pp}; | |||||||||||||||||||||||||||||||||
| 87 | my @args_for_pp = ( | ||||||||||||||||||||||||||||||||||
| 88 | 0 | (map {("--link" => $_)} @$argv_linkers), | |||||||||||||||||||||||||||||||||
| 89 | @$args_array, | ||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | my $method = $self->{autolink_list_method}; | |||||||||||||||||||||||||||||||||
| 93 | 0 | say 'Scanning dependent dynamic libs'; | |||||||||||||||||||||||||||||||||
| 94 | 0 | my @dll_list = $self->$method; | |||||||||||||||||||||||||||||||||
| 95 | 0 | my $alien_sys_installs = $self->{alien_sys_installs}; | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | # two-step process to get unique paths | ||||||||||||||||||||||||||||||||||
| 98 | 0 | my %tmp = map {($_ => '--link')} (@dll_list, @$alien_sys_installs); | |||||||||||||||||||||||||||||||||
| 99 | 0 | my @links = reverse %tmp; | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (@$alien_sys_installs) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 0 | say 'Alien sys dlls added: ' . join ' ', @$alien_sys_installs; | |||||||||||||||||||||||||||||||||
| 103 | 0 | say ''; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||||||
| 106 | 0 | say "No alien system dlls detected\n"; | |||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 0 | say 'Detected link list: ' . join ' ', grep {$_ ne '--link'} @links; | |||||||||||||||||||||||||||||||||
| 110 | 0 | say ''; | |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 0 | my @aliens = uniq @{$self->{alien_deps}}; | |||||||||||||||||||||||||||||||||
| 113 | 0 | my @alien_deps = map {; '-M' => $_} @aliens; | |||||||||||||||||||||||||||||||||
| 114 | 0 | say 'Detected aliens: ' . join ' ', sort @aliens; | |||||||||||||||||||||||||||||||||
| 115 | 0 | say ''; | |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 0 | my @command = ( | |||||||||||||||||||||||||||||||||
| 118 | 'pp', | ||||||||||||||||||||||||||||||||||
| 119 | @links, | ||||||||||||||||||||||||||||||||||
| 120 | #"--cachedeps=$cache_file", | ||||||||||||||||||||||||||||||||||
| 121 | @alien_deps, | ||||||||||||||||||||||||||||||||||
| 122 | @args_for_pp, | ||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 0 | say 'CMD: ' . join ' ', @command; | |||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | system (@command) == 0 | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | or die "system @command failed: $?"; | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub get_autolink_list { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_autolink_list: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 0 | my $argv_linkers = $self->{argv_linkers}; | |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $OBJDUMP = which('objdump') or die "objdump not found"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 0 | my @exe_path = @PATH; | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 0 | my @system_paths; | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($OSNAME =~ /MSWin32/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 146 | # skip anything under the C:\Windows folder, | ||||||||||||||||||||||||||||||||||
| 147 | # blank entries | ||||||||||||||||||||||||||||||||||
| 148 | # and no longer extant folders | ||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $system_root = $ENV{SystemRoot} || $ENV{WINDIR}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'SystemRoot'} || $ENV{'WINDIR'}
MC/DC0%0/2
$ENV{'SystemRoot'} || $ENV{'WINDIR'}
$ENV{'SystemRoot'}
$ENV{'WINDIR'}
Truth table0%0/3
A || B
A= $ENV{'SystemRoot'}B= $ENV{'WINDIR'}
| |||||||||||||||||||||||||||||||||||
| 150 | @system_paths | ||||||||||||||||||||||||||||||||||
| 151 | 0 | = map {path($_)->stringify} # otherwise we hit issues on SP5.36 | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | grep {$_ and $_ =~ m|^\Q$system_root\E|i} | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ && $_ =~ /^\Q$system_root\E/iu
MC/DC0%0/2
$_ && $_ =~ /^\Q$system_root\E/iu
$_
$_ =~ /^\Q$system_root\E/iu
Truth table0%0/3
A && B
A= $_B= $_ =~ /^\Q$system_root\E/iu
| |||||||||||||||||||||||||||||||||||
| 153 | @exe_path; | ||||||||||||||||||||||||||||||||||
| 154 | @exe_path | ||||||||||||||||||||||||||||||||||
| 155 | 0 | = map {path($_)->stringify} | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | grep {$_ and (-e $_) and $_ !~ m|^\Q$system_root\E|i} | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_ && -e $_ && !($_ =~ /^\Q$system_root\E/iu)
$_ and -e $_
MC/DC0%0/3
$_ && -e $_ && !($_ =~ /^\Q$system_root\E/iu)
$_
-e $_
!($_ =~ /^\Q$system_root\E/iu)
Truth table0%0/4
A and B && not(C)
A= $_B= -e $_C= !($_ =~ /^\Q$system_root\E/iu)
| |||||||||||||||||||||||||||||||||||
| 157 | @exe_path; | ||||||||||||||||||||||||||||||||||
| 158 | #say "PATHS: " . join ' ', @exe_path; | ||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | # what to skip for linux or mac? | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | # get all the DLLs in the path - saves repeated searching lower down | ||||||||||||||||||||||||||||||||||
| 163 | my @dll_files | ||||||||||||||||||||||||||||||||||
| 164 | 0 | = map {$_->stringify} | |||||||||||||||||||||||||||||||||
| 165 | 0 | map {path($_)->children ( qr /$Config::Config{so}$/)} | |||||||||||||||||||||||||||||||||
| 166 | @exe_path; | ||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 0 | if (CASE_INSENSITIVE_OS) { | |||||||||||||||||||||||||||||||||
| 169 | @dll_files = map {lc $_} @dll_files; | ||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 0 | my %dll_file_hash; | |||||||||||||||||||||||||||||||||
| 173 | 0 | foreach my $file (@dll_files) { | |||||||||||||||||||||||||||||||||
| 174 | 0 | my $basename = path($file)->basename; | |||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $dll_file_hash{$basename} //= $file; # we only want the first in the path | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$dll_file_hash{$basename} //= $file
MC/DC0%0/2
$dll_file_hash{$basename} //= $file
$dll_file_hash{$basename}
$file
Truth table0%0/3
A //= B
A= $dll_file_hash{$basename}B= $file
| |||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | # lc is dirty and underhanded | ||||||||||||||||||||||||||||||||||
| 180 | # - need to find a different approach to get | ||||||||||||||||||||||||||||||||||
| 181 | # canonical file name while handling case, | ||||||||||||||||||||||||||||||||||
| 182 | # poss Win32::GetLongPathName | ||||||||||||||||||||||||||||||||||
| 183 | 0 | say "Getting dependent DLLs"; | |||||||||||||||||||||||||||||||||
| 184 | 0 | my @dlls = @$argv_linkers; | |||||||||||||||||||||||||||||||||
| 185 | 0 | push @dlls, | |||||||||||||||||||||||||||||||||
| 186 | $self->get_dep_dlls; | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 0 | if (CASE_INSENSITIVE_OS) { | |||||||||||||||||||||||||||||||||
| 189 | @dlls = map {path ($_)->stringify} map {lc $_} @dlls; | ||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||
| 191 | #say join "\n", @dlls; | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 0 | my $re_skippers = $self->get_dll_skipper_regexp(); | |||||||||||||||||||||||||||||||||
| 194 | 0 | my %full_list; | |||||||||||||||||||||||||||||||||
| 195 | my %searched_for; | ||||||||||||||||||||||||||||||||||
| 196 | 0 | my $iter = 0; | |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 0 | my @missing; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | DLL_CHECK: | ||||||||||||||||||||||||||||||||||
| 201 | 0 | while (1) { | |||||||||||||||||||||||||||||||||
| 202 | 0 | $iter++; | |||||||||||||||||||||||||||||||||
| 203 | 0 | say "DLL check iter: $iter"; | |||||||||||||||||||||||||||||||||
| 204 | #say join ' ', @dlls; | ||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my ( $stdout, $stderr, $exit ) = capture { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 206 | 0 | system( $OBJDUMP, '-p', @dlls ); | |||||||||||||||||||||||||||||||||
| 207 | 0 | }; | |||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if( $exit ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 209 | 0 | $stderr =~ s{\s+$}{}; | |||||||||||||||||||||||||||||||||
| 210 | 0 | warn "(@dlls):$exit: $stderr "; | |||||||||||||||||||||||||||||||||
| 211 | 0 | exit; | |||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||
| 213 | 0 | @dlls = $stdout =~ /DLL.Name:\s*(\S+)/gmi; | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 0 | if (CASE_INSENSITIVE_OS) { | |||||||||||||||||||||||||||||||||
| 216 | @dlls = map {lc $_} @dlls; | ||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | # extra grep appears wasteful but useful for debug | ||||||||||||||||||||||||||||||||||
| 220 | # since we can easily disable it | ||||||||||||||||||||||||||||||||||
| 221 | @dlls | ||||||||||||||||||||||||||||||||||
| 222 | = sort | ||||||||||||||||||||||||||||||||||
| 223 | 0 | grep {!exists $full_list{$_}} | |||||||||||||||||||||||||||||||||
| 224 | 0 | grep {$_ !~ /$re_skippers/} | |||||||||||||||||||||||||||||||||
| 225 | uniq | ||||||||||||||||||||||||||||||||||
| 226 | @dlls; | ||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if (!@dlls) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 229 | 0 | say 'no more DLLs'; | |||||||||||||||||||||||||||||||||
| 230 | 0 | last DLL_CHECK; | |||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 0 | my @dll2; | |||||||||||||||||||||||||||||||||
| 234 | 0 | foreach my $file (@dlls) { | |||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | next if $searched_for{$file}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (exists $dll_file_hash{$file}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 238 | 0 | push @dll2, $dll_file_hash{$file}; | |||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||||
| 241 | 0 | push @missing, $file; | |||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | 0 | $searched_for{$file}++; | |||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||
| 246 | 0 | @dlls = uniq @dll2; | |||||||||||||||||||||||||||||||||
| 247 | 0 | my $key_count = keys %full_list; | |||||||||||||||||||||||||||||||||
| 248 | 0 | @full_list{@dlls} = (1) x @dlls; | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | # did we add anything new? | ||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | last DLL_CHECK if $key_count == scalar keys %full_list; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||
| 254 | 0 | my @l2 = sort keys %full_list; | |||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if (@missing) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 257 | 0 | my @missing2; | |||||||||||||||||||||||||||||||||
| 258 | MISSING: | ||||||||||||||||||||||||||||||||||
| 259 | 0 | foreach my $file (uniq @missing) { | |||||||||||||||||||||||||||||||||
| 260 | next MISSING | ||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if any {; -e "$_/$file"} @system_paths; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 262 | 0 | push @missing2, $file; | |||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (@missing2) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 266 | say STDERR | ||||||||||||||||||||||||||||||||||
| 267 | "\nUnable to locate these DLLS, packed script might not work: " | ||||||||||||||||||||||||||||||||||
| 268 | . join ' ', | ||||||||||||||||||||||||||||||||||
| 269 | 0 | sort {$a cmp $b} | |||||||||||||||||||||||||||||||||
| 270 | 0 | grep {$_ !~ /api-ms-win-crt-/} | |||||||||||||||||||||||||||||||||
| 271 | @missing2; | ||||||||||||||||||||||||||||||||||
| 272 | 0 | say ''; | |||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return wantarray ? @l2 : \@l2; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub _resolve_rpath_mac { | ||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_rpath_mac: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||
| 280 | 0 | my ($source, $target) = @_; | |||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | 0 | say "Resolving rpath for $source wrt $target"; | |||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||
| 284 | # clean up the target | ||||||||||||||||||||||||||||||||||
| 285 | 0 | $target =~ s|\@rpath/||; | |||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 0 | my @results = qx /otool -l $source/; | |||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | while (my $line = shift @results) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | last if $line =~ /LC_RPATH/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||
| 291 | 0 | my @lc_rpath_chunk; | |||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | while (my $line = shift @results) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | last if $line =~ /LC_/; # any other command | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 294 | 0 | push @lc_rpath_chunk, $line; | |||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||
| 296 | my @paths | ||||||||||||||||||||||||||||||||||
| 297 | 0 | = map {s/\s\(offset.+$//r} | |||||||||||||||||||||||||||||||||
| 298 | 0 | map {s/^\s+path //r} | |||||||||||||||||||||||||||||||||
| 299 | 0 | grep {/^\s+path/} | |||||||||||||||||||||||||||||||||
| 300 | @lc_rpath_chunk; | ||||||||||||||||||||||||||||||||||
| 301 | 0 | my $loader_path = path ($source)->parent->stringify; | |||||||||||||||||||||||||||||||||
| 302 | 0 | my @checked_paths; | |||||||||||||||||||||||||||||||||
| 303 | 0 | foreach my $path (@paths) { | |||||||||||||||||||||||||||||||||
| 304 | 0 | chomp $path; # should be done above | |||||||||||||||||||||||||||||||||
| 305 | 0 | $path =~ s/\@loader_path/$loader_path/; | |||||||||||||||||||||||||||||||||
| 306 | 0 | $path = path($path, $target); | |||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if ($path->exists) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 308 | 0 | $path = $path->realpath->stringify; | |||||||||||||||||||||||||||||||||
| 309 | 0 | push @checked_paths, $path; | |||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | # should handle multiple paths | ||||||||||||||||||||||||||||||||||
| 314 | 0 | return $checked_paths[0]; | |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub _resolve_loader_path_mac { | ||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_loader_path_mac: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 318 | 0 | my ($source, $target) = @_; | |||||||||||||||||||||||||||||||||
| 319 | 0 | say "Resolving loader_path for $source wrt $target"; | |||||||||||||||||||||||||||||||||
| 320 | 0 | my $source_path = path($source)->parent->stringify; | |||||||||||||||||||||||||||||||||
| 321 | 0 | $target =~ s/\@loader_path/$source_path/; | |||||||||||||||||||||||||||||||||
| 322 | 0 | return $target; | |||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub get_autolink_list_macos { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_autolink_list_macos: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 327 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | # sometimes flags creep in | ||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my @argv_linkers = grep {$_ !~ /^-/} @{$self->{argv_linkers} // []}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"argv_linkers"} // []
MC/DC0%0/1
$self->{"argv_linkers"} // []
$self->{"argv_linkers"}
Truth table0%0/2
A
A= $self->{"argv_linkers"}
| |||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | my $OTOOL = which('otool') or die "otool not found"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | 0 | my @bundle_list = $self->get_dep_dlls; | |||||||||||||||||||||||||||||||||
| 335 | 0 | my @libs_to_pack; | |||||||||||||||||||||||||||||||||
| 336 | my %seen; | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | 0 | my @target_libs = ( | |||||||||||||||||||||||||||||||||
| 339 | @argv_linkers, | ||||||||||||||||||||||||||||||||||
| 340 | @bundle_list, | ||||||||||||||||||||||||||||||||||
| 341 | #'/usr/local/opt/libffi/lib/libffi.6.dylib', | ||||||||||||||||||||||||||||||||||
| 342 | #($pixbuf_query_loader, | ||||||||||||||||||||||||||||||||||
| 343 | #find_so_files ($gdk_pixbuf_dir) ) if $pack_gdkpixbuf, | ||||||||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | while (my $lib = shift @target_libs) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | next if $lib =~ /^\s*$/; # we get some empty libs via aliens | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (!-e $lib) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 348 | 0 | warn qq{Cannot locate file "$lib"}; | |||||||||||||||||||||||||||||||||
| 349 | 0 | next; | |||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||
| 351 | 0 | say "otool -L $lib"; | |||||||||||||||||||||||||||||||||
| 352 | 0 | my @lib_arr = qx /otool -L $lib/; | |||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | warn qq["otool -L $lib" failed\n] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 354 | if not $? == 0; | ||||||||||||||||||||||||||||||||||
| 355 | 0 | shift @lib_arr; # first result is dylib we called otool on | |||||||||||||||||||||||||||||||||
| 356 | DEP_LIB: | ||||||||||||||||||||||||||||||||||
| 357 | 0 | foreach my $line (@lib_arr) { | |||||||||||||||||||||||||||||||||
| 358 | 0 | $line =~ /^\s+(.+?)\s/; | |||||||||||||||||||||||||||||||||
| 359 | 0 | my $dylib = $1; | |||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($dylib =~ /\@rpath/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 361 | 0 | my $orig_name = $dylib; | |||||||||||||||||||||||||||||||||
| 362 | 0 | $dylib = _resolve_rpath_mac($lib, $dylib); | |||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if (!defined $dylib) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 364 | 0 | say STDERR "Cannot resolve rpath for $orig_name, dependency of $lib"; | |||||||||||||||||||||||||||||||||
| 365 | 0 | next DEP_LIB; | |||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||
| 368 | elsif ($dylib =~ /\@loader_path/) { | ||||||||||||||||||||||||||||||||||
| 369 | 0 | my $orig_name = $dylib; | |||||||||||||||||||||||||||||||||
| 370 | 0 | $dylib = _resolve_loader_path_mac($lib, $dylib); | |||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | next if $seen{$dylib}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | next if $dylib =~ m{^/System}; # skip system libs | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 374 | #next if $dylib =~ m{^/usr/lib/system}; | ||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | next if $dylib =~ m{^/usr/lib/libSystem}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | next if $dylib =~ m{^/usr/lib/}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | next if $dylib =~ m{\Qdarwin-thread-multi-2level/auto/share/dist/Alien\E}; # another alien | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 378 | 0 | say "adding $dylib for $lib"; | |||||||||||||||||||||||||||||||||
| 379 | 0 | push @libs_to_pack, $dylib; | |||||||||||||||||||||||||||||||||
| 380 | 0 | $seen{$dylib}++; | |||||||||||||||||||||||||||||||||
| 381 | # add this dylib to the search set | ||||||||||||||||||||||||||||||||||
| 382 | 0 | push @target_libs, $dylib; | |||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||
| 386 | 0 | @libs_to_pack = sort @libs_to_pack; | |||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | return wantarray ? @libs_to_pack : \@libs_to_pack; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub get_autolink_list_ldd { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_autolink_list_ldd: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 392 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||
| 394 | 0 | my $argv_linkers = $self->{argv_linkers}; | |||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||
| 396 | 0 | my @bundle_list = $self->get_dep_dlls; | |||||||||||||||||||||||||||||||||
| 397 | 0 | my @libs_to_pack; | |||||||||||||||||||||||||||||||||
| 398 | my %seen; | ||||||||||||||||||||||||||||||||||
| 399 | 0 | my %seen_basename; | |||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | 0 | my $RE_skip = $self->get_ldd_skipper_regexp; | |||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 0 | my @target_libs = ( | |||||||||||||||||||||||||||||||||
| 404 | @$argv_linkers, | ||||||||||||||||||||||||||||||||||
| 405 | @bundle_list, | ||||||||||||||||||||||||||||||||||
| 406 | ); | ||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | while (my $lib = shift @target_libs) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ($lib =~ $RE_skip) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 409 | 0 | say "skipping $lib"; | |||||||||||||||||||||||||||||||||
| 410 | 0 | next; | |||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | 0 | say "ldd $lib"; | |||||||||||||||||||||||||||||||||
| 414 | 0 | my $out = qx /ldd $lib/; | |||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | warn qq["ldd $lib" failed\n] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 416 | if not $? == 0; | ||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||
| 418 | 0 | my $basename = path($lib)->basename; | |||||||||||||||||||||||||||||||||
| 419 | # say "Basename is $basename"; | ||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if ($seen_basename{$basename}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 421 | 0 | say "Double scanning of $basename via $lib - this could lead to packing issues"; | |||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||
| 423 | 0 | $seen_basename{$basename}++; | |||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||
| 426 | # much of this logic is from PAR::Packer | ||||||||||||||||||||||||||||||||||
| 427 | # https://github.com/rschupp/PAR-Packer/blob/04a133b034448adeb5444af1941a5d7947d8cafb/myldr/find_files_to_embed/ldd.pl#L47 | ||||||||||||||||||||||||||||||||||
| 428 | 0 | my %dlls = $out =~ /^ \s* (\S+) \s* => \s* ( \/ \S+ ) /gmx; | |||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||
| 430 | DLL: | ||||||||||||||||||||||||||||||||||
| 431 | 0 | foreach my $name (keys %dlls) { | |||||||||||||||||||||||||||||||||
| 432 | #say "$name, $dlls{$name}"; | ||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if ($seen{$name} or $name =~ $RE_skip) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$seen{$name} or $name =~ /$RE_skip/u
MC/DC0%0/2
$seen{$name} or $name =~ /$RE_skip/u
$seen{$name}
$name =~ /$RE_skip/u
Truth table0%0/3
A or B
A= $seen{$name}B= $name =~ /$RE_skip/u
| |||||||||||||||||||||||||||||||||||
| 434 | 0 | delete $dlls{$name}; | |||||||||||||||||||||||||||||||||
| 435 | 0 | next DLL; | |||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | 0 | $seen{$name}++; | |||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||
| 440 | 0 | my $path = path($dlls{$name})->realpath; | |||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||
| 442 | 0 | my $basename = path($dlls{$name})->basename; | |||||||||||||||||||||||||||||||||
| 443 | # say "Basename is $basename"; | ||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ($seen_basename{$basename}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 445 | 0 | say "Double scanning of $basename via $path - this could lead to packing issues"; | |||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||
| 447 | 0 | $seen_basename{$basename}++; | |||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||
| 449 | #say "Checking $name => $path"; | ||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | if (not -r $path) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 452 | 0 | warn qq[# ldd reported strange path: $path\n]; | |||||||||||||||||||||||||||||||||
| 453 | 0 | delete $dlls{$name}; | |||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||
| 455 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||
|
Condition0%0/6
$path =~ /$RE_skip/u or $path =~ m[\/auto\/share\/dist\/Alien]u or $name =~ /^lib(?:c|gcc_s|stdc\+\+)\./u
$path =~ /$RE_skip/u or $path =~ m[\/auto\/share\/dist\/Alien]u
MC/DC0%0/3
$path =~ /$RE_skip/u or $path =~ m[\/auto\/share\/dist\/Alien]u or $name =~ /^lib(?:c|gcc_s|stdc\+\+)\./u
$path =~ /$RE_skip/u
$path =~ m[\/auto\/share\/dist\/Alien]u
$name =~ /^lib(?:c|gcc_s|stdc\+\+)\./u
Truth table0%0/4
A or B or C
A= $path =~ /$RE_skip/uB= $path =~ m[\/auto\/share\/dist\/Alien]uC= $name =~ /^lib(?:c|gcc_s|stdc\+\+)\./u
| |||||||||||||||||||||||||||||||||||
| 456 | #$path =~ m{^(?:/usr)?/lib(?:32|64)?/} # system lib | ||||||||||||||||||||||||||||||||||
| 457 | $path =~ $RE_skip | ||||||||||||||||||||||||||||||||||
| 458 | or $path =~ m{\Q/auto/share/dist/Alien\E} # alien in share | ||||||||||||||||||||||||||||||||||
| 459 | or $name =~ m{^lib(?:c|gcc_s|stdc\+\+)\.} # should already be packed? | ||||||||||||||||||||||||||||||||||
| 460 | ) { | ||||||||||||||||||||||||||||||||||
| 461 | #say "skipping $name => $path"; | ||||||||||||||||||||||||||||||||||
| 462 | #warn "re1" if $path =~ m{^(?:/usr)?/lib(?:32|64)/}; | ||||||||||||||||||||||||||||||||||
| 463 | #warn "re2" if $path =~ m{\Q/auto/share/dist/Alien\E}; | ||||||||||||||||||||||||||||||||||
| 464 | #warn "re3" if $name =~ m{^lib(?:gcc_s|stdc\+\+)\.}; | ||||||||||||||||||||||||||||||||||
| 465 | 0 | delete $dlls{$name}; | |||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||
| 468 | 0 | push @target_libs, sort values %dlls; | |||||||||||||||||||||||||||||||||
| 469 | 0 | push @libs_to_pack, sort values %dlls; | |||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | 0 | @libs_to_pack = sort @libs_to_pack; | |||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||
| 474 | # # convoluted... | ||||||||||||||||||||||||||||||||||
| 475 | # my %basename_count; | ||||||||||||||||||||||||||||||||||
| 476 | # $basename_count{$_}++ for map {path($_)->basename} @libs_to_pack; | ||||||||||||||||||||||||||||||||||
| 477 | # my @toomany = grep {$basename_count{$_} > 1} sort keys %basename_count; | ||||||||||||||||||||||||||||||||||
| 478 | # say '=====' . join ' ', @toomany; | ||||||||||||||||||||||||||||||||||
| 479 | # if (@toomany) { | ||||||||||||||||||||||||||||||||||
| 480 | # warn "The following libs are referenced several times from different paths. " | ||||||||||||||||||||||||||||||||||
| 481 | # . "There may be issues with the packed executable unless they have the same ABI"; | ||||||||||||||||||||||||||||||||||
| 482 | # warn join ' ', @toomany; | ||||||||||||||||||||||||||||||||||
| 483 | # my %dups; | ||||||||||||||||||||||||||||||||||
| 484 | # foreach my $dup (@libs_to_pack) { | ||||||||||||||||||||||||||||||||||
| 485 | # my $basename = path ($dup)->basename; | ||||||||||||||||||||||||||||||||||
| 486 | # next if $basename_count{$dup} < 2; | ||||||||||||||||||||||||||||||||||
| 487 | # my $aref = $dups{$basename} //= []; | ||||||||||||||||||||||||||||||||||
| 488 | # push @$aref, $dup; | ||||||||||||||||||||||||||||||||||
| 489 | # } | ||||||||||||||||||||||||||||||||||
| 490 | # foreach my $aref (values %dups) { | ||||||||||||||||||||||||||||||||||
| 491 | # warn join ' ', @$aref; | ||||||||||||||||||||||||||||||||||
| 492 | # } | ||||||||||||||||||||||||||||||||||
| 493 | # } | ||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return wantarray ? @libs_to_pack : \@libs_to_pack; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||
| 500 | # needed for gdkpixbuf, when we support it | ||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | sub find_so_files { | ||||||||||||||||||||||||||||||||
|
Subroutine
find_so_files: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 502 | 0 | my ($self, $target_dir) = @_; | |||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | return if !defined $target_dir; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||
| 505 | 0 | my @files = File::Find::Rule->extras({ follow => 1, follow_skip=>2 }) | |||||||||||||||||||||||||||||||||
| 506 | ->file() | ||||||||||||||||||||||||||||||||||
| 507 | ->name( qr/\.so$/ ) | ||||||||||||||||||||||||||||||||||
| 508 | ->in( $target_dir ); | ||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | return wantarray ? @files : \@files; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub get_ldd_skipper_regexp { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_ldd_skipper_regexp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 513 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 514 | 0 | my @skip = qw /libm libc libpthread libdl/; | |||||||||||||||||||||||||||||||||
| 515 | 0 | my $sk = join '|', @skip; | |||||||||||||||||||||||||||||||||
| 516 | 0 | my $qr_skip = qr {\b(?:$sk)\.$Config::Config{so}}; | |||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||
| 518 | 0 | return $qr_skip; | |||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | sub get_dll_skipper_regexp { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_dll_skipper_regexp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 522 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||
| 524 | # PAR packs these automatically these days. | ||||||||||||||||||||||||||||||||||
| 525 | 0 | my @skip = qw / | |||||||||||||||||||||||||||||||||
| 526 | perl5\d\d | ||||||||||||||||||||||||||||||||||
| 527 | libstdc\+\+\-6 | ||||||||||||||||||||||||||||||||||
| 528 | libgcc_s_seh\-1 | ||||||||||||||||||||||||||||||||||
| 529 | libwinpthread\-1 | ||||||||||||||||||||||||||||||||||
| 530 | libgcc_s_sjlj\-1 | ||||||||||||||||||||||||||||||||||
| 531 | /; | ||||||||||||||||||||||||||||||||||
| 532 | 0 | my $sk = join '|', @skip; | |||||||||||||||||||||||||||||||||
| 533 | 0 | my $qr_skip = qr /^(?:$sk)$RE_DLL_EXT$/; | |||||||||||||||||||||||||||||||||
| 534 | 0 | return $qr_skip; | |||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||
| 537 | # find dependent dlls | ||||||||||||||||||||||||||||||||||
| 538 | # could also adapt some of Module::ScanDeps::_compile_or_execute | ||||||||||||||||||||||||||||||||||
| 539 | # as it handles more edge cases | ||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | sub get_dep_dlls { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_dep_dlls: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 541 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||
| 543 | 0 | my $script = $self->{script_fullname}; | |||||||||||||||||||||||||||||||||
| 544 | 0 | my $no_execute_flag = $self->{no_execute_flag}; | |||||||||||||||||||||||||||||||||
| 545 | 0 | my $alien_sys_installs = $self->{alien_sys_installs}; | |||||||||||||||||||||||||||||||||
| 546 | # my $cache_file = $self->{cache_file}; | ||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||
| 548 | 0 | my $deps_hash = scan_deps( | |||||||||||||||||||||||||||||||||
| 549 | files => [ $script ], | ||||||||||||||||||||||||||||||||||
| 550 | recurse => 1, | ||||||||||||||||||||||||||||||||||
| 551 | execute => !$no_execute_flag, | ||||||||||||||||||||||||||||||||||
| 552 | # cache_file => $cache_file, | ||||||||||||||||||||||||||||||||||
| 553 | ); | ||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||
| 555 | #my @lib_paths | ||||||||||||||||||||||||||||||||||
| 556 | # = map {path($_)->absolute} | ||||||||||||||||||||||||||||||||||
| 557 | # grep {defined} # needed? | ||||||||||||||||||||||||||||||||||
| 558 | # @Config{qw /installsitearch installvendorarch installarchlib/}; | ||||||||||||||||||||||||||||||||||
| 559 | #say join ' ', @lib_paths; | ||||||||||||||||||||||||||||||||||
| 560 | my @lib_paths | ||||||||||||||||||||||||||||||||||
| 561 | 0 | = reverse sort {length $a <=> length $b} | |||||||||||||||||||||||||||||||||
| 562 | 0 | map {path($_)->absolute} | |||||||||||||||||||||||||||||||||
| 563 | @INC; | ||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||
| 565 | 0 | my $paths = join '|', map {quotemeta} map {path($_)->stringify} @lib_paths; | |||||||||||||||||||||||||||||||||
| 566 | 0 | my $inc_path_re = qr /^($paths)/i; | |||||||||||||||||||||||||||||||||
| 567 | #say $inc_path_re; | ||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||
| 569 | #say "DEPS HASH:" . join "\n", keys %$deps_hash; | ||||||||||||||||||||||||||||||||||
| 570 | 0 | my %dll_hash; | |||||||||||||||||||||||||||||||||
| 571 | my @aliens; | ||||||||||||||||||||||||||||||||||
| 572 | 0 | foreach my $package (keys %$deps_hash) { | |||||||||||||||||||||||||||||||||
| 573 | 0 | my $details = $deps_hash->{$package}; | |||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | my @uses = @{$details->{uses} // []}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$details->{"uses"} // []
MC/DC0%0/1
$details->{"uses"} // []
$details->{"uses"}
Truth table0%0/2
A
A= $details->{"uses"}
| |||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | if ($details->{key} =~ m{^Alien/.+\.pm$}) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 576 | 0 | push @aliens, $package; | |||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||
| 578 | elsif ($details->{key} =~ m{^Gtk}) { | ||||||||||||||||||||||||||||||||||
| 579 | # we need to check the pixbuf loaders | ||||||||||||||||||||||||||||||||||
| 580 | 0 | my @pixbuf_loaders = $self->process_gdk_pixbuf_loaders; | |||||||||||||||||||||||||||||||||
| 581 | 0 | push @uses, @pixbuf_loaders; | |||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||
| 584 | push @uses, $package | ||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | if $details->{file} =~ $RE_DLL_EXT; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | next if !@uses; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||
| 589 | 0 | foreach my $dll (grep {$_ =~ $RE_DLL_EXT} @uses) { | |||||||||||||||||||||||||||||||||
| 590 | 0 | my $dll_path = $dll; | |||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | if (!path($dll_path)->is_absolute) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if (my $pfx = List::Util::first {path($_, $dll)->exists} @INC) { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 593 | 0 | $dll_path = path($pfx, $dll); | |||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||
| 596 | # We were getting double paths under SP 5.36. | ||||||||||||||||||||||||||||||||||
| 597 | # It should be fixed now but leave here just in case. | ||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if ($dll =~ /^\w:.+:/){ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 599 | 0 | warn "Fixing double dir path: $dll_path}"; | |||||||||||||||||||||||||||||||||
| 600 | 0 | $dll_path =~ s/^.+(.):/$1:/; | |||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | croak "either cannot find or cannot read $dll " | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 603 | . "for package $package" | ||||||||||||||||||||||||||||||||||
| 604 | if not -r $dll_path; | ||||||||||||||||||||||||||||||||||
| 605 | 0 | $dll_hash{$dll_path}++; | |||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||
| 608 | # handle aliens | ||||||||||||||||||||||||||||||||||
| 609 | ALIEN: | ||||||||||||||||||||||||||||||||||
| 610 | 0 | foreach my $package (@aliens) { | |||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | next if $package =~ m{^Alien/(Base|Build)}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 612 | 0 | my $package_inc_name = $package; | |||||||||||||||||||||||||||||||||
| 613 | 0 | $package =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||
| 614 | 0 | $package =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | if (!$INC{$package_inc_name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 616 | # if the execute flag was off then try to load the package | ||||||||||||||||||||||||||||||||||
| 617 | 0 | eval "require $package"; | |||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 619 | 0 | say "Unable to require $package, skipping (error is $@)"; | |||||||||||||||||||||||||||||||||
| 620 | 0 | next ALIEN; | |||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||
| 623 | # some older aliens might do different things | ||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | next ALIEN if !$package->isa ('Alien::Base'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 625 | 0 | say "Finding dynamic libs for $package"; | |||||||||||||||||||||||||||||||||
| 626 | 0 | foreach my $path ($package->dynamic_libs) { | |||||||||||||||||||||||||||||||||
| 627 | # warn $path; | ||||||||||||||||||||||||||||||||||
| 628 | 0 | $dll_hash{$path}++; | |||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if ($package->install_type eq 'system') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 631 | 0 | push @$alien_sys_installs, $package->dynamic_libs; | |||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||
| 633 | 0 | push @{$self->{alien_deps}}, $package; | |||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||
| 636 | 0 | my @dll_list = sort keys %dll_hash; | |||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | return wantarray ? @dll_list : \@dll_list; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | sub process_gdk_pixbuf_loaders { | ||||||||||||||||||||||||||||||||
|
Subroutine
process_gdk_pixbuf_loaders: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 641 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||
| 643 | 0 | say 'Scanning gdk-pixbuf-query-loaders result'; | |||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||
| 645 | 0 | my $ql = which 'gdk-pixbuf-query-loaders'; | |||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | return if !$ql; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||
| 649 | 0 | my $pixbuf_parent_path = path ($ql)->parent->parent; | |||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||
| 651 | my @res = | ||||||||||||||||||||||||||||||||||
| 652 | 0 | map {path $_} | |||||||||||||||||||||||||||||||||
| 653 | 0 | grep {$_ =~ /$RE_DLL_EXT$/} | |||||||||||||||||||||||||||||||||
| 654 | 0 | grep {$_ !~ /#/} | |||||||||||||||||||||||||||||||||
| 655 | 0 | map {s/"//gr} | |||||||||||||||||||||||||||||||||
| 656 | 0 | map {s/\s*//gr} | |||||||||||||||||||||||||||||||||
| 657 | qx /gdk-pixbuf-query-loaders/; | ||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||
| 659 | 0 | foreach my $path (@res) { | |||||||||||||||||||||||||||||||||
| 660 | # are we relative to pixbuf-loader? | ||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | if (!$path->is_absolute) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 662 | 0 | $path = path ($pixbuf_parent_path, $path); | |||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||
| 665 | 0 | return @res; | |||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||
| 668 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||
| 670 | __END__ | ||||||||||||||||||||||||||||||||||