Commit | Line | Data |
f1c5bace |
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 | # |
2fb8ff88 |
7 | # with -d option, output the diffs too |
8 | # with -x option, exclude dual-life modules (after all, there are tools |
9 | # like core-cpan-diff that can already deal with them) |
10 | # With this option, one od the directories must be '.'. |
2547c837 |
11 | # |
f1c5bace |
12 | # Original by slaven@rezic.de, modified by jhi. |
13 | # |
14 | |
15 | use strict; |
16 | |
17 | use ExtUtils::MakeMaker; |
18 | use File::Compare; |
19 | use File::Find; |
20 | use File::Spec::Functions qw(rel2abs abs2rel catfile catdir curdir); |
2547c837 |
21 | use Getopt::Std; |
22 | |
2fb8ff88 |
23 | use lib 'Porting'; |
24 | use Maintainers; |
25 | |
2547c837 |
26 | sub usage { |
27 | die <<'EOF'; |
2fb8ff88 |
28 | usage: $0 [ -d -x ] source_dir1 source_dir2 |
2547c837 |
29 | EOF |
30 | } |
f1c5bace |
31 | |
2547c837 |
32 | my %opts; |
2fb8ff88 |
33 | getopts('dx', \%opts) or usage; |
2547c837 |
34 | @ARGV == 2 or usage; |
0c429c78 |
35 | |
f1c5bace |
36 | for (@ARGV[0, 1]) { |
37 | die "$0: '$_' does not look like Perl directory\n" |
38 | unless -f catfile($_, "perl.h") && -d catdir($_, "Porting"); |
39 | } |
40 | |
2fb8ff88 |
41 | my %dual_files; |
42 | if ($opts{x}) { |
43 | die "With -x, one of the directories must be '.'\n" |
44 | unless $ARGV[0] eq '.' or $ARGV[1] eq '.'; |
45 | for my $m (grep $Maintainers::Modules{$_}{CPAN}, |
46 | keys %Maintainers::Modules) |
47 | { |
48 | |
49 | $dual_files{"./$_"} = 1 for Maintainers::get_module_files($m); |
50 | } |
51 | } |
52 | |
f1c5bace |
53 | my $dir2 = rel2abs($ARGV[1]); |
54 | chdir $ARGV[0] or die "$0: chdir '$ARGV[0]' failed: $!\n"; |
55 | |
88830c88 |
56 | # Files to skip from the check for one reason or another, |
57 | # usually because they pull in their version from some other file. |
58 | my %skip; |
477acd91 |
59 | @skip{ |
60 | './lib/Carp/Heavy.pm', |
7536d879 |
61 | './lib/Config.pm', # no version number but contents will vary |
8adca191 |
62 | './lib/Exporter/Heavy.pm', |
7536d879 |
63 | './win32/FindExt.pm', |
477acd91 |
64 | } = (); |
ae8d64f5 |
65 | my $skip_dirs = qr|^\./t/lib|; |
88830c88 |
66 | |
f1c5bace |
67 | my @wanted; |
2547c837 |
68 | my @diffs; |
f1c5bace |
69 | find( |
70 | sub { /\.pm$/ && |
ae8d64f5 |
71 | $File::Find::dir !~ $skip_dirs && |
2fb8ff88 |
72 | ! exists $skip{$File::Find::name} && |
73 | ! exists $dual_files{$File::Find::name} |
88830c88 |
74 | && |
f1c5bace |
75 | do { my $file2 = |
76 | catfile(catdir($dir2, $File::Find::dir), $_); |
780d3752 |
77 | (my $xs_file1 = $_) =~ s/\.pm$/.xs/; |
78 | (my $xs_file2 = $file2) =~ s/\.pm$/.xs/; |
2547c837 |
79 | my $eq1 = compare($_, $file2) == 0; |
80 | my $eq2 = 1; |
780d3752 |
81 | if (-e $xs_file1 && -e $xs_file2) { |
2547c837 |
82 | $eq2 = compare($xs_file1, $xs_file2) == 0; |
780d3752 |
83 | } |
2547c837 |
84 | return if $eq1 && $eq2; |
f1c5bace |
85 | my $version1 = eval {MM->parse_version($_)}; |
86 | my $version2 = eval {MM->parse_version($file2)}; |
2547c837 |
87 | return unless |
88 | defined $version1 && |
89 | defined $version2 && |
90 | $version1 eq $version2; |
91 | push @wanted, $File::Find::name; |
92 | push @diffs, [ "$File::Find::dir/$_", $file2 ] unless $eq1; |
93 | push @diffs, [ "$File::Find::dir/$xs_file1", $xs_file2 ] |
94 | unless $eq2; |
f1c5bace |
95 | } }, curdir); |
2547c837 |
96 | for (sort @wanted) { |
97 | print "$_\n"; |
98 | } |
99 | exit unless $opts{d}; |
100 | for (sort { $a->[0] cmp $b->[0] } @diffs) { |
101 | print "\n"; |
102 | system "diff -du '$_->[0]' '$_->[1]'"; |
103 | } |
f1c5bace |
104 | |