| 1 | package ExtUtils::Install; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | use vars qw(@ISA @EXPORT $VERSION $MUST_REBOOT %Config); | ||
| 5 | |||
| 6 | use AutoSplit; | ||
| 7 | use Carp (); | ||
| 8 | use Config qw(%Config); | ||
| 9 | use Cwd qw(cwd); | ||
| 10 | use Exporter; | ||
| 11 | use ExtUtils::Packlist; | ||
| 12 | use File::Basename qw(dirname); | ||
| 13 | use File::Compare qw(compare); | ||
| 14 | use File::Copy; | ||
| 15 | use File::Find qw(find); | ||
| 16 | use File::Path; | ||
| 17 | use File::Spec; | ||
| 18 | |||
| 19 | |||
| 20 | @ISA = ('Exporter'); | ||
| 21 | @EXPORT = ('install','uninstall','pm_to_blib', 'install_default'); | ||
| 22 | |||
| 23 | =pod | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | ExtUtils::Install - install files from here to there | ||
| 28 | |||
| 29 | =head1 SYNOPSIS | ||
| 30 | |||
| 31 | use ExtUtils::Install; | ||
| 32 | |||
| 33 | install({ 'blib/lib' => 'some/install/dir' } ); | ||
| 34 | |||
| 35 | uninstall($packlist); | ||
| 36 | |||
| 37 | pm_to_blib({ 'lib/Foo/Bar.pm' => 'blib/lib/Foo/Bar.pm' }); | ||
| 38 | |||
| 39 | =head1 VERSION | ||
| 40 | |||
| 41 | 1.50 | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | $VERSION = '1.50'; | ||
| 46 | $VERSION = eval $VERSION; | ||
| 47 | |||
| 48 | =pod | ||
| 49 | |||
| 50 | =head1 DESCRIPTION | ||
| 51 | |||
| 52 | Handles the installing and uninstalling of perl modules, scripts, man | ||
| 53 | pages, etc... | ||
| 54 | |||
| 55 | Both install() and uninstall() are specific to the way | ||
| 56 | ExtUtils::MakeMaker handles the installation and deinstallation of | ||
| 57 | perl modules. They are not designed as general purpose tools. | ||
| 58 | |||
| 59 | On some operating systems such as Win32 installation may not be possible | ||
| 60 | until after a reboot has occured. This can have varying consequences: | ||
| 61 | removing an old DLL does not impact programs using the new one, but if | ||
| 62 | a new DLL cannot be installed properly until reboot then anything | ||
| 63 | depending on it must wait. The package variable | ||
| 64 | |||
| 65 | $ExtUtils::Install::MUST_REBOOT | ||
| 66 | |||
| 67 | is used to store this status. | ||
| 68 | |||
| 69 | If this variable is true then such an operation has occured and | ||
| 70 | anything depending on this module cannot proceed until a reboot | ||
| 71 | has occured. | ||
| 72 | |||
| 73 | If this value is defined but false then such an operation has | ||
| 74 | ocurred, but should not impact later operations. | ||
| 75 | |||
| 76 | =begin _private | ||
| 77 | |||
| 78 | =item _chmod($$;$) | ||
| 79 | |||
| 80 | Wrapper to chmod() for debugging and error trapping. | ||
| 81 | |||
| 82 | =item _warnonce(@) | ||
| 83 | |||
| 84 | Warns about something only once. | ||
| 85 | |||
| 86 | =item _choke(@) | ||
| 87 | |||
| 88 | Dies with a special message. | ||
| 89 | |||
| 90 | =end _private | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | my $Is_VMS = $^O eq 'VMS'; | ||
| 95 | my $Is_MacPerl = $^O eq 'MacOS'; | ||
| 96 | my $Is_Win32 = $^O eq 'MSWin32'; | ||
| 97 | my $Is_cygwin = $^O eq 'cygwin'; | ||
| 98 | my $CanMoveAtBoot = ($Is_Win32 || $Is_cygwin); | ||
| 99 | |||
| 100 | # *note* CanMoveAtBoot is only incidentally the same condition as below | ||
| 101 | # this needs not hold true in the future. | ||
| 102 | my $Has_Win32API_File = ($Is_Win32 || $Is_cygwin) | ||
| 103 | ? (eval {require Win32API::File; 1} || 0) | ||
| 104 | : 0; | ||
| 105 | |||
| 106 | |||
| 107 | my $Inc_uninstall_warn_handler; | ||
| 108 | |||
| 109 | # install relative to here | ||
| 110 | |||
| 111 | my $INSTALL_ROOT = $ENV{PERL_INSTALL_ROOT}; | ||
| 112 | |||
| 113 | my $Curdir = File::Spec->curdir; | ||
| 114 | my $Updir = File::Spec->updir; | ||
| 115 | |||
| 116 | sub _estr(@) { | ||
| 117 | return join "\n",'!' x 72,@_,'!' x 72,''; | ||
| 118 | } | ||
| 119 | |||
| 120 | {my %warned; | ||
| 121 | sub _warnonce(@) { | ||
| 122 | my $first=shift; | ||
| 123 | my $msg=_estr "WARNING: $first",@_; | ||
| 124 | warn $msg unless $warned{$msg}++; | ||
| 125 | }} | ||
| 126 | |||
| 127 | sub _choke(@) { | ||
| 128 | my $first=shift; | ||
| 129 | my $msg=_estr "ERROR: $first",@_; | ||
| 130 | Carp::croak($msg); | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | sub _chmod($$;$) { | ||
| 135 | my ( $mode, $item, $verbose )=@_; | ||
| 136 | $verbose ||= 0; | ||
| 137 | if (chmod $mode, $item) { | ||
| 138 | print "chmod($mode, $item)\n" if $verbose > 1; | ||
| 139 | } else { | ||
| 140 | my $err="$!"; | ||
| 141 | _warnonce "WARNING: Failed chmod($mode, $item): $err\n" | ||
| 142 | if -e $item; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | =begin _private | ||
| 147 | |||
| 148 | =item _move_file_at_boot( $file, $target, $moan ) | ||
| 149 | |||
| 150 | OS-Specific, Win32/Cygwin | ||
| 151 | |||
| 152 | Schedules a file to be moved/renamed/deleted at next boot. | ||
| 153 | $file should be a filespec of an existing file | ||
| 154 | $target should be a ref to an array if the file is to be deleted | ||
| 155 | otherwise it should be a filespec for a rename. If the file is existing | ||
| 156 | it will be replaced. | ||
| 157 | |||
| 158 | Sets $MUST_REBOOT to 0 to indicate a deletion operation has occured | ||
| 159 | and sets it to 1 to indicate that a move operation has been requested. | ||
| 160 | |||
| 161 | returns 1 on success, on failure if $moan is false errors are fatal. | ||
| 162 | If $moan is true then returns 0 on error and warns instead of dies. | ||
| 163 | |||
| 164 | =end _private | ||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | sub _move_file_at_boot { #XXX OS-SPECIFIC | ||
| 171 | my ( $file, $target, $moan )= @_; | ||
| 172 | Carp::confess("Panic: Can't _move_file_at_boot on this platform!") | ||
| 173 | unless $CanMoveAtBoot; | ||
| 174 | |||
| 175 | my $descr= ref $target | ||
| 176 | ? "'$file' for deletion" | ||
| 177 | : "'$file' for installation as '$target'"; | ||
| 178 | |||
| 179 | if ( ! $Has_Win32API_File ) { | ||
| 180 | |||
| 181 | my @msg=( | ||
| 182 | "Cannot schedule $descr at reboot.", | ||
| 183 | "Try installing Win32API::File to allow operations on locked files", | ||
| 184 | "to be scheduled during reboot. Or try to perform the operation by", | ||
| 185 | "hand yourself. (You may need to close other perl processes first)" | ||
| 186 | ); | ||
| 187 | if ( $moan ) { _warnonce(@msg) } else { _choke(@msg) } | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | my $opts= Win32API::File::MOVEFILE_DELAY_UNTIL_REBOOT(); | ||
| 191 | $opts= $opts | Win32API::File::MOVEFILE_REPLACE_EXISTING() | ||
| 192 | unless ref $target; | ||
| 193 | |||
| 194 | _chmod( 0666, $file ); | ||
| 195 | _chmod( 0666, $target ) unless ref $target; | ||
| 196 | |||
| 197 | if (Win32API::File::MoveFileEx( $file, $target, $opts )) { | ||
| 198 | $MUST_REBOOT ||= ref $target ? 0 : 1; | ||
| 199 | return 1; | ||
| 200 | } else { | ||
| 201 | my @msg=( | ||
| 202 | "MoveFileEx $descr at reboot failed: $^E", | ||
| 203 | "You may try to perform the operation by hand yourself. ", | ||
| 204 | "(You may need to close other perl processes first).", | ||
| 205 | ); | ||
| 206 | if ( $moan ) { _warnonce(@msg) } else { _choke(@msg) } | ||
| 207 | } | ||
| 208 | return 0; | ||
| 209 | } | ||
| 210 | |||
| 211 | |||
| 212 | =begin _private | ||
| 213 | |||
| 214 | =item _unlink_or_rename( $file, $tryhard, $installing ) | ||
| 215 | |||
| 216 | OS-Specific, Win32/Cygwin | ||
| 217 | |||
| 218 | Tries to get a file out of the way by unlinking it or renaming it. On | ||
| 219 | some OS'es (Win32 based) DLL files can end up locked such that they can | ||
| 220 | be renamed but not deleted. Likewise sometimes a file can be locked such | ||
| 221 | that it cant even be renamed or changed except at reboot. To handle | ||
| 222 | these cases this routine finds a tempfile name that it can either rename | ||
| 223 | the file out of the way or use as a proxy for the install so that the | ||
| 224 | rename can happen later (at reboot). | ||
| 225 | |||
| 226 | $file : the file to remove. | ||
| 227 | $tryhard : should advanced tricks be used for deletion | ||
| 228 | $installing : we are not merely deleting but we want to overwrite | ||
| 229 | |||
| 230 | When $tryhard is not true if the unlink fails its fatal. When $tryhard | ||
| 231 | is true then the file is attempted to be renamed. The renamed file is | ||
| 232 | then scheduled for deletion. If the rename fails then $installing | ||
| 233 | governs what happens. If it is false the failure is fatal. If it is true | ||
| 234 | then an attempt is made to schedule installation at boot using a | ||
| 235 | temporary file to hold the new file. If this fails then a fatal error is | ||
| 236 | thrown, if it succeeds it returns the temporary file name (which will be | ||
| 237 | a derivative of the original in the same directory) so that the caller can | ||
| 238 | use it to install under. In all other cases of success returns $file. | ||
| 239 | On failure throws a fatal error. | ||
| 240 | |||
| 241 | =end _private | ||
| 242 | |||
| 243 | =cut | ||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | sub _unlink_or_rename { #XXX OS-SPECIFIC | ||
| 248 | my ( $file, $tryhard, $installing )= @_; | ||
| 249 | |||
| 250 | _chmod( 0666, $file ); | ||
| 251 | unlink $file | ||
| 252 | and return $file; | ||
| 253 | my $error="$!"; | ||
| 254 | |||
| 255 | _choke("Cannot unlink '$file': $!") | ||
| 256 | unless $CanMoveAtBoot && $tryhard; | ||
| 257 | |||
| 258 | my $tmp= "AAA"; | ||
| 259 | ++$tmp while -e "$file.$tmp"; | ||
| 260 | $tmp= "$file.$tmp"; | ||
| 261 | |||
| 262 | warn "WARNING: Unable to unlink '$file': $error\n", | ||
| 263 | "Going to try to rename it to '$tmp'.\n"; | ||
| 264 | |||
| 265 | if ( rename $file, $tmp ) { | ||
| 266 | warn "Rename succesful. Scheduling '$tmp'\nfor deletion at reboot.\n"; | ||
| 267 | # when $installing we can set $moan to true. | ||
| 268 | # IOW, if we cant delete the renamed file at reboot its | ||
| 269 | # not the end of the world. The other cases are more serious | ||
| 270 | # and need to be fatal. | ||
| 271 | _move_file_at_boot( $tmp, [], $installing ); | ||
| 272 | return $file; | ||
| 273 | } elsif ( $installing ) { | ||
| 274 | _warnonce("Rename failed: $!. Scheduling '$tmp'\nfor". | ||
| 275 | " installation as '$file' at reboot.\n"); | ||
| 276 | _move_file_at_boot( $tmp, $file ); | ||
| 277 | return $tmp; | ||
| 278 | } else { | ||
| 279 | _choke("Rename failed:$!", "Cannot procede."); | ||
| 280 | } | ||
| 281 | |||
| 282 | } | ||
| 283 | |||
| 284 | |||
| 285 | =pod | ||
| 286 | |||
| 287 | =head2 Functions | ||
| 288 | |||
| 289 | =begin _private | ||
| 290 | |||
| 291 | =item _get_install_skip | ||
| 292 | |||
| 293 | Handles loading the INSTALL.SKIP file. Returns an array of patterns to use. | ||
| 294 | |||
| 295 | =cut | ||
| 296 | |||
| 297 | |||
| 298 | |||
| 299 | sub _get_install_skip { | ||
| 300 | my ( $skip, $verbose )= @_; | ||
| 301 | if ($ENV{EU_INSTALL_IGNORE_SKIP}) { | ||
| 302 | print "EU_INSTALL_IGNORE_SKIP is set, ignore skipfile settings\n" | ||
| 303 | if $verbose>2; | ||
| 304 | return []; | ||
| 305 | } | ||
| 306 | if ( ! defined $skip ) { | ||
| 307 | print "Looking for install skip list\n" | ||
| 308 | if $verbose>2; | ||
| 309 | for my $file ( 'INSTALL.SKIP', $ENV{EU_INSTALL_SITE_SKIPFILE} ) { | ||
| 310 | next unless $file; | ||
| 311 | print "\tChecking for $file\n" | ||
| 312 | if $verbose>2; | ||
| 313 | if (-e $file) { | ||
| 314 | $skip= $file; | ||
| 315 | last; | ||
| 316 | } | ||
| 317 | } | ||
| 318 | } | ||
| 319 | if ($skip && !ref $skip) { | ||
| 320 | print "Reading skip patterns from '$skip'.\n" | ||
| 321 | if $verbose; | ||
| 322 | if (open my $fh,$skip ) { | ||
| 323 | my @patterns; | ||
| 324 | while (<$fh>) { | ||
| 325 | chomp; | ||
| 326 | next if /^\s*(?:#|$)/; | ||
| 327 | print "\tSkip pattern: $_\n" if $verbose>3; | ||
| 328 | push @patterns, $_; | ||
| 329 | } | ||
| 330 | $skip= \@patterns; | ||
| 331 | } else { | ||
| 332 | warn "Can't read skip file:'$skip':$!\n"; | ||
| 333 | $skip=[]; | ||
| 334 | } | ||
| 335 | } elsif ( UNIVERSAL::isa($skip,'ARRAY') ) { | ||
| 336 | print "Using array for skip list\n" | ||
| 337 | if $verbose>2; | ||
| 338 | } elsif ($verbose) { | ||
| 339 | print "No skip list found.\n" | ||
| 340 | if $verbose>1; | ||
| 341 | $skip= []; | ||
| 342 | } | ||
| 343 | warn "Got @{[0+@$skip]} skip patterns.\n" | ||
| 344 | if $verbose>3; | ||
| 345 | return $skip | ||
| 346 | } | ||
| 347 | |||
| 348 | =pod | ||
| 349 | |||
| 350 | =item _have_write_access | ||
| 351 | |||
| 352 | Abstract a -w check that tries to use POSIX::access() if possible. | ||
| 353 | |||
| 354 | =cut | ||
| 355 | |||
| 356 | { | ||
| 357 | my $has_posix; | ||
| 358 | sub _have_write_access { | ||
| 359 | my $dir=shift; | ||
| 360 | unless (defined $has_posix) { | ||
| 361 | $has_posix= (!$Is_cygwin && eval 'local $^W; require POSIX; 1') || 0; | ||
| 362 | } | ||
| 363 | if ($has_posix) { | ||
| 364 | return POSIX::access($dir, POSIX::W_OK()); | ||
| 365 | } else { | ||
| 366 | return -w $dir; | ||
| 367 | } | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | =pod | ||
| 372 | |||
| 373 | =item _can_write_dir(C<$dir>) | ||
| 374 | |||
| 375 | Checks whether a given directory is writable, taking account | ||
| 376 | the possibility that the directory might not exist and would have to | ||
| 377 | be created first. | ||
| 378 | |||
| 379 | Returns a list, containing: C<($writable, $determined_by, @create)> | ||
| 380 | |||
| 381 | C<$writable> says whether whether the directory is (hypothetically) writable | ||
| 382 | |||
| 383 | C<$determined_by> is the directory the status was determined from. It will be | ||
| 384 | either the C<$dir>, or one of its parents. | ||
| 385 | |||
| 386 | C<@create> is a list of directories that would probably have to be created | ||
| 387 | to make the requested directory. It may not actually be correct on | ||
| 388 | relative paths with C<..> in them. But for our purposes it should work ok | ||
| 389 | |||
| 390 | =cut | ||
| 391 | |||
| 392 | |||
| 393 | sub _can_write_dir { | ||
| 394 | my $dir=shift; | ||
| 395 | return | ||
| 396 | unless defined $dir and length $dir; | ||
| 397 | |||
| 398 | my ($vol, $dirs, $file) = File::Spec->splitpath($dir,1); | ||
| 399 | my @dirs = File::Spec->splitdir($dirs); | ||
| 400 | unshift @dirs, File::Spec->curdir | ||
| 401 | unless File::Spec->file_name_is_absolute($dir); | ||
| 402 | |||
| 403 | my $path=''; | ||
| 404 | my @make; | ||
| 405 | while (@dirs) { | ||
| 406 | $dir = File::Spec->catdir(@dirs); | ||
| 407 | $dir = File::Spec->catpath($vol,$dir,'') | ||
| 408 | if defined $vol and length $vol; | ||
| 409 | next if ( $dir eq $path ); | ||
| 410 | if ( ! -e $dir ) { | ||
| 411 | unshift @make,$dir; | ||
| 412 | next; | ||
| 413 | } | ||
| 414 | if ( _have_write_access($dir) ) { | ||
| 415 | return 1,$dir,@make | ||
| 416 | } else { | ||
| 417 | return 0,$dir,@make | ||
| 418 | } | ||
| 419 | } continue { | ||
| 420 | pop @dirs; | ||
| 421 | } | ||
| 422 | return 0; | ||
| 423 | } | ||
| 424 | |||
| 425 | =pod | ||
| 426 | |||
| 427 | =item _mkpath($dir,$show,$mode,$verbose,$dry_run) | ||
| 428 | |||
| 429 | Wrapper around File::Path::mkpath() to handle errors. | ||
| 430 | |||
| 431 | If $verbose is true and >1 then additional diagnostics will be produced, also | ||
| 432 | this will force $show to true. | ||
| 433 | |||
| 434 | If $dry_run is true then the directory will not be created but a check will be | ||
| 435 | made to see whether it would be possible to write to the directory, or that | ||
| 436 | it would be possible to create the directory. | ||
| 437 | |||
| 438 | If $dry_run is not true dies if the directory can not be created or is not | ||
| 439 | writable. | ||
| 440 | |||
| 441 | =cut | ||
| 442 | |||
| 443 | sub _mkpath { | ||
| 444 | my ($dir,$show,$mode,$verbose,$dry_run)=@_; | ||
| 445 | if ( $verbose && $verbose > 1 && ! -d $dir) { | ||
| 446 | $show= 1; | ||
| 447 | printf "mkpath(%s,%d,%#o)\n", $dir, $show, $mode; | ||
| 448 | } | ||
| 449 | if (!$dry_run) { | ||
| 450 | if ( ! eval { File::Path::mkpath($dir,$show,$mode); 1 } ) { | ||
| 451 | _choke("Can't create '$dir'","$@"); | ||
| 452 | } | ||
| 453 | |||
| 454 | } | ||
| 455 | my ($can,$root,@make)=_can_write_dir($dir); | ||
| 456 | if (!$can) { | ||
| 457 | my @msg=( | ||
| 458 | "Can't create '$dir'", | ||
| 459 | $root ? "Do not have write permissions on '$root'" | ||
| 460 | : "Unknown Error" | ||
| 461 | ); | ||
| 462 | if ($dry_run) { | ||
| 463 | _warnonce @msg; | ||
| 464 | } else { | ||
| 465 | _choke @msg; | ||
| 466 | } | ||
| 467 | } elsif ($show and $dry_run) { | ||
| 468 | print "$_\n" for @make; | ||
| 469 | } | ||
| 470 | |||
| 471 | } | ||
| 472 | |||
| 473 | =pod | ||
| 474 | |||
| 475 | =item _copy($from,$to,$verbose,$dry_run) | ||
| 476 | |||
| 477 | Wrapper around File::Copy::copy to handle errors. | ||
| 478 | |||
| 479 | If $verbose is true and >1 then additional dignostics will be emitted. | ||
| 480 | |||
| 481 | If $dry_run is true then the copy will not actually occur. | ||
| 482 | |||
| 483 | Dies if the copy fails. | ||
| 484 | |||
| 485 | =cut | ||
| 486 | |||
| 487 | |||
| 488 | sub _copy { | ||
| 489 | my ( $from, $to, $verbose, $dry_run)=@_; | ||
| 490 | if ($verbose && $verbose>1) { | ||
| 491 | printf "copy(%s,%s)\n", $from, $to; | ||
| 492 | } | ||
| 493 | if (!$dry_run) { | ||
| 494 | File::Copy::copy($from,$to) | ||
| 495 | or Carp::croak( _estr "ERROR: Cannot copy '$from' to '$to': $!" ); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | =pod | ||
| 500 | |||
| 501 | =item _chdir($from) | ||
| 502 | |||
| 503 | Wrapper around chdir to catch errors. | ||
| 504 | |||
| 505 | If not called in void context returns the cwd from before the chdir. | ||
| 506 | |||
| 507 | dies on error. | ||
| 508 | |||
| 509 | =cut | ||
| 510 | |||
| 511 | sub _chdir { | ||
| 512 | my ($dir)= @_; | ||
| 513 | my $ret; | ||
| 514 | if (defined wantarray) { | ||
| 515 | $ret= cwd; | ||
| 516 | } | ||
| 517 | chdir $dir | ||
| 518 | or _choke("Couldn't chdir to '$dir': $!"); | ||
| 519 | return $ret; | ||
| 520 | } | ||
| 521 | |||
| 522 | =pod | ||
| 523 | |||
| 524 | =end _private | ||
| 525 | |||
| 526 | =over 4 | ||
| 527 | |||
| 528 | =item B<install> | ||
| 529 | |||
| 530 | # deprecated forms | ||
| 531 | install(\%from_to); | ||
| 532 | install(\%from_to, $verbose, $dry_run, $uninstall_shadows, | ||
| 533 | $skip, $always_copy, \%result); | ||
| 534 | |||
| 535 | # recommended form as of 1.47 | ||
| 536 | install([ | ||
| 537 | from_to => \%from_to, | ||
| 538 | verbose => 1, | ||
| 539 | dry_run => 0, | ||
| 540 | uninstall_shadows => 1, | ||
| 541 | skip => undef, | ||
| 542 | always_copy => 1, | ||
| 543 | result => \%install_results, | ||
| 544 | ]); | ||
| 545 | |||
| 546 | |||
| 547 | Copies each directory tree of %from_to to its corresponding value | ||
| 548 | preserving timestamps and permissions. | ||
| 549 | |||
| 550 | There are two keys with a special meaning in the hash: "read" and | ||
| 551 | "write". These contain packlist files. After the copying is done, | ||
| 552 | install() will write the list of target files to $from_to{write}. If | ||
| 553 | $from_to{read} is given the contents of this file will be merged into | ||
| 554 | the written file. The read and the written file may be identical, but | ||
| 555 | on AFS it is quite likely that people are installing to a different | ||
| 556 | directory than the one where the files later appear. | ||
| 557 | |||
| 558 | If $verbose is true, will print out each file removed. Default is | ||
| 559 | false. This is "make install VERBINST=1". $verbose values going | ||
| 560 | up to 5 show increasingly more diagnostics output. | ||
| 561 | |||
| 562 | If $dry_run is true it will only print what it was going to do | ||
| 563 | without actually doing it. Default is false. | ||
| 564 | |||
| 565 | If $uninstall_shadows is true any differing versions throughout @INC | ||
| 566 | will be uninstalled. This is "make install UNINST=1" | ||
| 567 | |||
| 568 | As of 1.37_02 install() supports the use of a list of patterns to filter out | ||
| 569 | files that shouldn't be installed. If $skip is omitted or undefined then | ||
| 570 | install will try to read the list from INSTALL.SKIP in the CWD. This file is | ||
| 571 | a list of regular expressions and is just like the MANIFEST.SKIP file used | ||
| 572 | by L<ExtUtils::Manifest>. | ||
| 573 | |||
| 574 | A default site INSTALL.SKIP may be provided by setting then environment | ||
| 575 | variable EU_INSTALL_SITE_SKIPFILE, this will only be used when there isn't a | ||
| 576 | distribution specific INSTALL.SKIP. If the environment variable | ||
| 577 | EU_INSTALL_IGNORE_SKIP is true then no install file filtering will be | ||
| 578 | performed. | ||
| 579 | |||
| 580 | If $skip is undefined then the skip file will be autodetected and used if it | ||
| 581 | is found. If $skip is a reference to an array then it is assumed the array | ||
| 582 | contains the list of patterns, if $skip is a true non reference it is | ||
| 583 | assumed to be the filename holding the list of patterns, any other value of | ||
| 584 | $skip is taken to mean that no install filtering should occur. | ||
| 585 | |||
| 586 | B<Changes As of Version 1.47> | ||
| 587 | |||
| 588 | As of version 1.47 the following additions were made to the install interface. | ||
| 589 | Note that the new argument style and use of the %result hash is recommended. | ||
| 590 | |||
| 591 | The $always_copy parameter which when true causes files to be updated | ||
| 592 | regardles as to whether they have changed, if it is defined but false then | ||
| 593 | copies are made only if the files have changed, if it is undefined then the | ||
| 594 | value of the environment variable EU_INSTALL_ALWAYS_COPY is used as default. | ||
| 595 | |||
| 596 | The %result hash will be populated with the various keys/subhashes reflecting | ||
| 597 | the install. Currently these keys and their structure are: | ||
| 598 | |||
| 599 | install => { $target => $source }, | ||
| 600 | install_fail => { $target => $source }, | ||
| 601 | install_unchanged => { $target => $source }, | ||
| 602 | |||
| 603 | install_filtered => { $source => $pattern }, | ||
| 604 | |||
| 605 | uninstall => { $uninstalled => $source }, | ||
| 606 | uninstall_fail => { $uninstalled => $source }, | ||
| 607 | |||
| 608 | where C<$source> is the filespec of the file being installed. C<$target> is where | ||
| 609 | it is being installed to, and C<$uninstalled> is any shadow file that is in C<@INC> | ||
| 610 | or C<$ENV{PERL5LIB}> or other standard locations, and C<$pattern> is the pattern that | ||
| 611 | caused a source file to be skipped. In future more keys will be added, such as to | ||
| 612 | show created directories, however this requires changes in other modules and must | ||
| 613 | therefore wait. | ||
| 614 | |||
| 615 | These keys will be populated before any exceptions are thrown should there be an | ||
| 616 | error. | ||
| 617 | |||
| 618 | Note that all updates of the %result are additive, the hash will not be | ||
| 619 | cleared before use, thus allowing status results of many installs to be easily | ||
| 620 | aggregated. | ||
| 621 | |||
| 622 | B<NEW ARGUMENT STYLE> | ||
| 623 | |||
| 624 | If there is only one argument and it is a reference to an array then | ||
| 625 | the array is assumed to contain a list of key-value pairs specifying | ||
| 626 | the options. In this case the option "from_to" is mandatory. This style | ||
| 627 | means that you dont have to supply a cryptic list of arguments and can | ||
| 628 | use a self documenting argument list that is easier to understand. | ||
| 629 | |||
| 630 | This is now the recommended interface to install(). | ||
| 631 | |||
| 632 | B<RETURN> | ||
| 633 | |||
| 634 | If all actions were successful install will return a hashref of the results | ||
| 635 | as described above for the $result parameter. If any action is a failure | ||
| 636 | then install will die, therefore it is recommended to pass in the $result | ||
| 637 | parameter instead of using the return value. If the result parameter is | ||
| 638 | provided then the returned hashref will be the passed in hashref. | ||
| 639 | |||
| 640 | =cut | ||
| 641 | |||
| 642 | sub install { #XXX OS-SPECIFIC | ||
| 643 | my($from_to,$verbose,$dry_run,$uninstall_shadows,$skip,$always_copy,$result) = @_; | ||
| 644 | if (@_==1 and eval { 1+@$from_to }) { | ||
| 645 | my %opts = @$from_to; | ||
| 646 | $from_to = $opts{from_to} | ||
| 647 | or Carp::confess("from_to is a mandatory parameter"); | ||
| 648 | $verbose = $opts{verbose}; | ||
| 649 | $dry_run = $opts{dry_run}; | ||
| 650 | $uninstall_shadows = $opts{uninstall_shadows}; | ||
| 651 | $skip = $opts{skip}; | ||
| 652 | $always_copy = $opts{always_copy}; | ||
| 653 | $result = $opts{result}; | ||
| 654 | } | ||
| 655 | |||
| 656 | $result ||= {}; | ||
| 657 | $verbose ||= 0; | ||
| 658 | $dry_run ||= 0; | ||
| 659 | |||
| 660 | $skip= _get_install_skip($skip,$verbose); | ||
| 661 | $always_copy = $ENV{EU_INSTALL_ALWAYS_COPY} | ||
| 662 | || $ENV{EU_ALWAYS_COPY} | ||
| 663 | || 0 | ||
| 664 | unless defined $always_copy; | ||
| 665 | |||
| 666 | my(%from_to) = %$from_to; | ||
| 667 | my(%pack, $dir, %warned); | ||
| 668 | my($packlist) = ExtUtils::Packlist->new(); | ||
| 669 | |||
| 670 | local(*DIR); | ||
| 671 | for (qw/read write/) { | ||
| 672 | $pack{$_}=$from_to{$_}; | ||
| 673 | delete $from_to{$_}; | ||
| 674 | } | ||
| 675 | my $tmpfile = install_rooted_file($pack{"read"}); | ||
| 676 | $packlist->read($tmpfile) if (-f $tmpfile); | ||
| 677 | my $cwd = cwd(); | ||
| 678 | my @found_files; | ||
| 679 | my %check_dirs; | ||
| 680 | |||
| 681 | MOD_INSTALL: foreach my $source (sort keys %from_to) { | ||
| 682 | #copy the tree to the target directory without altering | ||
| 683 | #timestamp and permission and remember for the .packlist | ||
| 684 | #file. The packlist file contains the absolute paths of the | ||
| 685 | #install locations. AFS users may call this a bug. We'll have | ||
| 686 | #to reconsider how to add the means to satisfy AFS users also. | ||
| 687 | |||
| 688 | #October 1997: we want to install .pm files into archlib if | ||
| 689 | #there are any files in arch. So we depend on having ./blib/arch | ||
| 690 | #hardcoded here. | ||
| 691 | |||
| 692 | my $targetroot = install_rooted_dir($from_to{$source}); | ||
| 693 | |||
| 694 | my $blib_lib = File::Spec->catdir('blib', 'lib'); | ||
| 695 | my $blib_arch = File::Spec->catdir('blib', 'arch'); | ||
| 696 | if ($source eq $blib_lib and | ||
| 697 | exists $from_to{$blib_arch} and | ||
| 698 | directory_not_empty($blib_arch) | ||
| 699 | ){ | ||
| 700 | $targetroot = install_rooted_dir($from_to{$blib_arch}); | ||
| 701 | print "Files found in $blib_arch: installing files in $blib_lib into architecture dependent library tree\n"; | ||
| 702 | } | ||
| 703 | |||
| 704 | next unless -d $source; | ||
| 705 | _chdir($source); | ||
| 706 | # 5.5.3's File::Find missing no_chdir option | ||
| 707 | # XXX OS-SPECIFIC | ||
| 708 | # File::Find seems to always be Unixy except on MacPerl :( | ||
| 709 | my $current_directory= $Is_MacPerl ? $Curdir : '.'; | ||
| 710 | find(sub { | ||
| 711 | my ($mode,$size,$atime,$mtime) = (stat)[2,7,8,9]; | ||
| 712 | |||
| 713 | return if !-f _; | ||
| 714 | my $origfile = $_; | ||
| 715 | |||
| 716 | return if $origfile eq ".exists"; | ||
| 717 | my $targetdir = File::Spec->catdir($targetroot, $File::Find::dir); | ||
| 718 | my $targetfile = File::Spec->catfile($targetdir, $origfile); | ||
| 719 | my $sourcedir = File::Spec->catdir($source, $File::Find::dir); | ||
| 720 | my $sourcefile = File::Spec->catfile($sourcedir, $origfile); | ||
| 721 | |||
| 722 | for my $pat (@$skip) { | ||
| 723 | if ( $sourcefile=~/$pat/ ) { | ||
| 724 | print "Skipping $targetfile (filtered)\n" | ||
| 725 | if $verbose>1; | ||
| 726 | $result->{install_filtered}{$sourcefile} = $pat; | ||
| 727 | return; | ||
| 728 | } | ||
| 729 | } | ||
| 730 | # we have to do this for back compat with old File::Finds | ||
| 731 | # and because the target is relative | ||
| 732 | my $save_cwd = _chdir($cwd); | ||
| 733 | my $diff = 0; | ||
| 734 | # XXX: I wonder how useful this logic is actually -- demerphq | ||
| 735 | if ( $always_copy or !-f $targetfile or -s $targetfile != $size) { | ||
| 736 | $diff++; | ||
| 737 | } else { | ||
| 738 | # we might not need to copy this file | ||
| 739 | $diff = compare($sourcefile, $targetfile); | ||
| 740 | } | ||
| 741 | $check_dirs{$targetdir}++ | ||
| 742 | unless -w $targetfile; | ||
| 743 | |||
| 744 | push @found_files, | ||
| 745 | [ $diff, $File::Find::dir, $origfile, | ||
| 746 | $mode, $size, $atime, $mtime, | ||
| 747 | $targetdir, $targetfile, $sourcedir, $sourcefile, | ||
| 748 | |||
| 749 | ]; | ||
| 750 | #restore the original directory we were in when File::Find | ||
| 751 | #called us so that it doesnt get horribly confused. | ||
| 752 | _chdir($save_cwd); | ||
| 753 | }, $current_directory ); | ||
| 754 | _chdir($cwd); | ||
| 755 | } | ||
| 756 | foreach my $targetdir (sort keys %check_dirs) { | ||
| 757 | _mkpath( $targetdir, 0, 0755, $verbose, $dry_run ); | ||
| 758 | } | ||
| 759 | foreach my $found (@found_files) { | ||
| 760 | my ($diff, $ffd, $origfile, $mode, $size, $atime, $mtime, | ||
| 761 | $targetdir, $targetfile, $sourcedir, $sourcefile)= @$found; | ||
| 762 | |||
| 763 | my $realtarget= $targetfile; | ||
| 764 | if ($diff) { | ||
| 765 | eval { | ||
| 766 | if (-f $targetfile) { | ||
| 767 | print "_unlink_or_rename($targetfile)\n" if $verbose>1; | ||
| 768 | $targetfile= _unlink_or_rename( $targetfile, 'tryhard', 'install' ) | ||
| 769 | unless $dry_run; | ||
| 770 | } elsif ( ! -d $targetdir ) { | ||
| 771 | _mkpath( $targetdir, 0, 0755, $verbose, $dry_run ); | ||
| 772 | } | ||
| 773 | print "Installing $targetfile\n"; | ||
| 774 | |||
| 775 | _copy( $sourcefile, $targetfile, $verbose, $dry_run, ); | ||
| 776 | |||
| 777 | |||
| 778 | #XXX OS-SPECIFIC | ||
| 779 | print "utime($atime,$mtime,$targetfile)\n" if $verbose>1; | ||
| 780 | utime($atime,$mtime + $Is_VMS,$targetfile) unless $dry_run>1; | ||
| 781 | |||
| 782 | |||
| 783 | $mode = 0444 | ( $mode & 0111 ? 0111 : 0 ); | ||
| 784 | $mode = $mode | 0222 | ||
| 785 | if $realtarget ne $targetfile; | ||
| 786 | _chmod( $mode, $targetfile, $verbose ); | ||
| 787 | $result->{install}{$targetfile} = $sourcefile; | ||
| 788 | 1 | ||
| 789 | } or do { | ||
| 790 | $result->{install_fail}{$targetfile} = $sourcefile; | ||
| 791 | die $@; | ||
| 792 | }; | ||
| 793 | } else { | ||
| 794 | $result->{install_unchanged}{$targetfile} = $sourcefile; | ||
| 795 | print "Skipping $targetfile (unchanged)\n" if $verbose; | ||
| 796 | } | ||
| 797 | |||
| 798 | if ( $uninstall_shadows ) { | ||
| 799 | inc_uninstall($sourcefile,$ffd, $verbose, | ||
| 800 | $dry_run, | ||
| 801 | $realtarget ne $targetfile ? $realtarget : "", | ||
| 802 | $result); | ||
| 803 | } | ||
| 804 | |||
| 805 | # Record the full pathname. | ||
| 806 | $packlist->{$targetfile}++; | ||
| 807 | } | ||
| 808 | |||
| 809 | if ($pack{'write'}) { | ||
| 810 | $dir = install_rooted_dir(dirname($pack{'write'})); | ||
| 811 | _mkpath( $dir, 0, 0755, $verbose, $dry_run ); | ||
| 812 | print "Writing $pack{'write'}\n"; | ||
| 813 | $packlist->write(install_rooted_file($pack{'write'})) unless $dry_run; | ||
| 814 | } | ||
| 815 | |||
| 816 | _do_cleanup($verbose); | ||
| 817 | return $result; | ||
| 818 | } | ||
| 819 | |||
| 820 | =begin _private | ||
| 821 | |||
| 822 | =item _do_cleanup | ||
| 823 | |||
| 824 | Standardize finish event for after another instruction has occured. | ||
| 825 | Handles converting $MUST_REBOOT to a die for instance. | ||
| 826 | |||
| 827 | =end _private | ||
| 828 | |||
| 829 | =cut | ||
| 830 | |||
| 831 | sub _do_cleanup { | ||
| 832 | my ($verbose) = @_; | ||
| 833 | if ($MUST_REBOOT) { | ||
| 834 | die _estr "Operation not completed! ", | ||
| 835 | "You must reboot to complete the installation.", | ||
| 836 | "Sorry."; | ||
| 837 | } elsif (defined $MUST_REBOOT & $verbose) { | ||
| 838 | warn _estr "Installation will be completed at the next reboot.\n", | ||
| 839 | "However it is not necessary to reboot immediately.\n"; | ||
| 840 | } | ||
| 841 | } | ||
| 842 | |||
| 843 | =begin _undocumented | ||
| 844 | |||
| 845 | =item install_rooted_file( $file ) | ||
| 846 | |||
| 847 | Returns $file, or catfile($INSTALL_ROOT,$file) if $INSTALL_ROOT | ||
| 848 | is defined. | ||
| 849 | |||
| 850 | =item install_rooted_dir( $dir ) | ||
| 851 | |||
| 852 | Returns $dir, or catdir($INSTALL_ROOT,$dir) if $INSTALL_ROOT | ||
| 853 | is defined. | ||
| 854 | |||
| 855 | =end _undocumented | ||
| 856 | |||
| 857 | =cut | ||
| 858 | |||
| 859 | |||
| 860 | sub install_rooted_file { | ||
| 861 | if (defined $INSTALL_ROOT) { | ||
| 862 | File::Spec->catfile($INSTALL_ROOT, $_[0]); | ||
| 863 | } else { | ||
| 864 | $_[0]; | ||
| 865 | } | ||
| 866 | } | ||
| 867 | |||
| 868 | |||
| 869 | sub install_rooted_dir { | ||
| 870 | if (defined $INSTALL_ROOT) { | ||
| 871 | File::Spec->catdir($INSTALL_ROOT, $_[0]); | ||
| 872 | } else { | ||
| 873 | $_[0]; | ||
| 874 | } | ||
| 875 | } | ||
| 876 | |||
| 877 | =begin _undocumented | ||
| 878 | |||
| 879 | =item forceunlink( $file, $tryhard ) | ||
| 880 | |||
| 881 | Tries to delete a file. If $tryhard is true then we will use whatever | ||
| 882 | devious tricks we can to delete the file. Currently this only applies to | ||
| 883 | Win32 in that it will try to use Win32API::File to schedule a delete at | ||
| 884 | reboot. A wrapper for _unlink_or_rename(). | ||
| 885 | |||
| 886 | =end _undocumented | ||
| 887 | |||
| 888 | =cut | ||
| 889 | |||
| 890 | |||
| 891 | sub forceunlink { | ||
| 892 | my ( $file, $tryhard )= @_; #XXX OS-SPECIFIC | ||
| 893 | _unlink_or_rename( $file, $tryhard, not("installing") ); | ||
| 894 | } | ||
| 895 | |||
| 896 | =begin _undocumented | ||
| 897 | |||
| 898 | =item directory_not_empty( $dir ) | ||
| 899 | |||
| 900 | Returns 1 if there is an .exists file somewhere in a directory tree. | ||
| 901 | Returns 0 if there is not. | ||
| 902 | |||
| 903 | =end _undocumented | ||
| 904 | |||
| 905 | =cut | ||
| 906 | |||
| 907 | sub directory_not_empty ($) { | ||
| 908 | my($dir) = @_; | ||
| 909 | my $files = 0; | ||
| 910 | find(sub { | ||
| 911 | return if $_ eq ".exists"; | ||
| 912 | if (-f) { | ||
| 913 | $File::Find::prune++; | ||
| 914 | $files = 1; | ||
| 915 | } | ||
| 916 | }, $dir); | ||
| 917 | return $files; | ||
| 918 | } | ||
| 919 | |||
| 920 | =pod | ||
| 921 | |||
| 922 | =item B<install_default> I<DISCOURAGED> | ||
| 923 | |||
| 924 | install_default(); | ||
| 925 | install_default($fullext); | ||
| 926 | |||
| 927 | Calls install() with arguments to copy a module from blib/ to the | ||
| 928 | default site installation location. | ||
| 929 | |||
| 930 | $fullext is the name of the module converted to a directory | ||
| 931 | (ie. Foo::Bar would be Foo/Bar). If $fullext is not specified, it | ||
| 932 | will attempt to read it from @ARGV. | ||
| 933 | |||
| 934 | This is primarily useful for install scripts. | ||
| 935 | |||
| 936 | B<NOTE> This function is not really useful because of the hard-coded | ||
| 937 | install location with no way to control site vs core vs vendor | ||
| 938 | directories and the strange way in which the module name is given. | ||
| 939 | Consider its use discouraged. | ||
| 940 | |||
| 941 | =cut | ||
| 942 | |||
| 943 | sub install_default { | ||
| 944 | @_ < 2 or Carp::croak("install_default should be called with 0 or 1 argument"); | ||
| 945 | my $FULLEXT = @_ ? shift : $ARGV[0]; | ||
| 946 | defined $FULLEXT or die "Do not know to where to write install log"; | ||
| 947 | my $INST_LIB = File::Spec->catdir($Curdir,"blib","lib"); | ||
| 948 | my $INST_ARCHLIB = File::Spec->catdir($Curdir,"blib","arch"); | ||
| 949 | my $INST_BIN = File::Spec->catdir($Curdir,'blib','bin'); | ||
| 950 | my $INST_SCRIPT = File::Spec->catdir($Curdir,'blib','script'); | ||
| 951 | my $INST_MAN1DIR = File::Spec->catdir($Curdir,'blib','man1'); | ||
| 952 | my $INST_MAN3DIR = File::Spec->catdir($Curdir,'blib','man3'); | ||
| 953 | install({ | ||
| 954 | read => "$Config{sitearchexp}/auto/$FULLEXT/.packlist", | ||
| 955 | write => "$Config{installsitearch}/auto/$FULLEXT/.packlist", | ||
| 956 | $INST_LIB => (directory_not_empty($INST_ARCHLIB)) ? | ||
| 957 | $Config{installsitearch} : | ||
| 958 | $Config{installsitelib}, | ||
| 959 | $INST_ARCHLIB => $Config{installsitearch}, | ||
| 960 | $INST_BIN => $Config{installbin} , | ||
| 961 | $INST_SCRIPT => $Config{installscript}, | ||
| 962 | $INST_MAN1DIR => $Config{installman1dir}, | ||
| 963 | $INST_MAN3DIR => $Config{installman3dir}, | ||
| 964 | },1,0,0); | ||
| 965 | } | ||
| 966 | |||
| 967 | |||
| 968 | =item B<uninstall> | ||
| 969 | |||
| 970 | uninstall($packlist_file); | ||
| 971 | uninstall($packlist_file, $verbose, $dont_execute); | ||
| 972 | |||
| 973 | Removes the files listed in a $packlist_file. | ||
| 974 | |||
| 975 | If $verbose is true, will print out each file removed. Default is | ||
| 976 | false. | ||
| 977 | |||
| 978 | If $dont_execute is true it will only print what it was going to do | ||
| 979 | without actually doing it. Default is false. | ||
| 980 | |||
| 981 | =cut | ||
| 982 | |||
| 983 | sub uninstall { | ||
| 984 | my($fil,$verbose,$dry_run) = @_; | ||
| 985 | $verbose ||= 0; | ||
| 986 | $dry_run ||= 0; | ||
| 987 | |||
| 988 | die _estr "ERROR: no packlist file found: '$fil'" | ||
| 989 | unless -f $fil; | ||
| 990 | # my $my_req = $self->catfile(qw(auto ExtUtils Install forceunlink.al)); | ||
| 991 | # require $my_req; # Hairy, but for the first | ||
| 992 | my ($packlist) = ExtUtils::Packlist->new($fil); | ||
| 993 | foreach (sort(keys(%$packlist))) { | ||
| 994 | chomp; | ||
| 995 | print "unlink $_\n" if $verbose; | ||
| 996 | forceunlink($_,'tryhard') unless $dry_run; | ||
| 997 | } | ||
| 998 | print "unlink $fil\n" if $verbose; | ||
| 999 | forceunlink($fil, 'tryhard') unless $dry_run; | ||
| 1000 | _do_cleanup($verbose); | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | =begin _undocumented | ||
| 1004 | |||
| 1005 | =item inc_uninstall($filepath,$libdir,$verbose,$dry_run,$ignore,$results) | ||
| 1006 | |||
| 1007 | Remove shadowed files. If $ignore is true then it is assumed to hold | ||
| 1008 | a filename to ignore. This is used to prevent spurious warnings from | ||
| 1009 | occuring when doing an install at reboot. | ||
| 1010 | |||
| 1011 | We now only die when failing to remove a file that has precedence over | ||
| 1012 | our own, when our install has precedence we only warn. | ||
| 1013 | |||
| 1014 | $results is assumed to contain a hashref which will have the keys | ||
| 1015 | 'uninstall' and 'uninstall_fail' populated with keys for the files | ||
| 1016 | removed and values of the source files they would shadow. | ||
| 1017 | |||
| 1018 | =end _undocumented | ||
| 1019 | |||
| 1020 | =cut | ||
| 1021 | |||
| 1022 | sub inc_uninstall { | ||
| 1023 | my($filepath,$libdir,$verbose,$dry_run,$ignore,$results) = @_; | ||
| 1024 | my($dir); | ||
| 1025 | $ignore||=""; | ||
| 1026 | my $file = (File::Spec->splitpath($filepath))[2]; | ||
| 1027 | my %seen_dir = (); | ||
| 1028 | |||
| 1029 | my @PERL_ENV_LIB = split $Config{path_sep}, defined $ENV{'PERL5LIB'} | ||
| 1030 | ? $ENV{'PERL5LIB'} : $ENV{'PERLLIB'} || ''; | ||
| 1031 | |||
| 1032 | my @dirs=( @PERL_ENV_LIB, | ||
| 1033 | @INC, | ||
| 1034 | @Config{qw(archlibexp | ||
| 1035 | privlibexp | ||
| 1036 | sitearchexp | ||
| 1037 | sitelibexp)}); | ||
| 1038 | |||
| 1039 | #warn join "\n","---",@dirs,"---"; | ||
| 1040 | my $seen_ours; | ||
| 1041 | foreach $dir ( @dirs ) { | ||
| 1042 | my $canonpath = File::Spec->canonpath($dir); | ||
| 1043 | next if $canonpath eq $Curdir; | ||
| 1044 | next if $seen_dir{$canonpath}++; | ||
| 1045 | my $targetfile = File::Spec->catfile($canonpath,$libdir,$file); | ||
| 1046 | next unless -f $targetfile; | ||
| 1047 | |||
| 1048 | # The reason why we compare file's contents is, that we cannot | ||
| 1049 | # know, which is the file we just installed (AFS). So we leave | ||
| 1050 | # an identical file in place | ||
| 1051 | my $diff = 0; | ||
| 1052 | if ( -f $targetfile && -s _ == -s $filepath) { | ||
| 1053 | # We have a good chance, we can skip this one | ||
| 1054 | $diff = compare($filepath,$targetfile); | ||
| 1055 | } else { | ||
| 1056 | $diff++; | ||
| 1057 | } | ||
| 1058 | print "#$file and $targetfile differ\n" if $diff && $verbose > 1; | ||
| 1059 | |||
| 1060 | if (!$diff or $targetfile eq $ignore) { | ||
| 1061 | $seen_ours = 1; | ||
| 1062 | next; | ||
| 1063 | } | ||
| 1064 | if ($dry_run) { | ||
| 1065 | $results->{uninstall}{$targetfile} = $filepath; | ||
| 1066 | if ($verbose) { | ||
| 1067 | $Inc_uninstall_warn_handler ||= ExtUtils::Install::Warn->new(); | ||
| 1068 | $libdir =~ s|^\./||s ; # That's just cosmetics, no need to port. It looks prettier. | ||
| 1069 | $Inc_uninstall_warn_handler->add( | ||
| 1070 | File::Spec->catfile($libdir, $file), | ||
| 1071 | $targetfile | ||
| 1072 | ); | ||
| 1073 | } | ||
| 1074 | # if not verbose, we just say nothing | ||
| 1075 | } else { | ||
| 1076 | print "Unlinking $targetfile (shadowing?)\n" if $verbose; | ||
| 1077 | eval { | ||
| 1078 | die "Fake die for testing" | ||
| 1079 | if $ExtUtils::Install::Testing and | ||
| 1080 | File::Spec->canonpath($ExtUtils::Install::Testing) eq $targetfile; | ||
| 1081 | forceunlink($targetfile,'tryhard'); | ||
| 1082 | $results->{uninstall}{$targetfile} = $filepath; | ||
| 1083 | 1; | ||
| 1084 | } or do { | ||
| 1085 | $results->{fail_uninstall}{$targetfile} = $filepath; | ||
| 1086 | if ($seen_ours) { | ||
| 1087 | warn "Failed to remove probably harmless shadow file '$targetfile'\n"; | ||
| 1088 | } else { | ||
| 1089 | die "$@\n"; | ||
| 1090 | } | ||
| 1091 | }; | ||
| 1092 | } | ||
| 1093 | } | ||
| 1094 | } | ||
| 1095 | |||
| 1096 | =begin _undocumented | ||
| 1097 | |||
| 1098 | =item run_filter($cmd,$src,$dest) | ||
| 1099 | |||
| 1100 | Filter $src using $cmd into $dest. | ||
| 1101 | |||
| 1102 | =end _undocumented | ||
| 1103 | |||
| 1104 | =cut | ||
| 1105 | |||
| 1106 | sub run_filter { | ||
| 1107 | my ($cmd, $src, $dest) = @_; | ||
| 1108 | local(*CMD, *SRC); | ||
| 1109 | open(CMD, "|$cmd >$dest") || die "Cannot fork: $!"; | ||
| 1110 | open(SRC, $src) || die "Cannot open $src: $!"; | ||
| 1111 | my $buf; | ||
| 1112 | my $sz = 1024; | ||
| 1113 | while (my $len = sysread(SRC, $buf, $sz)) { | ||
| 1114 | syswrite(CMD, $buf, $len); | ||
| 1115 | } | ||
| 1116 | close SRC; | ||
| 1117 | close CMD or die "Filter command '$cmd' failed for $src"; | ||
| 1118 | } | ||
| 1119 | |||
| 1120 | =pod | ||
| 1121 | |||
| 1122 | =item B<pm_to_blib> | ||
| 1123 | |||
| 1124 | pm_to_blib(\%from_to, $autosplit_dir); | ||
| 1125 | pm_to_blib(\%from_to, $autosplit_dir, $filter_cmd); | ||
| 1126 | |||
| 1127 | Copies each key of %from_to to its corresponding value efficiently. | ||
| 1128 | Filenames with the extension .pm are autosplit into the $autosplit_dir. | ||
| 1129 | Any destination directories are created. | ||
| 1130 | |||
| 1131 | $filter_cmd is an optional shell command to run each .pm file through | ||
| 1132 | prior to splitting and copying. Input is the contents of the module, | ||
| 1133 | output the new module contents. | ||
| 1134 | |||
| 1135 | You can have an environment variable PERL_INSTALL_ROOT set which will | ||
| 1136 | be prepended as a directory to each installed file (and directory). | ||
| 1137 | |||
| 1138 | =cut | ||
| 1139 | |||
| 1140 | sub pm_to_blib { | ||
| 1141 | my($fromto,$autodir,$pm_filter) = @_; | ||
| 1142 | |||
| 1143 | _mkpath($autodir,0,0755); | ||
| 1144 | while(my($from, $to) = each %$fromto) { | ||
| 1145 | if( -f $to && -s $from == -s $to && -M $to < -M $from ) { | ||
| 1146 | print "Skip $to (unchanged)\n"; | ||
| 1147 | next; | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | # When a pm_filter is defined, we need to pre-process the source first | ||
| 1151 | # to determine whether it has changed or not. Therefore, only perform | ||
| 1152 | # the comparison check when there's no filter to be ran. | ||
| 1153 | # -- RAM, 03/01/2001 | ||
| 1154 | |||
| 1155 | my $need_filtering = defined $pm_filter && length $pm_filter && | ||
| 1156 | $from =~ /\.pm$/; | ||
| 1157 | |||
| 1158 | if (!$need_filtering && 0 == compare($from,$to)) { | ||
| 1159 | print "Skip $to (unchanged)\n"; | ||
| 1160 | next; | ||
| 1161 | } | ||
| 1162 | if (-f $to){ | ||
| 1163 | # we wont try hard here. its too likely to mess things up. | ||
| 1164 | forceunlink($to); | ||
| 1165 | } else { | ||
| 1166 | _mkpath(dirname($to),0,0755); | ||
| 1167 | } | ||
| 1168 | if ($need_filtering) { | ||
| 1169 | run_filter($pm_filter, $from, $to); | ||
| 1170 | print "$pm_filter <$from >$to\n"; | ||
| 1171 | } else { | ||
| 1172 | _copy( $from, $to ); | ||
| 1173 | print "cp $from $to\n"; | ||
| 1174 | } | ||
| 1175 | my($mode,$atime,$mtime) = (stat $from)[2,8,9]; | ||
| 1176 | utime($atime,$mtime+$Is_VMS,$to); | ||
| 1177 | _chmod(0444 | ( $mode & 0111 ? 0111 : 0 ),$to); | ||
| 1178 | next unless $from =~ /\.pm$/; | ||
| 1179 | _autosplit($to,$autodir); | ||
| 1180 | } | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | |||
| 1184 | =begin _private | ||
| 1185 | |||
| 1186 | =item _autosplit | ||
| 1187 | |||
| 1188 | From 1.0307 back, AutoSplit will sometimes leave an open filehandle to | ||
| 1189 | the file being split. This causes problems on systems with mandatory | ||
| 1190 | locking (ie. Windows). So we wrap it and close the filehandle. | ||
| 1191 | |||
| 1192 | =end _private | ||
| 1193 | |||
| 1194 | =cut | ||
| 1195 | |||
| 1196 | sub _autosplit { #XXX OS-SPECIFIC | ||
| 1197 | my $retval = autosplit(@_); | ||
| 1198 | close *AutoSplit::IN if defined *AutoSplit::IN{IO}; | ||
| 1199 | |||
| 1200 | return $retval; | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | |||
| 1204 | package ExtUtils::Install::Warn; | ||
| 1205 | |||
| 1206 | sub new { bless {}, shift } | ||
| 1207 | |||
| 1208 | sub add { | ||
| 1209 | my($self,$file,$targetfile) = @_; | ||
| 1210 | push @{$self->{$file}}, $targetfile; | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | sub DESTROY { | ||
| 1214 | unless(defined $INSTALL_ROOT) { | ||
| 1215 | my $self = shift; | ||
| 1216 | my($file,$i,$plural); | ||
| 1217 | foreach $file (sort keys %$self) { | ||
| 1218 | $plural = @{$self->{$file}} > 1 ? "s" : ""; | ||
| 1219 | print "## Differing version$plural of $file found. You might like to\n"; | ||
| 1220 | for (0..$#{$self->{$file}}) { | ||
| 1221 | print "rm ", $self->{$file}[$_], "\n"; | ||
| 1222 | $i++; | ||
| 1223 | } | ||
| 1224 | } | ||
| 1225 | $plural = $i>1 ? "all those files" : "this file"; | ||
| 1226 | my $inst = (_invokant() eq 'ExtUtils::MakeMaker') | ||
| 1227 | ? ( $Config::Config{make} || 'make' ).' install UNINST=1' | ||
| 1228 | : './Build install uninst=1'; | ||
| 1229 | print "## Running '$inst' will unlink $plural for you.\n"; | ||
| 1230 | } | ||
| 1231 | } | ||
| 1232 | |||
| 1233 | =begin _private | ||
| 1234 | |||
| 1235 | =item _invokant | ||
| 1236 | |||
| 1237 | Does a heuristic on the stack to see who called us for more intelligent | ||
| 1238 | error messages. Currently assumes we will be called only by Module::Build | ||
| 1239 | or by ExtUtils::MakeMaker. | ||
| 1240 | |||
| 1241 | =end _private | ||
| 1242 | |||
| 1243 | =cut | ||
| 1244 | |||
| 1245 | sub _invokant { | ||
| 1246 | my @stack; | ||
| 1247 | my $frame = 0; | ||
| 1248 | while (my $file = (caller($frame++))[1]) { | ||
| 1249 | push @stack, (File::Spec->splitpath($file))[2]; | ||
| 1250 | } | ||
| 1251 | |||
| 1252 | my $builder; | ||
| 1253 | my $top = pop @stack; | ||
| 1254 | if ($top =~ /^Build/i || exists($INC{'Module/Build.pm'})) { | ||
| 1255 | $builder = 'Module::Build'; | ||
| 1256 | } else { | ||
| 1257 | $builder = 'ExtUtils::MakeMaker'; | ||
| 1258 | } | ||
| 1259 | return $builder; | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | =pod | ||
| 1263 | |||
| 1264 | =back | ||
| 1265 | |||
| 1266 | =head1 ENVIRONMENT | ||
| 1267 | |||
| 1268 | =over 4 | ||
| 1269 | |||
| 1270 | =item B<PERL_INSTALL_ROOT> | ||
| 1271 | |||
| 1272 | Will be prepended to each install path. | ||
| 1273 | |||
| 1274 | =item B<EU_INSTALL_IGNORE_SKIP> | ||
| 1275 | |||
| 1276 | Will prevent the automatic use of INSTALL.SKIP as the install skip file. | ||
| 1277 | |||
| 1278 | =item B<EU_INSTALL_SITE_SKIPFILE> | ||
| 1279 | |||
| 1280 | If there is no INSTALL.SKIP file in the make directory then this value | ||
| 1281 | can be used to provide a default. | ||
| 1282 | |||
| 1283 | =item B<EU_INSTALL_ALWAYS_COPY> | ||
| 1284 | |||
| 1285 | If this environment variable is true then normal install processes will | ||
| 1286 | always overwrite older identical files during the install process. | ||
| 1287 | |||
| 1288 | Note that the alias EU_ALWAYS_COPY will be supported if EU_INSTALL_ALWAYS_COPY | ||
| 1289 | is not defined until at least the 1.50 release. Please ensure you use the | ||
| 1290 | correct EU_INSTALL_ALWAYS_COPY. | ||
| 1291 | |||
| 1292 | =back | ||
| 1293 | |||
| 1294 | =head1 AUTHOR | ||
| 1295 | |||
| 1296 | Original author lost in the mists of time. Probably the same as Makemaker. | ||
| 1297 | |||
| 1298 | Production release currently maintained by demerphq C<yves at cpan.org>, | ||
| 1299 | extensive changes by Michael G. Schwern. | ||
| 1300 | |||
| 1301 | Send bug reports via http://rt.cpan.org/. Please send your | ||
| 1302 | generated Makefile along with your report. | ||
| 1303 | |||
| 1304 | =head1 LICENSE | ||
| 1305 | |||
| 1306 | This program is free software; you can redistribute it and/or | ||
| 1307 | modify it under the same terms as Perl itself. | ||
| 1308 | |||
| 1309 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||
| 1310 | |||
| 1311 | |||
| 1312 | =cut | ||
| 1313 | |||
| 1314 | 1; |