This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Configure should sort inc_version_list
[perl5.git] / Porting / corelist.pl
CommitLineData
4a656c5e
RGS
1#!perl
2# Generates info for Module::CoreList from this perl tree
3# run this from the root of a clean perl tree
4
4a656c5e
RGS
5use strict;
6use warnings;
7use File::Find;
8use ExtUtils::MM_Unix;
fb237dfd
NC
9use lib "Porting";
10use Maintainers qw(%Modules files_to_modules);
11use File::Spec;
4a656c5e 12
59189dd7 13my %lines;
fb237dfd
NC
14my %module_to_file;
15my %modlist;
16my $cpan = shift;
17
18if ($cpan) {
19 my $modlistfile
20 = File::Spec->catfile($cpan, 'modules', '02packages.details.txt');
21 open my $fh, '<', $modlistfile or die "Couldn't open $modlistfile: $!";
22
23 {
24 local $/ = "\n\n";
25 die "Incompatible modlist format"
26 unless <$fh> =~ /^Columns: +package name, version, path/m;
27 }
28
29 # Converting the file to a hash is about 5 times faster than a regexp flat
30 # lookup.
31 while (<$fh>) {
32 next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/;
33 $modlist{$1} = $2;
34 }
35}
36
4a656c5e
RGS
37find(sub {
38 /(\.pm|_pm\.PL)$/ or return;
d51d469b 39 /PPPort\.pm$/ and return;
4a656c5e 40 my $module = $File::Find::name;
d51d469b
RGS
41 $module =~ /\b(demo|t|private)\b/ and return; # demo or test modules
42 my $version = MM->parse_version($_);
43 defined $version or $version = 'undef';
4a656c5e
RGS
44 $version =~ /\d/ and $version = "'$version'";
45 # some heuristics to figure out the module name from the file name
4a626d91
RGS
46 $module =~ s{^(lib|(win32/|vms/|symbian/)?ext)/}{}
47 and $1 ne 'lib'
fb237dfd 48 and ( $module =~ s{\b(\w+)/\1\b}{$1},
dc5f10bb 49 $module =~ s{^B/O}{O},
da09dfe3 50 $module =~ s{^Devel-PPPort}{Devel},
4a656c5e 51 $module =~ s{^Encode/encoding}{encoding},
da09dfe3
NC
52 $module =~ s{^IPC-SysV/}{IPC/},
53 $module =~ s{^MIME-Base64/QuotedPrint}{MIME/QuotedPrint},
dc5f10bb 54 $module =~ s{^(?:DynaLoader|Errno|Opcode)/}{},
4a656c5e
RGS
55 );
56 $module =~ s{/}{::}g;
da09dfe3
NC
57 $module =~ s{-}{::}g;
58 $module =~ s{^.*::lib::}{};
4a656c5e 59 $module =~ s/(\.pm|_pm\.PL)$//;
0fdd9e5c 60 $lines{$module} = $version;
fb237dfd 61 $module_to_file{$module} = $File::Find::name;
59189dd7
MB
62}, 'lib', 'ext', 'vms/ext', 'symbian/ext');
63
0fdd9e5c 64-e 'configpm' and $lines{Config} = 'undef';
cc8432b2 65
59189dd7
MB
66if (open my $ucdv, "<", "lib/unicore/version") {
67 chomp (my $ucd = <$ucdv>);
0fdd9e5c 68 $lines{Unicode} = "'$ucd'";
59189dd7
MB
69 close $ucdv;
70 }
fb237dfd
NC
71
72sub display_hash {
73 my ($hash) = @_;
0fdd9e5c 74}
fb237dfd
NC
75
76print " $] => {\n";
77printf "\t%-24s=> $lines{$_},\n", "'$_'" foreach sort keys %lines;
4a656c5e 78print " },\n";
fb237dfd
NC
79
80exit unless %modlist;
81
82# We have to go through this two stage lookup, given how Maintainers.pl keys its
83# data by "Module", which is really a dist.
84my $file_to_M = files_to_modules(values %module_to_file);
85
86my %module_to_upstream;
87my %module_to_dist;
88my %dist_to_meta_YAML;
89while (my ($module, $file) = each %module_to_file) {
90 my $M = $file_to_M->{$file};
91 next unless $M;
92 next if $Modules{$M}{MAINTAINER} eq 'p5p';
93 $module_to_upstream{$module} = $Modules{$M}{UPSTREAM};
94 next if defined $module_to_upstream{$module} &&
95 $module_to_upstream{$module} =~ /^(?:blead|first-come)$/;
96 my $dist = $modlist{$module};
97 unless ($dist) {
98 warn "Can't find a distribution for $module";
99 next;
100 }
101 $module_to_dist{$module} = $dist;
102
103 next if exists $dist_to_meta_YAML{$dist};
104
105 $dist_to_meta_YAML{$dist} = undef;
106
107 # Like it or lump it, this has to be Unix format.
108 my $meta_YAML_path = "$cpan/authors/id/$dist";
109 $meta_YAML_path =~ s/(?:tar\.gz|zip)$/meta/ or die "$meta_YAML_path";
110 unless (-e $meta_YAML_path) {
111 warn "$meta_YAML_path does not exist for $module";
112 # I tried code to open the tarballs with Archive::Tar to find and
113 # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one,
114 # so it's not worth including.
115 next;
116 }
117 require Parse::CPAN::Meta;
118 $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile($meta_YAML_path);
119}
120
121print "\n%upstream = (\n";
122foreach my $module (sort keys %module_to_upstream) {
123 my $upstream = defined $module_to_upstream{$module}
124 ? "'$module_to_upstream{$module}'" : 'undef';
125 printf " %-24s=> $upstream,\n", "'$module'";
126}
127print ");\n";
128
129print "\n%bug_tracker = (\n";
130foreach my $module (sort keys %module_to_upstream) {
131 my $upstream = defined $module_to_upstream{$module};
132 next if defined $upstream
133 and $upstream eq 'blead' || $upstream eq 'first-come';
134
135 my $bug_tracker;
136
137 my $dist = $module_to_dist{$module};
138 $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker}
139 if $dist;
140
141 $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef';
142 next if $bug_tracker eq "'http://rt.perl.org/perlbug/'";
143 printf " %-24s=> $bug_tracker,\n", "'$module'";
144}
145print ");\n";