This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Typo fix in pod/perl5110delta.pod
[perl5.git] / Porting / cmpVERSION.pl
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 #
7 # withg -d option, output the diffs too
8 #
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);
18 use Getopt::Std;
19
20 sub usage {
21 die <<'EOF';
22 usage: $0 [ -d ] source_dir1 source_dir2
23 EOF
24 }
25
26 my %opts;
27 getopts('d', \%opts) or usage;
28 @ARGV == 2 or usage;
29
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
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;
41 @skip{
42     './lib/Carp/Heavy.pm',
43     './lib/Exporter/Heavy.pm',
44     './win32/FindExt.pm'
45 } = ();
46 my $skip_dirs = qr|^\./t/lib|;
47
48 my @wanted;
49 my @diffs;
50 find(
51      sub { /\.pm$/ &&
52                $File::Find::dir !~ $skip_dirs &&
53                ! exists $skip{$File::Find::name}
54                &&
55                do { my $file2 =
56                         catfile(catdir($dir2, $File::Find::dir), $_);
57                     (my $xs_file1 = $_)     =~ s/\.pm$/.xs/;
58                     (my $xs_file2 = $file2) =~ s/\.pm$/.xs/;
59                     my $eq1 = compare($_, $file2) == 0;
60                     my $eq2 = 1;
61                     if (-e $xs_file1 && -e $xs_file2) {
62                         $eq2 = compare($xs_file1, $xs_file2) == 0;
63                     }
64                     return if $eq1 && $eq2;
65                     my $version1 = eval {MM->parse_version($_)};
66                     my $version2 = eval {MM->parse_version($file2)};
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;
75                 } }, curdir);
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 }
84