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