Commit | Line | Data |
---|---|---|
f1c5bace JH |
1 | #!/usr/bin/perl -w |
2 | ||
3 | # | |
4 | # cmpVERSION - compare two Perl source trees for modules | |
5 | # that have identical version numbers but different contents. | |
6 | # | |
2547c837 DM |
7 | # withg -d option, output the diffs too |
8 | # | |
f1c5bace JH |
9 | # Original by slaven@rezic.de, modified by jhi. |
10 | # | |
11 | ||
12 | use strict; | |
13 | ||
14 | use ExtUtils::MakeMaker; | |
15 | use File::Compare; | |
16 | use File::Find; | |
17 | use File::Spec::Functions qw(rel2abs abs2rel catfile catdir curdir); | |
2547c837 DM |
18 | use Getopt::Std; |
19 | ||
20 | sub usage { | |
21 | die <<'EOF'; | |
22 | usage: $0 [ -d ] source_dir1 source_dir2 | |
23 | EOF | |
24 | } | |
f1c5bace | 25 | |
2547c837 DM |
26 | my %opts; |
27 | getopts('d', \%opts) or usage; | |
28 | @ARGV == 2 or usage; | |
0c429c78 | 29 | |
f1c5bace JH |
30 | for (@ARGV[0, 1]) { |
31 | die "$0: '$_' does not look like Perl directory\n" | |
32 | unless -f catfile($_, "perl.h") && -d catdir($_, "Porting"); | |
33 | } | |
34 | ||
35 | my $dir2 = rel2abs($ARGV[1]); | |
36 | chdir $ARGV[0] or die "$0: chdir '$ARGV[0]' failed: $!\n"; | |
37 | ||
88830c88 JH |
38 | # Files to skip from the check for one reason or another, |
39 | # usually because they pull in their version from some other file. | |
40 | my %skip; | |
477acd91 SH |
41 | @skip{ |
42 | './lib/Carp/Heavy.pm', | |
8adca191 SH |
43 | './lib/Exporter/Heavy.pm', |
44 | './win32/FindExt.pm' | |
477acd91 | 45 | } = (); |
ae8d64f5 | 46 | my $skip_dirs = qr|^\./t/lib|; |
88830c88 | 47 | |
f1c5bace | 48 | my @wanted; |
2547c837 | 49 | my @diffs; |
f1c5bace JH |
50 | find( |
51 | sub { /\.pm$/ && | |
ae8d64f5 | 52 | $File::Find::dir !~ $skip_dirs && |
88830c88 JH |
53 | ! exists $skip{$File::Find::name} |
54 | && | |
f1c5bace JH |
55 | do { my $file2 = |
56 | catfile(catdir($dir2, $File::Find::dir), $_); | |
780d3752 JH |
57 | (my $xs_file1 = $_) =~ s/\.pm$/.xs/; |
58 | (my $xs_file2 = $file2) =~ s/\.pm$/.xs/; | |
2547c837 DM |
59 | my $eq1 = compare($_, $file2) == 0; |
60 | my $eq2 = 1; | |
780d3752 | 61 | if (-e $xs_file1 && -e $xs_file2) { |
2547c837 | 62 | $eq2 = compare($xs_file1, $xs_file2) == 0; |
780d3752 | 63 | } |
2547c837 | 64 | return if $eq1 && $eq2; |
f1c5bace JH |
65 | my $version1 = eval {MM->parse_version($_)}; |
66 | my $version2 = eval {MM->parse_version($file2)}; | |
2547c837 DM |
67 | return unless |
68 | defined $version1 && | |
69 | defined $version2 && | |
70 | $version1 eq $version2; | |
71 | push @wanted, $File::Find::name; | |
72 | push @diffs, [ "$File::Find::dir/$_", $file2 ] unless $eq1; | |
73 | push @diffs, [ "$File::Find::dir/$xs_file1", $xs_file2 ] | |
74 | unless $eq2; | |
f1c5bace | 75 | } }, curdir); |
2547c837 DM |
76 | for (sort @wanted) { |
77 | print "$_\n"; | |
78 | } | |
79 | exit unless $opts{d}; | |
80 | for (sort { $a->[0] cmp $b->[0] } @diffs) { | |
81 | print "\n"; | |
82 | system "diff -du '$_->[0]' '$_->[1]'"; | |
83 | } | |
f1c5bace | 84 |