4 # cmpVERSION - compare two Perl source trees for modules
5 # that have identical version numbers but different contents.
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 '.'.
12 # Original by slaven@rezic.de, modified by jhi.
17 use ExtUtils::MakeMaker;
20 use File::Spec::Functions qw(rel2abs abs2rel catfile catdir curdir);
28 usage: $0 [ -d -x ] source_dir1 source_dir2
33 getopts('dx', \%opts) or usage;
37 die "$0: '$_' does not look like Perl directory\n"
38 unless -f catfile($_, "perl.h") && -d catdir($_, "Porting");
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)
49 $dual_files{"./$_"} = 1 for Maintainers::get_module_files($m);
53 my $dir2 = rel2abs($ARGV[1]);
54 chdir $ARGV[0] or die "$0: chdir '$ARGV[0]' failed: $!\n";
56 # Files to skip from the check for one reason or another,
57 # usually because they pull in their version from some other file.
60 './lib/Carp/Heavy.pm',
61 './lib/Config.pm', # no version number but contents will vary
62 './lib/Exporter/Heavy.pm',
65 my $skip_dirs = qr|^\./t/lib|;
71 $File::Find::dir !~ $skip_dirs &&
72 ! exists $skip{$File::Find::name} &&
73 ! exists $dual_files{$File::Find::name}
76 catfile(catdir($dir2, $File::Find::dir), $_);
77 (my $xs_file1 = $_) =~ s/\.pm$/.xs/;
78 (my $xs_file2 = $file2) =~ s/\.pm$/.xs/;
79 my $eq1 = compare($_, $file2) == 0;
81 if (-e $xs_file1 && -e $xs_file2) {
82 $eq2 = compare($xs_file1, $xs_file2) == 0;
84 return if $eq1 && $eq2;
85 my $version1 = eval {MM->parse_version($_)};
86 my $version2 = eval {MM->parse_version($file2)};
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 ]
100 for (sort { $a->[0] cmp $b->[0] } @diffs) {
102 system "diff -du '$_->[0]' '$_->[1]'";