forked from Perl/docker-perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.pl
executable file
·210 lines (155 loc) · 5.24 KB
/
generate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env perl
use v5.14;
use strict;
use warnings;
use YAML::XS;
use Devel::PatchPerl;
use LWP::Simple;
sub die_with_sample {
die <<EOF;
The Releases.yaml file must look roughly like:
releases:
- version: 5.20.0
sha1: asdasdadas
pause: RJBS
Where version is the version number of Perl, sha1 is the SHA1 of the
tar.bz2 file, and pause is the PAUSE account of the release manager.
If needed or desired, extra_flags: can be added, which will be passed
verbatim to Configure.
EOF
}
my $yaml = do {
open my $fh, "Releases.yaml" or die "Couldn't open releases";
local $/;
Load <$fh>;
};
my $template = do {
local $/;
<DATA>;
};
my %builds = (
"64bit" => "-Duse64bitall",
"64bit,threaded" => "-Dusethreads -Duse64bitall",
);
die_with_sample unless defined $yaml->{releases};
die_with_sample unless ref $yaml->{releases} eq "ARRAY";
if (! -d "downloads") {
mkdir "downloads" or die "Couldn't create a downloads directory";
}
for my $release (@{$yaml->{releases}}) {
do { die_with_sample unless $release->{$_}} for (qw(version pause sha1));
die "Bad version: $release->{version}" unless $release->{version} =~ /\A5\.\d+\.\d+\Z/;
my $patch;
my $file = "perl-$release->{version}.tar.bz2";
my $url = "http://www.cpan.org/src/5.0/$file";
if (-f "downloads/$file" &&
`sha1sum downloads/$file` =~ /^\Q$release->{sha1}\E\s+\Qdownloads\/$file\E/) {
print "Skipping download of $file, already current\n";
} else {
print "Downloading $url\n";
getstore($url, "downloads/$file");
}
{
my $dir = "downloads/perl-$release->{version}";
qx{rm -fR $dir};
mkdir $dir or die "Couldn't create $dir";
qx{
tar -C "downloads" -jxf $dir.tar.bz2 &&\
cd $dir &&\
find . -exec chmod u+w {} + &&\
git init &&\
git add . &&\
git commit -m tmp
};
die "Couldn't create a temp git repo for $release->{version}" if $? != 0;
Devel::PatchPerl->patch_source($release->{version}, $dir);
$patch = qx{
cd $dir && git diff
};
die "Couldn't create a Devel::PatchPerl patch for $release->{version}" if $? != 0;
}
$release->{pause} =~ s#(((.).).*)#$3/$2/$1#;
$release->{extra_flags} = "" unless defined $release->{extra_flags};
for my $config (keys %builds) {
my $output = $template;
$output =~ s/\{\{$_\}\}/$release->{$_}/mg for (qw(version pause extra_flags sha1));
$output =~ s/\{\{args\}\}/$builds{$config}/mg;
my $dir = sprintf "%i.%03i.%03i-%s",
($release->{version} =~ /(\d+)\.(\d+)\.(\d+)/),
$config;
mkdir $dir unless -d $dir;
# Set up the generated DevelPatchPerl.patch
{
open(my $fh, ">$dir/DevelPatchPerl.patch");
print $fh $patch;
}
if (defined $release->{test_parallel} && $release->{test_parallel} eq "no") {
$output =~ s/\{\{test\}\}/make test_harness/;
} elsif (!defined $release->{test_parallel} || $release->{test_parallel} eq "yes") {
$output =~ s/\{\{test\}\}/TEST_JOBS=\$(nproc) make test_harness/;
} else {
die "test_parallel was provided for $release->{version} but is invalid; should be 'yes' or 'no'\n";
}
open my $dockerfile, ">$dir/Dockerfile" or die "Couldn't open $dir/Dockerfile for writing";
print $dockerfile $output;
close $dockerfile;
}
}
=pod
=head1 NAME
generate.pl
=head1 SYNOPSIS
generate.pl is a little helper script to reinitalize the Dockerfiles from a YAML file.
=head1 DESCRIPTION
generate.pl is meant to be run from the actual repo directory, with a Releases.yaml file
correctly configured. It starts with a 'releases' key, which contains a list of releases,
each with the following keys:
=over 4
=item REQUIRED
=over 4
=item version
The actual perl version, such as B<5.20.1>.
=item sha1
The SHA-1 of the C<.tar.bz2> file for that release.
=item pause
The PAUSE (CPAN user) account that the release was uploaded to.
=back
=item OPTIONAL
=over 4
=item extra_args
Additional text to pass to C<Configure>. At the moment, this is necessary for
5.18.x so that it can get the C<-fwrapv> flag.
Default: C<"">
=item test_parallel
This can be either 'no', 'yes', or unspecified (equivalent to 'yes').
Added due to dist/IO/t/io_unix.t failing when TEST_JOBS > 1, but should
only be used in case of a documented issue.
Default: C<yes>
=back
=back
=cut
__DATA__
FROM buildpack-deps
MAINTAINER Peter Martini <[email protected]>
RUN apt-get update \
&& apt-get install -y curl procps \
&& rm -fr /var/lib/apt/lists/*
RUN mkdir /usr/src/perl
COPY *.patch /usr/src/perl/
WORKDIR /usr/src/perl
RUN curl -SL https://cpan.metacpan.org/authors/id/{{pause}}/perl-{{version}}.tar.bz2 -o perl-{{version}}.tar.bz2 \
&& echo '{{sha1}} *perl-{{version}}.tar.bz2' | sha1sum -c - \
&& tar --strip-components=1 -xjf perl-{{version}}.tar.bz2 -C /usr/src/perl \
&& rm perl-{{version}}.tar.bz2 \
&& cat *.patch | patch -p1 \
&& ./Configure {{args}} {{extra_flags}} -des \
&& make -j$(nproc) \
&& {{test}} \
&& make install \
&& cd /usr/src \
&& curl -LO https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm \
&& chmod +x cpanm \
&& ./cpanm App::cpanminus \
&& rm -fr ./cpanm /root/.cpanm /usr/src/perl /tmp/*
WORKDIR /root
CMD ["perl{{version}}","-de0"]