| 1 | package Module::Build::Platform::Windows; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 57 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 57 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 57 | our $VERSION = '0.4234'; | |||||||||||||||||||||||||||
| 6 | 57 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 57 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 57 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 57 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 57 | ▶ | use Module::Build::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 57 | our @ISA = qw(Module::Build::Base); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub manpage_separator { | ||||||||||||||||||||||||||
|
Subroutine
manpage_separator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | return '.'; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub have_forkpipe { 0 } | ||||||||||||||||||||||||||
|
Subroutine
have_forkpipe: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub _detildefy { | ||||||||||||||||||||||||||
|
Subroutine
_detildefy: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 25 | $value =~ s,^~(?= [/\\] | $ ),$ENV{HOME},x | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if $ENV{HOME}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | return $value; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub ACTION_realclean { | ||||||||||||||||||||||||||
|
Subroutine
ACTION_realclean: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | $self->SUPER::ACTION_realclean(); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $basename = basename($0); | |||||||||||||||||||||||||||
| 36 | 0 | $basename =~ s/(?:\.bat)?$//i; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( lc $basename eq lc $self->build_script ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $self->build_bat ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $self->log_verbose("Deleting $basename.bat\n"); | |||||||||||||||||||||||||||
| 41 | 0 | my $full_progname = $0; | |||||||||||||||||||||||||||
| 42 | 0 | $full_progname =~ s/(?:\.bat)?$/.bat/i; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Voodoo required to have a batch file delete itself without error; | ||||||||||||||||||||||||||||
| 45 | # Syntax differs between 9x & NT: the later requires a null arg (???) | ||||||||||||||||||||||||||||
| 46 | 0 | require Win32; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $null_arg = (Win32::IsWinNT()) ? '""' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | my $cmd = qq(start $null_arg /min "\%comspec\%" /c del "$full_progname"); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | open(my $fh, '>>', "$basename.bat") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | or die "Can't create $basename.bat: $!"; | ||||||||||||||||||||||||||||
| 52 | 0 | print $fh $cmd; | |||||||||||||||||||||||||||
| 53 | 0 | close $fh ; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 0 | $self->delete_filetree($self->build_script . '.bat'); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub make_executable { | ||||||||||||||||||||||||||
|
Subroutine
make_executable: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | $self->SUPER::make_executable(@_); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | foreach my $script (@_) { | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Native batch script | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $script =~ /\.(bat|cmd)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $self->SUPER::make_executable($script); | |||||||||||||||||||||||||||
| 70 | 0 | next; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Perl script that needs to be wrapped in a batch script | ||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 0 | my %opts = (); | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $script eq $self->build_script ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $opts{ntargs} = q(-x -S %0 --build_bat %*); | |||||||||||||||||||||||||||
| 77 | 0 | $opts{otherargs} = q(-x -S "%0" --build_bat %1 %2 %3 %4 %5 %6 %7 %8 %9); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $out = eval {$self->pl2bat(in => $script, update => 1, %opts)}; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $self->log_warn("WARNING: Unable to convert file '$script' to an executable script:\n$@"); | |||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||
| 84 | 0 | $self->SUPER::make_executable($out); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub pl2bat { | ||||||||||||||||||||||||||
|
Subroutine
pl2bat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | 0 | my %opts = @_; | |||||||||||||||||||||||||||
| 93 | 0 | require ExtUtils::PL2Bat; | |||||||||||||||||||||||||||
| 94 | 0 | return ExtUtils::PL2Bat::pl2bat(%opts); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub _quote_args { | ||||||||||||||||||||||||||
|
Subroutine
_quote_args: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 99 | # Returns a string that can become [part of] a command line with | ||||||||||||||||||||||||||||
| 100 | # proper quoting so that the subprocess sees this same list of args. | ||||||||||||||||||||||||||||
| 101 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my @quoted; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | for (@args) { | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( /^[^\s*?!\$<>;|'"\[\]\{\}]+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | # Looks pretty safe | ||||||||||||||||||||||||||||
| 108 | 0 | push @quoted, $_; | |||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||
| 110 | # XXX this will obviously have to improve - is there already a | ||||||||||||||||||||||||||||
| 111 | # core module lying around that does proper quoting? | ||||||||||||||||||||||||||||
| 112 | 0 | s/"/\\"/g; | |||||||||||||||||||||||||||
| 113 | 0 | push @quoted, qq("$_"); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return join " ", @quoted; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2850 | ▶ | sub split_like_shell { | ||||||||||||||||||||||||||
|
Subroutine
split_like_shell: called CC=16 SCAR=27.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | # As it turns out, Windows command-parsing is very different from | ||||||||||||||||||||||||||||
| 123 | # Unix command-parsing. Double-quotes mean different things, | ||||||||||||||||||||||||||||
| 124 | # backslashes don't necessarily mean escapes, and so on. So we | ||||||||||||||||||||||||||||
| 125 | # can't use Text::ParseWords::shellwords() to break a command string | ||||||||||||||||||||||||||||
| 126 | # into words. The algorithm below was bashed out by Randy and Ken | ||||||||||||||||||||||||||||
| 127 | # (mostly Randy), and there are a lot of regression tests, so we | ||||||||||||||||||||||||||||
| 128 | # should feel free to adjust if desired. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2850 | (my $self, local $_) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2850 | ▶ | return @$_ if defined() && ref() eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_ and ref $_ eq "ARRAY"
MC/DC50%1/2
defined $_ and ref $_ eq "ARRAY"
defined $_
ref $_ eq "ARRAY"
Truth table66%2/3
A and B
A= defined $_B= ref $_ eq "ARRAY"
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2793 | my @argv; | |||||||||||||||||||||||||||
| 135 | 2793 | ▶ | return @argv unless defined() && length(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_ and length $_
MC/DC50%1/2
defined $_ and length $_
defined $_
length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2736 | my $length = length; | |||||||||||||||||||||||||||
| 138 | 2736 | m/\G\s*/gc; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 2736 | ▶ | ARGS: until ( pos == $length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 3762 | my $quote_mode; | |||||||||||||||||||||||||||
| 142 | 3762 | my $arg = ''; | |||||||||||||||||||||||||||
| 143 | 3762 | ▶ | CHARS: until ( pos == $length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 16758 | ▶ | if ( m/\G((?:\\\\)+)(?=\\?(")?)/gc ) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 145 | 570 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 399 | $arg .= '\\' x (length($1) / 2); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||
| 149 | 171 | $arg .= $1; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | elsif ( m/\G\\"/gc ) { | ||||||||||||||||||||||||||||
| 153 | 912 | $arg .= '"'; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | elsif ( m/\G"/gc ) { | ||||||||||||||||||||||||||||
| 156 | 7239 | ▶ | if ( $quote_mode && m/\G"/gc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$quote_mode and /\G"/cg
MC/DC100%2/2
$quote_mode and /\G"/cg
$quote_mode
/\G"/cg
Truth table100%3/3
A and B
A= $quote_modeB= /\G"/cg
| |||||||||||||||||||||||||||||
| 157 | 798 | $arg .= '"'; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | 7239 | $quote_mode = !$quote_mode; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | ▶ | elsif ( !$quote_mode && m/\G\s+/gc ) { | |||||||||||||||||||||||||||
|
Condition100%3/3
not $quote_mode and /\G\s+/cg
MC/DC100%2/2
not $quote_mode and /\G\s+/cg
not $quote_mode
/\G\s+/cg
Truth table100%3/3
not(A) and B
A= not $quote_modeB= /\G\s+/cg
| |||||||||||||||||||||||||||||
| 162 | 1083 | last; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | elsif ( m/\G(.)/sgc ) { | ||||||||||||||||||||||||||||
| 165 | 6954 | $arg .= $1; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 3762 | push @argv, $arg; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 2736 | return @argv; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # system(@cmd) does not like having double-quotes in it on Windows. | ||||||||||||||||||||||||||||
| 176 | # So we quote them and run it as a single command. | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub do_system { | ||||||||||||||||||||||||||
|
Subroutine
do_system: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($self, @cmd) = @_; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my $cmd = $self->_quote_args(@cmd); | |||||||||||||||||||||||||||
| 181 | 0 | my $status = system($cmd); | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($status and $! =~ /Argument list too long/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$status and $! =~ /Argument list too long/i
MC/DC0%0/2
$status and $! =~ /Argument list too long/i
$status
$! =~ /Argument list too long/i
Truth table0%0/3
A and B
A= $statusB= $! =~ /Argument list too long/i
| |||||||||||||||||||||||||||||
| 183 | 0 | my $env_entries = ''; | |||||||||||||||||||||||||||
| 184 | 0 | foreach (sort keys %ENV) { $env_entries .= "$_=>".length($ENV{$_})."; " } | |||||||||||||||||||||||||||
| 185 | 0 | warn "'Argument list' was 'too long', env lengths are $env_entries"; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 0 | return !$status; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # Copied from ExtUtils::MM_Win32 | ||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub _maybe_command { | ||||||||||||||||||||||||||
|
Subroutine
_maybe_command: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 192 | 0 | my($self,$file) = @_; | |||||||||||||||||||||||||||
| 193 | my @e = exists($ENV{'PATHEXT'}) | ||||||||||||||||||||||||||||
| 194 | ? split(/;/, $ENV{PATHEXT}) | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | : qw(.com .exe .bat .cmd); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | my $e = ''; | |||||||||||||||||||||||||||
| 197 | 0 | for (@e) { $e .= "\Q$_\E|" } | |||||||||||||||||||||||||||
| 198 | 0 | chop $e; | |||||||||||||||||||||||||||
| 199 | # see if file ends in one of the known extensions | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($file =~ /($e)$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return $file if -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||
| 204 | 0 | for (@e) { | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | return "$file$_" if -e "$file$_"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 0 | return; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 57 | 1; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | __END__ | ||||||||||||||||||||||||||||