From: Nicholas Clark Date: Thu, 23 Apr 2009 20:35:26 +0000 (+0100) Subject: Use files_to_modules() and a CPAN mirror to map modules to bug tracker URLs. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb237dfd6e6270728b5c90da2e49591f90f67073;p=p5sagit%2Fp5-mst-13.2.git Use files_to_modules() and a CPAN mirror to map modules to bug tracker URLs. Output two hashes, ready for inclusion in Module::CoreList. %upstream maps module names to the UPSTREAM status in Porting/Maintainers.pl. %bug_tracker maps module names to the URL of the bug tracker, or undef if explict bug tracker is not known for a module known to be dual life. --- diff --git a/Porting/corelist.pl b/Porting/corelist.pl index 0d40c78..b301c83 100644 --- a/Porting/corelist.pl +++ b/Porting/corelist.pl @@ -6,8 +6,34 @@ use strict; use warnings; use File::Find; use ExtUtils::MM_Unix; +use lib "Porting"; +use Maintainers qw(%Modules files_to_modules); +use File::Spec; my %lines; +my %module_to_file; +my %modlist; +my $cpan = shift; + +if ($cpan) { + my $modlistfile + = File::Spec->catfile($cpan, 'modules', '02packages.details.txt'); + open my $fh, '<', $modlistfile or die "Couldn't open $modlistfile: $!"; + + { + local $/ = "\n\n"; + die "Incompatible modlist format" + unless <$fh> =~ /^Columns: +package name, version, path/m; + } + + # Converting the file to a hash is about 5 times faster than a regexp flat + # lookup. + while (<$fh>) { + next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/; + $modlist{$1} = $2; + } +} + find(sub { /(\.pm|_pm\.PL)$/ or return; /PPPort\.pm$/ and return; @@ -19,8 +45,7 @@ find(sub { # some heuristics to figure out the module name from the file name $module =~ s{^(lib|(win32/|vms/|symbian/)?ext)/}{} and $1 ne 'lib' - and ( $module =~ s{^(.*)/lib/\1\b}{$1}, - $module =~ s{(\w+)/\1\b}{$1}, + and ( $module =~ s{\b(\w+)/\1\b}{$1}, $module =~ s{^B/O}{O}, $module =~ s{^Devel-PPPort}{Devel}, $module =~ s{^Encode/encoding}{encoding}, @@ -33,6 +58,7 @@ find(sub { $module =~ s{^.*::lib::}{}; $module =~ s/(\.pm|_pm\.PL)$//; $lines{$module} = $version; + $module_to_file{$module} = $File::Find::name; }, 'lib', 'ext', 'vms/ext', 'symbian/ext'); -e 'configpm' and $lines{Config} = 'undef'; @@ -42,8 +68,78 @@ if (open my $ucdv, "<", "lib/unicore/version") { $lines{Unicode} = "'$ucd'"; close $ucdv; } -print " $] => {\n"; -foreach (sort keys %lines) { - printf "\t%-24s=> $lines{$_},\n", "'$_'"; + +sub display_hash { + my ($hash) = @_; } + +print " $] => {\n"; +printf "\t%-24s=> $lines{$_},\n", "'$_'" foreach sort keys %lines; print " },\n"; + +exit unless %modlist; + +# We have to go through this two stage lookup, given how Maintainers.pl keys its +# data by "Module", which is really a dist. +my $file_to_M = files_to_modules(values %module_to_file); + +my %module_to_upstream; +my %module_to_dist; +my %dist_to_meta_YAML; +while (my ($module, $file) = each %module_to_file) { + my $M = $file_to_M->{$file}; + next unless $M; + next if $Modules{$M}{MAINTAINER} eq 'p5p'; + $module_to_upstream{$module} = $Modules{$M}{UPSTREAM}; + next if defined $module_to_upstream{$module} && + $module_to_upstream{$module} =~ /^(?:blead|first-come)$/; + my $dist = $modlist{$module}; + unless ($dist) { + warn "Can't find a distribution for $module"; + next; + } + $module_to_dist{$module} = $dist; + + next if exists $dist_to_meta_YAML{$dist}; + + $dist_to_meta_YAML{$dist} = undef; + + # Like it or lump it, this has to be Unix format. + my $meta_YAML_path = "$cpan/authors/id/$dist"; + $meta_YAML_path =~ s/(?:tar\.gz|zip)$/meta/ or die "$meta_YAML_path"; + unless (-e $meta_YAML_path) { + warn "$meta_YAML_path does not exist for $module"; + # I tried code to open the tarballs with Archive::Tar to find and + # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one, + # so it's not worth including. + next; + } + require Parse::CPAN::Meta; + $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile($meta_YAML_path); +} + +print "\n%upstream = (\n"; +foreach my $module (sort keys %module_to_upstream) { + my $upstream = defined $module_to_upstream{$module} + ? "'$module_to_upstream{$module}'" : 'undef'; + printf " %-24s=> $upstream,\n", "'$module'"; +} +print ");\n"; + +print "\n%bug_tracker = (\n"; +foreach my $module (sort keys %module_to_upstream) { + my $upstream = defined $module_to_upstream{$module}; + next if defined $upstream + and $upstream eq 'blead' || $upstream eq 'first-come'; + + my $bug_tracker; + + my $dist = $module_to_dist{$module}; + $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker} + if $dist; + + $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef'; + next if $bug_tracker eq "'http://rt.perl.org/perlbug/'"; + printf " %-24s=> $bug_tracker,\n", "'$module'"; +} +print ");\n";