forked from parrot/parrot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manicheck.pl
126 lines (98 loc) · 2.41 KB
/
manicheck.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl -w
#
# manicheck.pl
#
# Check the contents of the MANIFEST file against the files present in
# this directory tree, accounting for CVS ignore files.
#
use strict;
my @base_patterns = qw(^core$ ^.*\.o$); # CVS built-in patterns
use ExtUtils::Manifest;
my $manifest = ExtUtils::Manifest::maniread();
my $filelist = ExtUtils::Manifest::manifind();
my @ignore_dirs = grep { m#(^|/)\.cvsignore$#; } keys %$filelist;
@ignore_dirs = map { s#(^|/)\.cvsignore$##; $_ } @ignore_dirs;
my %ignore_dirs;
foreach my $dir (@ignore_dirs) {
my $cvsignore = $dir ne '' ? "$dir/.cvsignore" : '.cvsignore';
open CVSIGNORE, "<$cvsignore" or die "Could not open $cvsignore.\n";
my @patterns = <CVSIGNORE>;
close CVSIGNORE;
@patterns = map { chomp; s/\*/.*/g; "^$_\$"; } @patterns;
$ignore_dirs{$dir} = [ @patterns, @base_patterns ];
}
my %matches;
foreach (keys %$filelist) { $matches{$_}++; }
foreach (keys %$manifest) { $matches{$_}--; }
my @missing;
my @expected;
my @ignored;
my @extra;
printf "Found %d distinct files among MANIFEST and directory contents.\n\n",
scalar(keys %matches);
foreach (sort keys %matches) {
if ($matches{$_} < 0) {
push @missing, $_;
} elsif ($matches{$_} == 0) {
push @expected, $_;
} elsif (ignore($_)) {
push @ignored, $_;
} else {
push @extra, $_;
}
}
printf " %5d missing\n", scalar @missing;
printf " %5d expected\n", scalar @expected;
printf " %5d ignored\n", scalar @ignored;
printf " %5d extra\n", scalar @extra;
if (@missing) {
print "\n";
print "Missing files:\n";
foreach (@missing) {
print " $_\n";
}
}
#if (@expected) {
# print "\n";
# print "Expected files:\n";
# foreach (@expected) {
# print " $_\n";
# }
#}
#if (@ignored) {
# print "\n";
# print "Ignored files:\n";
# foreach (@ignored) {
# print " $_\n";
# }
#}
if (@extra) {
print "\n";
print "Extra files:\n";
foreach (@extra) {
print " $_\n";
}
}
exit scalar(@missing) or scalar(@extra) ? 1 : 0;
sub ignore
{
my $file = shift;
my $dir;
if ($file =~ m|/|) {
($dir, $file) = m/^(.*)\/(.*)$/;
} else {
$dir = '';
}
return 1 if ($file eq '.cvsignore');
return 1 if ($dir =~ m#(^|/)CVS$#);
if ($ignore_dirs{$dir}) {
foreach my $pattern (@{$ignore_dirs{$dir}}) {
return 1 if $file =~ m/$pattern/;
}
} else {
foreach my $pattern (@base_patterns) {
return 1 if $file =~ m/$pattern/;
}
}
return 0;
}