Commit | Line | Data |
---|---|---|
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 | |
7 | use strict; | |
8 | use warnings; | |
4612967b | 9 | use Getopt::Std; |
0cf51544 | 10 | |
bfc0a3e7 CBW |
11 | my $opts = { |
12 | 'META.yml' => { version => '1.4' }, | |
13 | 'META.json' => { version => '2' }, | |
14 | }; | |
15 | ||
4612967b CBW |
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 | } | |
3e9ed10a | 29 | |
b39f0a19 | 30 | my ($vers, $stat ) = _determine_status(); |
bfc0a3e7 CBW |
31 | |
32 | my $distmeta = { | |
b39f0a19 | 33 | 'version' => $vers, |
bfc0a3e7 CBW |
34 | 'name' => 'perl', |
35 | 'author' => [ | |
36 | 'perl5-porters@perl.org' | |
37 | ], | |
38 | 'license' => [ | |
39 | 'perl_5' | |
40 | ], | |
41 | 'abstract' => 'The Perl 5 language interpreter', | |
b39f0a19 | 42 | 'release_status' => $stat, |
bfc0a3e7 CBW |
43 | 'dynamic_config' => 1, |
44 | 'resources' => { | |
45 | 'repository' => { | |
46 | 'url' => 'http://perl5.git.perl.org/' | |
47 | }, | |
48 | 'homepage' => 'http://www.perl.org/', | |
49 | 'bugtracker' => { | |
fba88146 | 50 | 'web' => 'https://rt.perl.org/' |
bfc0a3e7 CBW |
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; | |
df1ad5b3 JV |
61 | |
62 | BEGIN { | |
63 | # Get function prototypes | |
2bd4012d | 64 | require 'regen/regen_lib.pl'; |
df1ad5b3 JV |
65 | } |
66 | ||
0cf51544 JH |
67 | use Maintainers qw(%Modules get_module_files get_module_pat); |
68 | ||
69 | my @CPAN = grep { $Modules{$_}{CPAN} } keys %Modules; | |
1ce0c05c | 70 | my @files = ('autodoc.pl', 'lib/unicore/mktables', 'TestInit.pm', |
bfc0a3e7 CBW |
71 | 'Porting/Maintainers.pm', 'Porting/perldelta_template.pod', |
72 | map { get_module_files($_) } @CPAN); | |
3916408a | 73 | my @dirs = ('cpan', 'win32', 'lib/perl5db', grep { -d $_ && $_ !~ /^cpan/ } map { get_module_pat($_) } @CPAN); |
0cf51544 | 74 | |
3e9ed10a FD |
75 | my %dirs; |
76 | @dirs{@dirs} = (); | |
77 | ||
bfc0a3e7 | 78 | @files = |
3e9ed10a FD |
79 | grep { |
80 | my $d = $_; | |
2ccec147 | 81 | my $previous_d = ''; |
3e9ed10a | 82 | while(($d = dirname($d)) ne "."){ |
2ccec147 | 83 | last if $d eq $previous_d; # safety valve |
3e9ed10a | 84 | last if exists $dirs{$d}; |
2ccec147 | 85 | $previous_d = $d; |
3e9ed10a FD |
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 | |
bfc0a3e7 | 90 | |
2ccec147 | 91 | $d eq "." || $d eq $previous_d; |
3e9ed10a FD |
92 | } |
93 | sort { lc $a cmp lc $b } @files; | |
94 | ||
bfc0a3e7 | 95 | @dirs = sort { lc $a cmp lc $b } @dirs; |
0cf51544 | 96 | |
bfc0a3e7 CBW |
97 | $distmeta->{no_index}->{file} = \@files; |
98 | $distmeta->{no_index}->{directory} = \@dirs; | |
0cf51544 | 99 | |
bfc0a3e7 | 100 | my $meta = CPAN::Meta->create( $distmeta ); |
4612967b CBW |
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 | } | |
bfc0a3e7 CBW |
106 | exit 0; |
107 | ||
108 | sub _determine_status { | |
109 | my $patchlevel_h = 'patchlevel.h'; | |
110 | return unless -e $patchlevel_h; | |
111 | my $status = ''; | |
b39f0a19 | 112 | my $version = ''; |
bfc0a3e7 CBW |
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 | } | |
b39f0a19 CBW |
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 | } | |
bfc0a3e7 | 139 | } |
b39f0a19 | 140 | return ( $version, $status ); |
bfc0a3e7 | 141 | } |