Commit | Line | Data |
---|---|---|
005c1a0e AD |
1 | package ExtUtils::Manifest; |
2 | ||
005c1a0e | 3 | require Exporter; |
8e07c86e | 4 | use Config; |
5dca256e | 5 | use File::Basename; |
79dd614e | 6 | use File::Copy 'copy'; |
5dca256e | 7 | use File::Find; |
57b1a898 | 8 | use File::Spec; |
005c1a0e | 9 | use Carp; |
8a1da95f | 10 | use strict; |
11 | ||
57b1a898 MS |
12 | use vars qw($VERSION @ISA @EXPORT_OK |
13 | $Is_MacOS $Is_VMS | |
14 | $Debug $Verbose $Quiet $MANIFEST $DEFAULT_MSKIP); | |
8a1da95f | 15 | |
a2fa79ff | 16 | $VERSION = '1.51_01'; |
8a1da95f | 17 | @ISA=('Exporter'); |
479d2113 MS |
18 | @EXPORT_OK = qw(mkmanifest |
19 | manicheck filecheck fullcheck skipcheck | |
20 | manifind maniread manicopy maniadd | |
21 | ); | |
005c1a0e | 22 | |
db5fd395 | 23 | $Is_MacOS = $^O eq 'MacOS'; |
479d2113 | 24 | $Is_VMS = $^O eq 'VMS'; |
f6d6199c | 25 | require VMS::Filespec if $Is_VMS; |
005c1a0e | 26 | |
479d2113 | 27 | $Debug = $ENV{PERL_MM_MANIFEST_DEBUG} || 0; |
75e2e551 MS |
28 | $Verbose = defined $ENV{PERL_MM_MANIFEST_VERBOSE} ? |
29 | $ENV{PERL_MM_MANIFEST_VERBOSE} : 1; | |
005c1a0e | 30 | $Quiet = 0; |
cb1a09d0 | 31 | $MANIFEST = 'MANIFEST'; |
479d2113 | 32 | |
5dca256e | 33 | $DEFAULT_MSKIP = File::Spec->catfile( dirname(__FILE__), "$MANIFEST.SKIP" ); |
4e68a208 | 34 | |
479d2113 MS |
35 | |
36 | =head1 NAME | |
37 | ||
38 | ExtUtils::Manifest - utilities to write and check a MANIFEST file | |
39 | ||
40 | =head1 SYNOPSIS | |
41 | ||
42 | use ExtUtils::Manifest qw(...funcs to import...); | |
43 | ||
44 | mkmanifest(); | |
45 | ||
46 | my @missing_files = manicheck; | |
47 | my @skipped = skipcheck; | |
48 | my @extra_files = filecheck; | |
49 | my($missing, $extra) = fullcheck; | |
50 | ||
51 | my $found = manifind(); | |
52 | ||
53 | my $manifest = maniread(); | |
54 | ||
55 | manicopy($read,$target); | |
56 | ||
57 | maniadd({$file => $comment, ...}); | |
58 | ||
59 | ||
60 | =head1 DESCRIPTION | |
61 | ||
62 | =head2 Functions | |
63 | ||
64 | ExtUtils::Manifest exports no functions by default. The following are | |
65 | exported on request | |
66 | ||
67 | =over 4 | |
68 | ||
69 | =item mkmanifest | |
70 | ||
71 | mkmanifest(); | |
72 | ||
73 | Writes all files in and below the current directory to your F<MANIFEST>. | |
74 | It works similar to | |
75 | ||
76 | find . > MANIFEST | |
77 | ||
78 | All files that match any regular expression in a file F<MANIFEST.SKIP> | |
79 | (if it exists) are ignored. | |
80 | ||
81 | Any existing F<MANIFEST> file will be saved as F<MANIFEST.bak>. Lines | |
82 | from the old F<MANIFEST> file is preserved, including any comments | |
83 | that are found in the existing F<MANIFEST> file in the new one. | |
84 | ||
85 | =cut | |
86 | ||
dedf98bc MS |
87 | sub _sort { |
88 | return sort { lc $a cmp lc $b } @_; | |
89 | } | |
90 | ||
005c1a0e AD |
91 | sub mkmanifest { |
92 | my $manimiss = 0; | |
0300da75 | 93 | my $read = (-r 'MANIFEST' && maniread()) or $manimiss++; |
005c1a0e | 94 | $read = {} if $manimiss; |
864a5fa8 | 95 | local *M; |
a2fa79ff CB |
96 | my $bakbase = $MANIFEST; |
97 | $bakbase =~ s/\./_/g if $Is_VMS; # avoid double dots | |
98 | rename $MANIFEST, "$bakbase.bak" unless $manimiss; | |
cb1a09d0 | 99 | open M, ">$MANIFEST" or die "Could not open $MANIFEST: $!"; |
f6d6199c | 100 | my $skip = _maniskip(); |
005c1a0e AD |
101 | my $found = manifind(); |
102 | my($key,$val,$file,%all); | |
f1387719 | 103 | %all = (%$found, %$read); |
84876ac5 | 104 | $all{$MANIFEST} = ($Is_VMS ? "$MANIFEST\t\t" : '') . 'This list of files' |
105 | if $manimiss; # add new MANIFEST to known file list | |
dedf98bc | 106 | foreach $file (_sort keys %all) { |
f6d6199c MS |
107 | if ($skip->($file)) { |
108 | # Policy: only remove files if they're listed in MANIFEST.SKIP. | |
109 | # Don't remove files just because they don't exist. | |
110 | warn "Removed from $MANIFEST: $file\n" if $Verbose and exists $read->{$file}; | |
111 | next; | |
112 | } | |
005c1a0e | 113 | if ($Verbose){ |
cb1a09d0 | 114 | warn "Added to $MANIFEST: $file\n" unless exists $read->{$file}; |
005c1a0e | 115 | } |
8e07c86e | 116 | my $text = $all{$file}; |
db5fd395 | 117 | $file = _unmacify($file); |
005c1a0e AD |
118 | my $tabs = (5 - (length($file)+1)/8); |
119 | $tabs = 1 if $tabs < 1; | |
8e07c86e AD |
120 | $tabs = 0 unless $text; |
121 | print M $file, "\t" x $tabs, $text, "\n"; | |
005c1a0e AD |
122 | } |
123 | close M; | |
124 | } | |
125 | ||
f6d6199c MS |
126 | # Geez, shouldn't this use File::Spec or File::Basename or something? |
127 | # Why so careful about dependencies? | |
128 | sub clean_up_filename { | |
129 | my $filename = shift; | |
130 | $filename =~ s|^\./||; | |
131 | $filename =~ s/^:([^:]+)$/$1/ if $Is_MacOS; | |
132 | return $filename; | |
133 | } | |
134 | ||
479d2113 MS |
135 | |
136 | =item manifind | |
137 | ||
138 | my $found = manifind(); | |
139 | ||
140 | returns a hash reference. The keys of the hash are the files found | |
141 | below the current directory. | |
142 | ||
143 | =cut | |
144 | ||
005c1a0e | 145 | sub manifind { |
f6d6199c | 146 | my $p = shift || {}; |
f6d6199c MS |
147 | my $found = {}; |
148 | ||
149 | my $wanted = sub { | |
150 | my $name = clean_up_filename($File::Find::name); | |
151 | warn "Debug: diskfile $name\n" if $Debug; | |
57b1a898 | 152 | return if -d $_; |
f6d6199c MS |
153 | |
154 | if( $Is_VMS ) { | |
155 | $name =~ s#(.*)\.$#\L$1#; | |
156 | $name = uc($name) if $name =~ /^MANIFEST(\.SKIP)?$/i; | |
157 | } | |
158 | $found->{$name} = ""; | |
159 | }; | |
160 | ||
161 | # We have to use "$File::Find::dir/$_" in preprocess, because | |
162 | # $File::Find::name is unavailable. | |
163 | # Also, it's okay to use / here, because MANIFEST files use Unix-style | |
164 | # paths. | |
57b1a898 | 165 | find({wanted => $wanted}, |
f6d6199c MS |
166 | $Is_MacOS ? ":" : "."); |
167 | ||
168 | return $found; | |
005c1a0e AD |
169 | } |
170 | ||
479d2113 MS |
171 | |
172 | =item manicheck | |
173 | ||
174 | my @missing_files = manicheck(); | |
175 | ||
176 | checks if all the files within a C<MANIFEST> in the current directory | |
177 | really do exist. If C<MANIFEST> and the tree below the current | |
2c91f887 | 178 | directory are in sync it silently returns an empty list. |
479d2113 MS |
179 | Otherwise it returns a list of files which are listed in the |
180 | C<MANIFEST> but missing from the directory, and by default also | |
181 | outputs these names to STDERR. | |
182 | ||
183 | =cut | |
005c1a0e AD |
184 | |
185 | sub manicheck { | |
45bc4d3a | 186 | return _check_files(); |
005c1a0e AD |
187 | } |
188 | ||
479d2113 MS |
189 | |
190 | =item filecheck | |
191 | ||
192 | my @extra_files = filecheck(); | |
193 | ||
194 | finds files below the current directory that are not mentioned in the | |
195 | C<MANIFEST> file. An optional file C<MANIFEST.SKIP> will be | |
196 | consulted. Any file matching a regular expression in such a file will | |
197 | not be reported as missing in the C<MANIFEST> file. The list of any | |
198 | extraneous files found is returned, and by default also reported to | |
199 | STDERR. | |
200 | ||
201 | =cut | |
202 | ||
005c1a0e | 203 | sub filecheck { |
45bc4d3a | 204 | return _check_manifest(); |
005c1a0e AD |
205 | } |
206 | ||
479d2113 MS |
207 | |
208 | =item fullcheck | |
209 | ||
210 | my($missing, $extra) = fullcheck(); | |
211 | ||
212 | does both a manicheck() and a filecheck(), returning then as two array | |
213 | refs. | |
214 | ||
215 | =cut | |
216 | ||
217 | sub fullcheck { | |
218 | return [_check_files()], [_check_manifest()]; | |
219 | } | |
220 | ||
221 | ||
222 | =item skipcheck | |
223 | ||
224 | my @skipped = skipcheck(); | |
225 | ||
226 | lists all the files that are skipped due to your C<MANIFEST.SKIP> | |
227 | file. | |
228 | ||
229 | =cut | |
230 | ||
8e07c86e | 231 | sub skipcheck { |
45bc4d3a JH |
232 | my($p) = @_; |
233 | my $found = manifind(); | |
234 | my $matches = _maniskip(); | |
235 | ||
236 | my @skipped = (); | |
dedf98bc | 237 | foreach my $file (_sort keys %$found){ |
45bc4d3a JH |
238 | if (&$matches($file)){ |
239 | warn "Skipping $file\n"; | |
240 | push @skipped, $file; | |
241 | next; | |
242 | } | |
243 | } | |
244 | ||
245 | return @skipped; | |
8e07c86e AD |
246 | } |
247 | ||
f6d6199c | 248 | |
45bc4d3a JH |
249 | sub _check_files { |
250 | my $p = shift; | |
39e571d4 | 251 | my $dosnames=(defined(&Dos::UseLFN) && Dos::UseLFN()==0); |
45bc4d3a JH |
252 | my $read = maniread() || {}; |
253 | my $found = manifind($p); | |
254 | ||
255 | my(@missfile) = (); | |
dedf98bc | 256 | foreach my $file (_sort keys %$read){ |
45bc4d3a JH |
257 | warn "Debug: manicheck checking from $MANIFEST $file\n" if $Debug; |
258 | if ($dosnames){ | |
259 | $file = lc $file; | |
260 | $file =~ s=(\.(\w|-)+)=substr ($1,0,4)=ge; | |
261 | $file =~ s=((\w|-)+)=substr ($1,0,8)=ge; | |
262 | } | |
263 | unless ( exists $found->{$file} ) { | |
264 | warn "No such file: $file\n" unless $Quiet; | |
265 | push @missfile, $file; | |
266 | } | |
005c1a0e | 267 | } |
45bc4d3a JH |
268 | |
269 | return @missfile; | |
270 | } | |
271 | ||
272 | ||
273 | sub _check_manifest { | |
274 | my($p) = @_; | |
275 | my $read = maniread() || {}; | |
276 | my $found = manifind($p); | |
277 | my $skip = _maniskip(); | |
278 | ||
279 | my @missentry = (); | |
dedf98bc | 280 | foreach my $file (_sort keys %$found){ |
45bc4d3a JH |
281 | next if $skip->($file); |
282 | warn "Debug: manicheck checking from disk $file\n" if $Debug; | |
283 | unless ( exists $read->{$file} ) { | |
284 | my $canon = $Is_MacOS ? "\t" . _unmacify($file) : ''; | |
285 | warn "Not in $MANIFEST: $file$canon\n" unless $Quiet; | |
286 | push @missentry, $file; | |
287 | } | |
005c1a0e | 288 | } |
45bc4d3a JH |
289 | |
290 | return @missentry; | |
005c1a0e AD |
291 | } |
292 | ||
45bc4d3a | 293 | |
479d2113 MS |
294 | =item maniread |
295 | ||
296 | my $manifest = maniread(); | |
297 | my $manifest = maniread($manifest_file); | |
298 | ||
299 | reads a named C<MANIFEST> file (defaults to C<MANIFEST> in the current | |
300 | directory) and returns a HASH reference with files being the keys and | |
301 | comments being the values of the HASH. Blank lines and lines which | |
302 | start with C<#> in the C<MANIFEST> file are discarded. | |
303 | ||
304 | =cut | |
305 | ||
005c1a0e AD |
306 | sub maniread { |
307 | my ($mfile) = @_; | |
15a074ca | 308 | $mfile ||= $MANIFEST; |
005c1a0e AD |
309 | my $read = {}; |
310 | local *M; | |
311 | unless (open M, $mfile){ | |
1c14aae0 | 312 | warn "Problem opening $mfile: $!"; |
2530b651 | 313 | return $read; |
005c1a0e | 314 | } |
2530b651 | 315 | local $_; |
005c1a0e | 316 | while (<M>){ |
2530b651 | 317 | chomp; |
1df8d179 | 318 | next if /^\s*#/; |
0e3309e2 MS |
319 | |
320 | my($file, $comment) = /^(\S+)\s*(.*)/; | |
321 | next unless $file; | |
322 | ||
2530b651 MS |
323 | if ($Is_MacOS) { |
324 | $file = _macify($file); | |
325 | $file =~ s/\\([0-3][0-7][0-7])/sprintf("%c", oct($1))/ge; | |
326 | } | |
327 | elsif ($Is_VMS) { | |
328 | require File::Basename; | |
329 | my($base,$dir) = File::Basename::fileparse($file); | |
330 | # Resolve illegal file specifications in the same way as tar | |
331 | $dir =~ tr/./_/; | |
332 | my(@pieces) = split(/\./,$base); | |
333 | if (@pieces > 2) { $base = shift(@pieces) . '.' . join('_',@pieces); } | |
334 | my $okfile = "$dir$base"; | |
335 | warn "Debug: Illegal name $file changed to $okfile\n" if $Debug; | |
349e1be1 | 336 | $file = $okfile; |
f6d6199c | 337 | $file = lc($file) unless $file =~ /^MANIFEST(\.SKIP)?$/; |
2530b651 | 338 | } |
0e3309e2 MS |
339 | |
340 | $read->{$file} = $comment; | |
005c1a0e AD |
341 | } |
342 | close M; | |
343 | $read; | |
344 | } | |
345 | ||
346 | # returns an anonymous sub that decides if an argument matches | |
347 | sub _maniskip { | |
005c1a0e | 348 | my @skip ; |
45bc4d3a | 349 | my $mfile = "$MANIFEST.SKIP"; |
1c14aae0 RGS |
350 | _check_mskip_directives($mfile) if -f $mfile; |
351 | local(*M, $_); | |
f6d6199c | 352 | open M, $mfile or open M, $DEFAULT_MSKIP or return sub {0}; |
005c1a0e AD |
353 | while (<M>){ |
354 | chomp; | |
b3217f3b | 355 | s/\r//; |
15a074ca | 356 | next if /^#/; |
005c1a0e | 357 | next if /^\s*$/; |
db5fd395 | 358 | push @skip, _macify($_); |
005c1a0e AD |
359 | } |
360 | close M; | |
b3217f3b SP |
361 | return sub {0} unless (scalar @skip > 0); |
362 | ||
f6d6199c MS |
363 | my $opts = $Is_VMS ? '(?i)' : ''; |
364 | ||
365 | # Make sure each entry is isolated in its own parentheses, in case | |
366 | # any of them contain alternations | |
367 | my $regex = join '|', map "(?:$_)", @skip; | |
368 | ||
45bc4d3a | 369 | return sub { $_[0] =~ qr{$opts$regex} }; |
005c1a0e AD |
370 | } |
371 | ||
1c14aae0 RGS |
372 | # checks for the special directives |
373 | # #!include_default | |
374 | # #!include /path/to/some/manifest.skip | |
375 | # in a custom MANIFEST.SKIP for, for including | |
376 | # the content of, respectively, the default MANIFEST.SKIP | |
377 | # and an external manifest.skip file | |
378 | sub _check_mskip_directives { | |
379 | my $mfile = shift; | |
380 | local (*M, $_); | |
381 | my @lines = (); | |
382 | my $flag = 0; | |
383 | unless (open M, $mfile) { | |
384 | warn "Problem opening $mfile: $!"; | |
385 | return; | |
386 | } | |
387 | while (<M>) { | |
388 | if (/^#!include_default\s*$/) { | |
389 | if (my @default = _include_mskip_file()) { | |
390 | push @lines, @default; | |
391 | warn "Debug: Including default MANIFEST.SKIP\n" if $Debug; | |
392 | $flag++; | |
393 | } | |
394 | next; | |
395 | } | |
396 | if (/^#!include\s+(.*)\s*$/) { | |
397 | my $external_file = $1; | |
398 | if (my @external = _include_mskip_file($external_file)) { | |
399 | push @lines, @external; | |
400 | warn "Debug: Including external $external_file\n" if $Debug; | |
401 | $flag++; | |
402 | } | |
403 | next; | |
404 | } | |
405 | push @lines, $_; | |
406 | } | |
407 | close M; | |
408 | return unless $flag; | |
a2fa79ff CB |
409 | my $bakbase = $mfile; |
410 | $bakbase =~ s/\./_/g if $Is_VMS; # avoid double dots | |
411 | rename $mfile, "$bakbase.bak"; | |
412 | warn "Debug: Saving original $mfile as $bakbase.bak\n" if $Debug; | |
1c14aae0 RGS |
413 | unless (open M, ">$mfile") { |
414 | warn "Problem opening $mfile: $!"; | |
415 | return; | |
416 | } | |
417 | print M $_ for (@lines); | |
418 | close M; | |
419 | return; | |
420 | } | |
421 | ||
422 | # returns an array containing the lines of an external | |
423 | # manifest.skip file, if given, or $DEFAULT_MSKIP | |
424 | sub _include_mskip_file { | |
425 | my $mskip = shift || $DEFAULT_MSKIP; | |
426 | unless (-f $mskip) { | |
427 | warn qq{Included file "$mskip" not found - skipping}; | |
428 | return; | |
429 | } | |
430 | local (*M, $_); | |
431 | unless (open M, $mskip) { | |
432 | warn "Problem opening $mskip: $!"; | |
433 | return; | |
434 | } | |
435 | my @lines = (); | |
436 | push @lines, "\n#!start included $mskip\n"; | |
437 | push @lines, $_ while <M>; | |
438 | close M; | |
439 | push @lines, "#!end included $mskip\n\n"; | |
440 | return @lines; | |
441 | } | |
442 | ||
479d2113 MS |
443 | =item manicopy |
444 | ||
a7d1454b RGS |
445 | manicopy(\%src, $dest_dir); |
446 | manicopy(\%src, $dest_dir, $how); | |
479d2113 | 447 | |
a7d1454b RGS |
448 | Copies the files that are the keys in %src to the $dest_dir. %src is |
449 | typically returned by the maniread() function. | |
450 | ||
451 | manicopy( maniread(), $dest_dir ); | |
452 | ||
453 | This function is useful for producing a directory tree identical to the | |
454 | intended distribution tree. | |
455 | ||
456 | $how can be used to specify a different methods of "copying". Valid | |
479d2113 MS |
457 | values are C<cp>, which actually copies the files, C<ln> which creates |
458 | hard links, and C<best> which mostly links the files but copies any | |
a7d1454b | 459 | symbolic link to make a tree without any symbolic link. C<cp> is the |
479d2113 MS |
460 | default. |
461 | ||
462 | =cut | |
463 | ||
005c1a0e | 464 | sub manicopy { |
8e07c86e | 465 | my($read,$target,$how)=@_; |
005c1a0e | 466 | croak "manicopy() called without target argument" unless defined $target; |
15a074ca | 467 | $how ||= 'cp'; |
005c1a0e AD |
468 | require File::Path; |
469 | require File::Basename; | |
57b1a898 | 470 | |
8e07c86e | 471 | $target = VMS::Filespec::unixify($target) if $Is_VMS; |
553c0e07 | 472 | File::Path::mkpath([ $target ],! $Quiet,$Is_VMS ? undef : 0755); |
57b1a898 | 473 | foreach my $file (keys %$read){ |
db5fd395 CN |
474 | if ($Is_MacOS) { |
475 | if ($file =~ m!:!) { | |
476 | my $dir = _maccat($target, $file); | |
477 | $dir =~ s/[^:]+$//; | |
478 | File::Path::mkpath($dir,1,0755); | |
479 | } | |
480 | cp_if_diff($file, _maccat($target, $file), $how); | |
481 | } else { | |
482 | $file = VMS::Filespec::unixify($file) if $Is_VMS; | |
483 | if ($file =~ m!/!) { # Ilya, that hurts, I fear, or maybe not? | |
484 | my $dir = File::Basename::dirname($file); | |
485 | $dir = VMS::Filespec::unixify($dir) if $Is_VMS; | |
486 | File::Path::mkpath(["$target/$dir"],! $Quiet,$Is_VMS ? undef : 0755); | |
487 | } | |
488 | cp_if_diff($file, "$target/$file", $how); | |
84876ac5 | 489 | } |
005c1a0e AD |
490 | } |
491 | } | |
492 | ||
493 | sub cp_if_diff { | |
8a1da95f | 494 | my($from, $to, $how)=@_; |
15a074ca | 495 | -f $from or carp "$0: $from not found"; |
8e07c86e AD |
496 | my($diff) = 0; |
497 | local(*F,*T); | |
57b1a898 | 498 | open(F,"< $from\0") or die "Can't read $from: $!\n"; |
db5fd395 | 499 | if (open(T,"< $to\0")) { |
2530b651 | 500 | local $_; |
8e07c86e AD |
501 | while (<F>) { $diff++,last if $_ ne <T>; } |
502 | $diff++ unless eof(T); | |
503 | close T; | |
504 | } | |
505 | else { $diff++; } | |
506 | close F; | |
507 | if ($diff) { | |
508 | if (-e $to) { | |
509 | unlink($to) or confess "unlink $to: $!"; | |
510 | } | |
7292dc67 | 511 | STRICT_SWITCH: { |
15a074ca A |
512 | best($from,$to), last STRICT_SWITCH if $how eq 'best'; |
513 | cp($from,$to), last STRICT_SWITCH if $how eq 'cp'; | |
514 | ln($from,$to), last STRICT_SWITCH if $how eq 'ln'; | |
515 | croak("ExtUtils::Manifest::cp_if_diff " . | |
516 | "called with illegal how argument [$how]. " . | |
517 | "Legal values are 'best', 'cp', and 'ln'."); | |
518 | } | |
8e07c86e AD |
519 | } |
520 | } | |
521 | ||
8e07c86e AD |
522 | sub cp { |
523 | my ($srcFile, $dstFile) = @_; | |
a7d1454b RGS |
524 | my ($access,$mod) = (stat $srcFile)[8,9]; |
525 | ||
79dd614e | 526 | copy($srcFile,$dstFile); |
9607fc9c | 527 | utime $access, $mod + ($Is_VMS ? 1 : 0), $dstFile; |
1c14aae0 | 528 | _manicopy_chmod($srcFile, $dstFile); |
8e07c86e AD |
529 | } |
530 | ||
a7d1454b | 531 | |
8e07c86e AD |
532 | sub ln { |
533 | my ($srcFile, $dstFile) = @_; | |
f0f13d0e | 534 | return &cp if $Is_VMS or ($^O eq 'MSWin32' and Win32::IsWin95()); |
8e07c86e | 535 | link($srcFile, $dstFile); |
57b1a898 | 536 | |
1c14aae0 | 537 | unless( _manicopy_chmod($srcFile, $dstFile) ) { |
57b1a898 MS |
538 | unlink $dstFile; |
539 | return; | |
4e6ea2c3 GS |
540 | } |
541 | 1; | |
8e07c86e AD |
542 | } |
543 | ||
a7d1454b RGS |
544 | # 1) Strip off all group and world permissions. |
545 | # 2) Let everyone read it. | |
546 | # 3) If the owner can execute it, everyone can. | |
547 | sub _manicopy_chmod { | |
1c14aae0 | 548 | my($srcFile, $dstFile) = @_; |
57b1a898 | 549 | |
1c14aae0 RGS |
550 | my $perm = 0444 | (stat $srcFile)[2] & 0700; |
551 | chmod( $perm | ( $perm & 0100 ? 0111 : 0 ), $dstFile ); | |
a7d1454b | 552 | } |
57b1a898 | 553 | |
7292dc67 RGS |
554 | # Files that are often modified in the distdir. Don't hard link them. |
555 | my @Exceptions = qw(MANIFEST META.yml SIGNATURE); | |
4633a7c4 LW |
556 | sub best { |
557 | my ($srcFile, $dstFile) = @_; | |
7292dc67 RGS |
558 | |
559 | my $is_exception = grep $srcFile =~ /$_/, @Exceptions; | |
560 | if ($is_exception or !$Config{d_link} or -l $srcFile) { | |
4633a7c4 LW |
561 | cp($srcFile, $dstFile); |
562 | } else { | |
3dee4013 | 563 | ln($srcFile, $dstFile) or cp($srcFile, $dstFile); |
4633a7c4 LW |
564 | } |
565 | } | |
566 | ||
db5fd395 CN |
567 | sub _macify { |
568 | my($file) = @_; | |
569 | ||
570 | return $file unless $Is_MacOS; | |
a7d1454b | 571 | |
db5fd395 CN |
572 | $file =~ s|^\./||; |
573 | if ($file =~ m|/|) { | |
574 | $file =~ s|/+|:|g; | |
575 | $file = ":$file"; | |
576 | } | |
a7d1454b | 577 | |
db5fd395 CN |
578 | $file; |
579 | } | |
580 | ||
581 | sub _maccat { | |
582 | my($f1, $f2) = @_; | |
a7d1454b | 583 | |
db5fd395 | 584 | return "$f1/$f2" unless $Is_MacOS; |
a7d1454b | 585 | |
db5fd395 CN |
586 | $f1 .= ":$f2"; |
587 | $f1 =~ s/([^:]:):/$1/g; | |
588 | return $f1; | |
589 | } | |
590 | ||
591 | sub _unmacify { | |
592 | my($file) = @_; | |
593 | ||
594 | return $file unless $Is_MacOS; | |
5dca256e | 595 | |
db5fd395 CN |
596 | $file =~ s|^:||; |
597 | $file =~ s|([/ \n])|sprintf("\\%03o", unpack("c", $1))|ge; | |
598 | $file =~ y|:|/|; | |
5dca256e | 599 | |
db5fd395 CN |
600 | $file; |
601 | } | |
602 | ||
79dd614e | 603 | |
479d2113 | 604 | =item maniadd |
79dd614e | 605 | |
479d2113 | 606 | maniadd({ $file => $comment, ...}); |
79dd614e | 607 | |
1df8d179 | 608 | Adds an entry to an existing F<MANIFEST> unless its already there. |
79dd614e | 609 | |
479d2113 | 610 | $file will be normalized (ie. Unixified). B<UNIMPLEMENTED> |
79dd614e | 611 | |
479d2113 | 612 | =cut |
79dd614e | 613 | |
479d2113 MS |
614 | sub maniadd { |
615 | my($additions) = shift; | |
79dd614e | 616 | |
479d2113 | 617 | _normalize($additions); |
2530b651 | 618 | _fix_manifest($MANIFEST); |
79dd614e | 619 | |
479d2113 | 620 | my $manifest = maniread(); |
30361541 JH |
621 | my @needed = grep { !exists $manifest->{$_} } keys %$additions; |
622 | return 1 unless @needed; | |
1df8d179 | 623 | |
30361541 JH |
624 | open(MANIFEST, ">>$MANIFEST") or |
625 | die "maniadd() could not open $MANIFEST: $!"; | |
2c91f887 | 626 | |
30361541 | 627 | foreach my $file (_sort @needed) { |
dedf98bc | 628 | my $comment = $additions->{$file} || ''; |
30361541 | 629 | printf MANIFEST "%-40s %s\n", $file, $comment; |
479d2113 | 630 | } |
30361541 JH |
631 | close MANIFEST or die "Error closing $MANIFEST: $!"; |
632 | ||
633 | return 1; | |
479d2113 | 634 | } |
79dd614e | 635 | |
2530b651 MS |
636 | |
637 | # Sometimes MANIFESTs are missing a trailing newline. Fix this. | |
638 | sub _fix_manifest { | |
639 | my $manifest_file = shift; | |
640 | ||
641 | open MANIFEST, $MANIFEST or die "Could not open $MANIFEST: $!"; | |
642 | ||
643 | # Yes, we should be using seek(), but I'd like to avoid loading POSIX | |
644 | # to get SEEK_* | |
645 | my @manifest = <MANIFEST>; | |
646 | close MANIFEST; | |
647 | ||
648 | unless( $manifest[-1] =~ /\n\z/ ) { | |
649 | open MANIFEST, ">>$MANIFEST" or die "Could not open $MANIFEST: $!"; | |
650 | print MANIFEST "\n"; | |
651 | close MANIFEST; | |
652 | } | |
653 | } | |
5dca256e | 654 | |
2530b651 | 655 | |
479d2113 MS |
656 | # UNIMPLEMENTED |
657 | sub _normalize { | |
658 | return; | |
659 | } | |
79dd614e | 660 | |
79dd614e | 661 | |
479d2113 | 662 | =back |
79dd614e | 663 | |
479d2113 | 664 | =head2 MANIFEST |
79dd614e | 665 | |
5dca256e RGS |
666 | A list of files in the distribution, one file per line. The MANIFEST |
667 | always uses Unix filepath conventions even if you're not on Unix. This | |
668 | means F<foo/bar> style not F<foo\bar>. | |
669 | ||
479d2113 | 670 | Anything between white space and an end of line within a C<MANIFEST> |
5dca256e RGS |
671 | file is considered to be a comment. Any line beginning with # is also |
672 | a comment. | |
673 | ||
674 | # this a comment | |
675 | some/file | |
676 | some/other/file comment about some/file | |
79dd614e | 677 | |
79dd614e | 678 | |
479d2113 | 679 | =head2 MANIFEST.SKIP |
79dd614e | 680 | |
681 | The file MANIFEST.SKIP may contain regular expressions of files that | |
682 | should be ignored by mkmanifest() and filecheck(). The regular | |
15a074ca A |
683 | expressions should appear one on each line. Blank lines and lines |
684 | which start with C<#> are skipped. Use C<\#> if you need a regular | |
5dca256e RGS |
685 | expression to start with a C<#>. |
686 | ||
687 | For example: | |
79dd614e | 688 | |
0b9c804f | 689 | # Version control files and dirs. |
79dd614e | 690 | \bRCS\b |
0b9c804f MS |
691 | \bCVS\b |
692 | ,v$ | |
479d2113 | 693 | \B\.svn\b |
0b9c804f MS |
694 | |
695 | # Makemaker generated files and dirs. | |
79dd614e | 696 | ^MANIFEST\. |
697 | ^Makefile$ | |
79dd614e | 698 | ^blib/ |
699 | ^MakeMaker-\d | |
700 | ||
0b9c804f MS |
701 | # Temp, old and emacs backup files. |
702 | ~$ | |
703 | \.old$ | |
704 | ^#.*#$ | |
cfcce72b | 705 | ^\.# |
0b9c804f MS |
706 | |
707 | If no MANIFEST.SKIP file is found, a default set of skips will be | |
708 | used, similar to the example above. If you want nothing skipped, | |
709 | simply make an empty MANIFEST.SKIP file. | |
710 | ||
1c14aae0 RGS |
711 | In one's own MANIFEST.SKIP file, certain directives |
712 | can be used to include the contents of other MANIFEST.SKIP | |
713 | files. At present two such directives are recognized. | |
714 | ||
715 | =over 4 | |
716 | ||
717 | =item #!include_default | |
718 | ||
719 | This inserts the contents of the default MANIFEST.SKIP file | |
720 | ||
721 | =item #!include /Path/to/another/manifest.skip | |
722 | ||
723 | This inserts the contents of the specified external file | |
724 | ||
725 | =back | |
726 | ||
727 | The included contents will be inserted into the MANIFEST.SKIP | |
728 | file in between I<#!start included /path/to/manifest.skip> | |
729 | and I<#!end included /path/to/manifest.skip> markers. | |
730 | The original MANIFEST.SKIP is saved as MANIFEST.SKIP.bak. | |
0b9c804f | 731 | |
479d2113 | 732 | =head2 EXPORT_OK |
79dd614e | 733 | |
734 | C<&mkmanifest>, C<&manicheck>, C<&filecheck>, C<&fullcheck>, | |
735 | C<&maniread>, and C<&manicopy> are exportable. | |
736 | ||
479d2113 | 737 | =head2 GLOBAL VARIABLES |
79dd614e | 738 | |
739 | C<$ExtUtils::Manifest::MANIFEST> defaults to C<MANIFEST>. Changing it | |
740 | results in both a different C<MANIFEST> and a different | |
741 | C<MANIFEST.SKIP> file. This is useful if you want to maintain | |
742 | different distributions for different audiences (say a user version | |
743 | and a developer version including RCS). | |
744 | ||
81ff29e3 | 745 | C<$ExtUtils::Manifest::Quiet> defaults to 0. If set to a true value, |
79dd614e | 746 | all functions act silently. |
747 | ||
0b9c804f MS |
748 | C<$ExtUtils::Manifest::Debug> defaults to 0. If set to a true value, |
749 | or if PERL_MM_MANIFEST_DEBUG is true, debugging output will be | |
750 | produced. | |
751 | ||
79dd614e | 752 | =head1 DIAGNOSTICS |
753 | ||
754 | All diagnostic output is sent to C<STDERR>. | |
755 | ||
bbc7dcd2 | 756 | =over 4 |
79dd614e | 757 | |
758 | =item C<Not in MANIFEST:> I<file> | |
759 | ||
45bc4d3a JH |
760 | is reported if a file is found which is not in C<MANIFEST>. |
761 | ||
762 | =item C<Skipping> I<file> | |
763 | ||
764 | is reported if a file is skipped due to an entry in C<MANIFEST.SKIP>. | |
79dd614e | 765 | |
766 | =item C<No such file:> I<file> | |
767 | ||
768 | is reported if a file mentioned in a C<MANIFEST> file does not | |
769 | exist. | |
770 | ||
771 | =item C<MANIFEST:> I<$!> | |
772 | ||
773 | is reported if C<MANIFEST> could not be opened. | |
774 | ||
775 | =item C<Added to MANIFEST:> I<file> | |
776 | ||
777 | is reported by mkmanifest() if $Verbose is set and a file is added | |
778 | to MANIFEST. $Verbose is set to 1 by default. | |
779 | ||
780 | =back | |
781 | ||
0b9c804f MS |
782 | =head1 ENVIRONMENT |
783 | ||
784 | =over 4 | |
785 | ||
786 | =item B<PERL_MM_MANIFEST_DEBUG> | |
787 | ||
788 | Turns on debugging | |
789 | ||
790 | =back | |
791 | ||
79dd614e | 792 | =head1 SEE ALSO |
793 | ||
794 | L<ExtUtils::MakeMaker> which has handy targets for most of the functionality. | |
795 | ||
796 | =head1 AUTHOR | |
797 | ||
a7d1454b RGS |
798 | Andreas Koenig C<andreas.koenig@anima.de> |
799 | ||
4c857482 SP |
800 | Maintained by Michael G Schwern C<schwern@pobox.com> within the |
801 | ExtUtils-MakeMaker package and, as a separate CPAN package, by | |
802 | Randy Kobes C<r.kobes@uwinnipeg.ca>. | |
79dd614e | 803 | |
804 | =cut | |
479d2113 MS |
805 | |
806 | 1; |