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