This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add -x option to Porting/cmpVERSION.pl
[perl5.git] / Porting / cmpVERSION.pl
CommitLineData
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#
2fb8ff88
DM
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
JH
12# Original by slaven@rezic.de, modified by jhi.
13#
14
15use strict;
16
17use ExtUtils::MakeMaker;
18use File::Compare;
19use File::Find;
20use File::Spec::Functions qw(rel2abs abs2rel catfile catdir curdir);
2547c837
DM
21use Getopt::Std;
22
2fb8ff88
DM
23use lib 'Porting';
24use Maintainers;
25
2547c837
DM
26sub usage {
27die <<'EOF';
2fb8ff88 28usage: $0 [ -d -x ] source_dir1 source_dir2
2547c837
DM
29EOF
30}
f1c5bace 31
2547c837 32my %opts;
2fb8ff88 33getopts('dx', \%opts) or usage;
2547c837 34@ARGV == 2 or usage;
0c429c78 35
f1c5bace
JH
36for (@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
DM
41my %dual_files;
42if ($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
JH
53my $dir2 = rel2abs($ARGV[1]);
54chdir $ARGV[0] or die "$0: chdir '$ARGV[0]' failed: $!\n";
55
88830c88
JH
56# Files to skip from the check for one reason or another,
57# usually because they pull in their version from some other file.
58my %skip;
477acd91
SH
59@skip{
60 './lib/Carp/Heavy.pm',
8adca191
SH
61 './lib/Exporter/Heavy.pm',
62 './win32/FindExt.pm'
477acd91 63} = ();
ae8d64f5 64my $skip_dirs = qr|^\./t/lib|;
88830c88 65
f1c5bace 66my @wanted;
2547c837 67my @diffs;
f1c5bace
JH
68find(
69 sub { /\.pm$/ &&
ae8d64f5 70 $File::Find::dir !~ $skip_dirs &&
2fb8ff88
DM
71 ! exists $skip{$File::Find::name} &&
72 ! exists $dual_files{$File::Find::name}
88830c88 73 &&
f1c5bace
JH
74 do { my $file2 =
75 catfile(catdir($dir2, $File::Find::dir), $_);
780d3752
JH
76 (my $xs_file1 = $_) =~ s/\.pm$/.xs/;
77 (my $xs_file2 = $file2) =~ s/\.pm$/.xs/;
2547c837
DM
78 my $eq1 = compare($_, $file2) == 0;
79 my $eq2 = 1;
780d3752 80 if (-e $xs_file1 && -e $xs_file2) {
2547c837 81 $eq2 = compare($xs_file1, $xs_file2) == 0;
780d3752 82 }
2547c837 83 return if $eq1 && $eq2;
f1c5bace
JH
84 my $version1 = eval {MM->parse_version($_)};
85 my $version2 = eval {MM->parse_version($file2)};
2547c837
DM
86 return unless
87 defined $version1 &&
88 defined $version2 &&
89 $version1 eq $version2;
90 push @wanted, $File::Find::name;
91 push @diffs, [ "$File::Find::dir/$_", $file2 ] unless $eq1;
92 push @diffs, [ "$File::Find::dir/$xs_file1", $xs_file2 ]
93 unless $eq2;
f1c5bace 94 } }, curdir);
2547c837
DM
95for (sort @wanted) {
96 print "$_\n";
97}
98exit unless $opts{d};
99for (sort { $a->[0] cmp $b->[0] } @diffs) {
100 print "\n";
101 system "diff -du '$_->[0]' '$_->[1]'";
102}
f1c5bace 103