This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove AT&T UWIN support
[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 20my %switches;
c69e4295
MM
21getopts('nbyj', \%switches);
22
23=head1 SYNOPSIS
24
25 ./perl -Ilib Porting/makemeta
26
27=head1 OPTIONS
28
29=item B<-y>
30
31Update only META.yml
32
33The default is to update both, META.yml and META.json
34
35=item B<-n>
36
37Don't update any files, exit with 1 if changes would be made
38
39=item B<-b>
40
41No-op, kept for historical purposes
42
43=cut
4612967b
CBW
44
45my @metafiles;
46if ( $switches{y} ) {
47 push @metafiles, 'META.yml';
48}
49elsif ( $switches{j} ) {
50 push @metafiles, 'META.json';
51}
52else {
53 push @metafiles, keys %$opts;
54}
3e9ed10a 55
b39f0a19 56my ($vers, $stat ) = _determine_status();
bfc0a3e7
CBW
57
58my $distmeta = {
b39f0a19 59 'version' => $vers,
bfc0a3e7
CBW
60 'name' => 'perl',
61 'author' => [
62 'perl5-porters@perl.org'
63 ],
64 'license' => [
65 'perl_5'
66 ],
67 'abstract' => 'The Perl 5 language interpreter',
b39f0a19 68 'release_status' => $stat,
bfc0a3e7
CBW
69 'dynamic_config' => 1,
70 'resources' => {
71 'repository' => {
47ef154c 72 'url' => 'https://github.com/Perl/perl5'
bfc0a3e7 73 },
77bf4cdb 74 'homepage' => 'https://www.perl.org/',
bfc0a3e7 75 'bugtracker' => {
47ef154c 76 'web' => 'https://github.com/Perl/perl5/issues'
bfc0a3e7
CBW
77 },
78 'license' => [
77bf4cdb 79 'https://dev.perl.org/licenses/'
bfc0a3e7
CBW
80 ],
81 },
82};
83
84use lib "Porting";
85use File::Basename qw( dirname );
86use CPAN::Meta;
ae7871d9 87use File::Spec;
df1ad5b3
JV
88
89BEGIN {
90 # Get function prototypes
3d7c117d 91 require './regen/regen_lib.pl';
df1ad5b3
JV
92}
93
0cf51544
JH
94use Maintainers qw(%Modules get_module_files get_module_pat);
95
96my @CPAN = grep { $Modules{$_}{CPAN} } keys %Modules;
1ce0c05c 97my @files = ('autodoc.pl', 'lib/unicore/mktables', 'TestInit.pm',
bfc0a3e7
CBW
98 'Porting/Maintainers.pm', 'Porting/perldelta_template.pod',
99 map { get_module_files($_) } @CPAN);
ae7871d9
TC
100my @extt = map { my $t = File::Spec->catdir($_, "t");
101 -d $t ? ( $_ . "t" ) : () }
102 grep { /^ext\b/ } split ' ', $Modules{_PERLLIB}{FILES};
103my @dirs = ('cpan', 'win32', 'lib/perl5db', @extt, grep { -d $_ && $_ !~ /^cpan/ } map { get_module_pat($_) } @CPAN);
0cf51544 104
3e9ed10a
FD
105my %dirs;
106@dirs{@dirs} = ();
107
bfc0a3e7 108@files =
3e9ed10a
FD
109 grep {
110 my $d = $_;
2ccec147 111 my $previous_d = '';
3e9ed10a 112 while(($d = dirname($d)) ne "."){
2ccec147 113 last if $d eq $previous_d; # safety valve
3e9ed10a 114 last if exists $dirs{$d};
2ccec147 115 $previous_d = $d;
3e9ed10a
FD
116 }
117
118 # if $d is "." it means we tried every parent dir of the file and none
119 # of them were in the private list
bfc0a3e7 120
2ccec147 121 $d eq "." || $d eq $previous_d;
3e9ed10a
FD
122 }
123 sort { lc $a cmp lc $b } @files;
124
bfc0a3e7 125@dirs = sort { lc $a cmp lc $b } @dirs;
0cf51544 126
bfc0a3e7
CBW
127$distmeta->{no_index}->{file} = \@files;
128$distmeta->{no_index}->{directory} = \@dirs;
0cf51544 129
bfc0a3e7 130my $meta = CPAN::Meta->create( $distmeta );
4612967b 131foreach my $file ( @metafiles ) {
c69e4295
MM
132 my $new = $meta->as_string( $opts->{$file} );
133 if( $switches{n} ) {
134 open my $fh, '<:raw', $file;
135 local $/;
136 my $old = <$fh>;
137 if( $old ne $new ) {
138 exit 1;
139 }
140 } else {
141 my $fh = open_new($file);
142 print $fh $new;
143 close_and_rename($fh);
144 }
4612967b 145}
bfc0a3e7
CBW
146exit 0;
147
148sub _determine_status {
149 my $patchlevel_h = 'patchlevel.h';
150 return unless -e $patchlevel_h;
151 my $status = '';
b39f0a19 152 my $version = '';
bfc0a3e7
CBW
153 {
154 my %defines;
155 open my $fh, '<', $patchlevel_h;
156 my @vers;
157 while (<$fh>) {
158 chomp;
159 next unless m!^#define! or m!!;
160 if ( m!^#define! ) {
161 my ($foo,$bar) = ( split /\s+/ )[1,2];
162 $defines{$foo} = $bar;
163 }
164 elsif ( m!\"RC\d+\"! ) {
165 $status = 'testing';
166 last;
167 }
168 }
169 unless ( $status ) {
170 $status = $defines{PERL_VERSION} % 2 ? 'unstable' : 'stable';
171 }
b39f0a19
CBW
172 if ( my @wotsits = grep { defined $defines{$_} } qw(PERL_REVISION PERL_VERSION PERL_SUBVERSION) ) {
173 $version = sprintf '%d.%03d%03d', map { $defines{$_} } @wotsits;
174 }
175 else {
176 # Well, you never know
177 $version = sprintf '5.%03d_%02d', map { $defines{$_} } qw(PATCHLEVEL SUBVERSION);
178 }
bfc0a3e7 179 }
b39f0a19 180 return ( $version, $status );
bfc0a3e7 181}