This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Regression test for 34394ecd - SVs that were only on the tmps stack leaked.
[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)
4c7053ad 10# With this option, one of 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',
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 65my $skip_dirs = qr|^\./t/lib|;
88830c88 66
f1c5bace 67my @wanted;
2547c837 68my @diffs;
f1c5bace
JH
69find(
70 sub { /\.pm$/ &&
ae8d64f5 71 $File::Find::dir !~ $skip_dirs &&
2fb8ff88
DM
72 ! exists $skip{$File::Find::name} &&
73 ! exists $dual_files{$File::Find::name}
88830c88 74 &&
f1c5bace
JH
75 do { my $file2 =
76 catfile(catdir($dir2, $File::Find::dir), $_);
780d3752
JH
77 (my $xs_file1 = $_) =~ s/\.pm$/.xs/;
78 (my $xs_file2 = $file2) =~ s/\.pm$/.xs/;
2547c837
DM
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
JH
85 my $version1 = eval {MM->parse_version($_)};
86 my $version2 = eval {MM->parse_version($file2)};
2547c837
DM
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
DM
96for (sort @wanted) {
97 print "$_\n";
98}
99exit unless $opts{d};
100for (sort { $a->[0] cmp $b->[0] } @diffs) {
101 print "\n";
102 system "diff -du '$_->[0]' '$_->[1]'";
103}
f1c5bace 104