This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127494] TODO test for $AUTOLOAD being set for DESTROY
[perl5.git] / Porting / makemeta
1 #!./perl -w
2 # this script must be run by the current perl to get perl's version right
3 #
4 # Create META.yml and META.json files in the current directory. Must be run from the
5 # root directory of a perl source tree.
6
7 use strict;
8 use warnings;
9 use Getopt::Std;
10
11 my $opts = {
12   'META.yml'  => { version => '1.4' },
13   'META.json' => { version => '2' },
14 };
15
16 my %switches;
17 getopts('byj', \%switches);
18
19 my @metafiles;
20 if ( $switches{y} ) {
21   push @metafiles, 'META.yml';
22 }
23 elsif ( $switches{j} ) {
24   push @metafiles, 'META.json';
25 }
26 else {
27   push @metafiles, keys %$opts;
28 }
29
30 my ($vers, $stat ) = _determine_status();
31
32 my $distmeta = {
33   'version' => $vers,
34   'name' => 'perl',
35   'author' => [
36     'perl5-porters@perl.org'
37   ],
38   'license' => [
39     'perl_5'
40   ],
41   'abstract' => 'The Perl 5 language interpreter',
42   'release_status' => $stat,
43   'dynamic_config' => 1,
44   'resources' => {
45     'repository' => {
46       'url' => 'http://perl5.git.perl.org/'
47     },
48     'homepage' => 'http://www.perl.org/',
49     'bugtracker' => {
50       'web' => 'https://rt.perl.org/'
51     },
52     'license' => [
53       'http://dev.perl.org/licenses/'
54     ],
55   },
56 };
57
58 use lib "Porting";
59 use File::Basename qw( dirname );
60 use CPAN::Meta;
61
62 BEGIN {
63     # Get function prototypes
64     require 'regen/regen_lib.pl';
65 }
66
67 use Maintainers qw(%Modules get_module_files get_module_pat);
68
69 my @CPAN  = grep { $Modules{$_}{CPAN} } keys %Modules;
70 my @files = ('autodoc.pl', 'lib/unicore/mktables', 'TestInit.pm',
71              'Porting/Maintainers.pm', 'Porting/perldelta_template.pod',
72              map { get_module_files($_) } @CPAN);
73 my @dirs  = ('cpan', 'win32', 'lib/perl5db', grep { -d $_ && $_  !~ /^cpan/ } map { get_module_pat($_) } @CPAN);
74
75 my %dirs;
76 @dirs{@dirs} = ();
77
78 @files =
79   grep {
80     my $d = $_;
81     my $previous_d = '';
82     while(($d = dirname($d)) ne "."){
83       last if $d eq $previous_d; # safety valve
84       last if exists $dirs{$d};
85       $previous_d = $d;
86     }
87
88     # if $d is "." it means we tried every parent dir of the file and none
89     # of them were in the private list
90
91     $d eq "." || $d eq $previous_d;
92   }
93   sort { lc $a cmp lc $b } @files;
94
95 @dirs  = sort { lc $a cmp lc $b } @dirs;
96
97 $distmeta->{no_index}->{file} = \@files;
98 $distmeta->{no_index}->{directory} = \@dirs;
99
100 my $meta = CPAN::Meta->create( $distmeta );
101 foreach my $file ( @metafiles ) {
102   my $fh = open_new($file);
103   print $fh $meta->as_string( $opts->{$file} );
104   close_and_rename($fh);
105 }
106 exit 0;
107
108 sub _determine_status {
109   my $patchlevel_h = 'patchlevel.h';
110   return unless -e $patchlevel_h;
111   my $status = '';
112   my $version = '';
113   {
114     my %defines;
115     open my $fh, '<', $patchlevel_h;
116     my @vers;
117     while (<$fh>) {
118       chomp;
119       next unless m!^#define! or m!!;
120       if ( m!^#define! ) {
121         my ($foo,$bar) = ( split /\s+/ )[1,2];
122         $defines{$foo} = $bar;
123       }
124       elsif ( m!\"RC\d+\"! ) {
125         $status = 'testing';
126         last;
127       }
128     }
129     unless ( $status ) {
130       $status = $defines{PERL_VERSION} % 2 ? 'unstable' : 'stable';
131     }
132     if ( my @wotsits = grep { defined $defines{$_} } qw(PERL_REVISION PERL_VERSION PERL_SUBVERSION) ) {
133       $version = sprintf '%d.%03d%03d', map { $defines{$_} } @wotsits;
134     }
135     else {
136       # Well, you never know
137       $version = sprintf '5.%03d_%02d', map { $defines{$_} } qw(PATCHLEVEL SUBVERSION);
138     }
139   }
140   return ( $version, $status );
141 }