From: Rafael Garcia-Suarez Date: Fri, 12 Jan 2007 11:44:04 +0000 (+0000) Subject: Upgrade to ExtUtils::Manifest 1.51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c14aae0b07e7d831ac07cadc1b3a73ceba9637c;p=p5sagit%2Fp5-mst-13.2.git Upgrade to ExtUtils::Manifest 1.51 p4raw-id: //depot/perl@29768 --- diff --git a/lib/ExtUtils/Manifest.pm b/lib/ExtUtils/Manifest.pm index 70c1ef8..f3459ae 100644 --- a/lib/ExtUtils/Manifest.pm +++ b/lib/ExtUtils/Manifest.pm @@ -13,7 +13,7 @@ use vars qw($VERSION @ISA @EXPORT_OK $Is_MacOS $Is_VMS $Debug $Verbose $Quiet $MANIFEST $DEFAULT_MSKIP); -$VERSION = '1.49'; +$VERSION = '1.51'; @ISA=('Exporter'); @EXPORT_OK = qw(mkmanifest manicheck filecheck fullcheck skipcheck @@ -308,7 +308,7 @@ sub maniread { my $read = {}; local *M; unless (open M, $mfile){ - warn "$mfile: $!"; + warn "Problem opening $mfile: $!"; return $read; } local $_; @@ -346,7 +346,8 @@ sub maniread { sub _maniskip { my @skip ; my $mfile = "$MANIFEST.SKIP"; - local(*M,$_); + _check_mskip_directives($mfile) if -f $mfile; + local(*M, $_); open M, $mfile or open M, $DEFAULT_MSKIP or return sub {0}; while (){ chomp; @@ -367,6 +368,75 @@ sub _maniskip { return sub { $_[0] =~ qr{$opts$regex} }; } +# checks for the special directives +# #!include_default +# #!include /path/to/some/manifest.skip +# in a custom MANIFEST.SKIP for, for including +# the content of, respectively, the default MANIFEST.SKIP +# and an external manifest.skip file +sub _check_mskip_directives { + my $mfile = shift; + local (*M, $_); + my @lines = (); + my $flag = 0; + unless (open M, $mfile) { + warn "Problem opening $mfile: $!"; + return; + } + while () { + if (/^#!include_default\s*$/) { + if (my @default = _include_mskip_file()) { + push @lines, @default; + warn "Debug: Including default MANIFEST.SKIP\n" if $Debug; + $flag++; + } + next; + } + if (/^#!include\s+(.*)\s*$/) { + my $external_file = $1; + if (my @external = _include_mskip_file($external_file)) { + push @lines, @external; + warn "Debug: Including external $external_file\n" if $Debug; + $flag++; + } + next; + } + push @lines, $_; + } + close M; + return unless $flag; + rename $mfile, "$mfile.bak"; + warn "Debug: Saving original $mfile as $mfile.bak\n" if $Debug; + unless (open M, ">$mfile") { + warn "Problem opening $mfile: $!"; + return; + } + print M $_ for (@lines); + close M; + return; +} + +# returns an array containing the lines of an external +# manifest.skip file, if given, or $DEFAULT_MSKIP +sub _include_mskip_file { + my $mskip = shift || $DEFAULT_MSKIP; + unless (-f $mskip) { + warn qq{Included file "$mskip" not found - skipping}; + return; + } + local (*M, $_); + unless (open M, $mskip) { + warn "Problem opening $mskip: $!"; + return; + } + my @lines = (); + push @lines, "\n#!start included $mskip\n"; + push @lines, $_ while ; + close M; + push @lines, "#!end included $mskip\n\n"; + return @lines; +} + =item manicopy manicopy(\%src, $dest_dir); @@ -452,7 +522,7 @@ sub cp { copy($srcFile,$dstFile); utime $access, $mod + ($Is_VMS ? 1 : 0), $dstFile; - _manicopy_chmod($dstFile); + _manicopy_chmod($srcFile, $dstFile); } @@ -461,7 +531,7 @@ sub ln { return &cp if $Is_VMS or ($^O eq 'MSWin32' and Win32::IsWin95()); link($srcFile, $dstFile); - unless( _manicopy_chmod($dstFile) ) { + unless( _manicopy_chmod($srcFile, $dstFile) ) { unlink $dstFile; return; } @@ -472,10 +542,10 @@ sub ln { # 2) Let everyone read it. # 3) If the owner can execute it, everyone can. sub _manicopy_chmod { - my($file) = shift; + my($srcFile, $dstFile) = @_; - my $perm = 0444 | (stat $file)[2] & 0700; - chmod( $perm | ( $perm & 0100 ? 0111 : 0 ), $file ); + my $perm = 0444 | (stat $srcFile)[2] & 0700; + chmod( $perm | ( $perm & 0100 ? 0111 : 0 ), $dstFile ); } # Files that are often modified in the distdir. Don't hard link them. @@ -635,6 +705,26 @@ If no MANIFEST.SKIP file is found, a default set of skips will be used, similar to the example above. If you want nothing skipped, simply make an empty MANIFEST.SKIP file. +In one's own MANIFEST.SKIP file, certain directives +can be used to include the contents of other MANIFEST.SKIP +files. At present two such directives are recognized. + +=over 4 + +=item #!include_default + +This inserts the contents of the default MANIFEST.SKIP file + +=item #!include /Path/to/another/manifest.skip + +This inserts the contents of the specified external file + +=back + +The included contents will be inserted into the MANIFEST.SKIP +file in between I<#!start included /path/to/manifest.skip> +and I<#!end included /path/to/manifest.skip> markers. +The original MANIFEST.SKIP is saved as MANIFEST.SKIP.bak. =head2 EXPORT_OK diff --git a/lib/ExtUtils/t/Manifest.t b/lib/ExtUtils/t/Manifest.t index a546bc1..c11c944 100644 --- a/lib/ExtUtils/t/Manifest.t +++ b/lib/ExtUtils/t/Manifest.t @@ -13,12 +13,13 @@ chdir 't'; use strict; -use Test::More tests => 49; +use Test::More tests => 66; use Cwd; use File::Spec; use File::Path; use File::Find; +use Config; my $Is_VMS = $^O eq 'VMS'; @@ -71,6 +72,12 @@ ok( mkdir( 'mantest', 0777 ), 'make mantest directory' ); ok( chdir( 'mantest' ), 'chdir() to mantest' ); ok( add_file('foo'), 'add a temporary file' ); +# This ensures the -x check for manicopy means something +# Some platforms don't have chmod or an executable bit, in which case +# this call will do nothing or fail, but on the platforms where chmod() +# works, we test the executable bit is copied +chmod( 0744, 'foo') if $Config{'chmod'}; + # there shouldn't be a MANIFEST there my ($res, $warn) = catch_warning( \&mkmanifest ); # Canonize the order. @@ -211,6 +218,40 @@ is( $files->{wibble}, '', 'maniadd() with undef comment' ); is( $files->{yarrow}, 'hock',' with comment' ); is( $files->{foobar}, '', ' preserved old entries' ); +# test including an external manifest.skip file in MANIFEST.SKIP +{ + maniadd({ foo => undef , albatross => undef, + 'mymanifest.skip' => undef, 'mydefault.skip' => undef}); + add_file('mymanifest.skip' => "^foo\n"); + add_file('mydefault.skip' => "^my\n"); + $ExtUtils::Manifest::DEFAULT_MSKIP = + File::Spec->catfile($cwd, qw(mantest mydefault.skip)); + my $skip = File::Spec->catfile($cwd, qw(mantest mymanifest.skip)); + add_file('MANIFEST.SKIP' => + "albatross\n#!include $skip\n#!include_default"); + my ($res, $warn) = catch_warning( \&skipcheck ); + for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { + like( $warn, qr/Skipping \b$_\b/, + "Skipping $_" ); + } + ($res, $warn) = catch_warning( \&mkmanifest ); + for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { + like( $warn, qr/Removed from MANIFEST: \b$_\b/, + "Removed $_ from MANIFEST" ); + } + my $files = maniread; + ok( ! exists $files->{albatross}, 'albatross excluded via MANIFEST.SKIP' ); + ok( exists $files->{yarrow}, 'yarrow included in MANIFEST' ); + ok( exists $files->{bar}, 'bar included in MANIFEST' ); + ok( ! exists $files->{foobar}, 'foobar excluded via mymanifest.skip' ); + ok( ! exists $files->{foo}, 'foo excluded via mymanifest.skip' ); + ok( ! exists $files->{'mymanifest.skip'}, + 'mymanifest.skip excluded via mydefault.skip' ); + ok( ! exists $files->{'mydefault.skip'}, + 'mydefault.skip excluded via mydefault.skip' ); + $Files{"$_.bak"}++ for (qw(MANIFEST MANIFEST.SKIP)); +} + add_file('MANIFEST' => 'Makefile.PL'); maniadd({ foo => 'bar' }); $files = maniread; @@ -221,8 +262,8 @@ my %expect = ( 'makefile.pl' => '', ); is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline'); -add_file('MANIFEST' => 'Makefile.PL'); -maniadd({ foo => 'bar' }); +#add_file('MANIFEST' => 'Makefile.PL'); +#maniadd({ foo => 'bar' }); SKIP: { chmod( 0400, 'MANIFEST' );