Skip to content

Commit 5150798

Browse files
committed
Use Devel::PatchPerl to generate a standard patch
1 parent a27f453 commit 5150798

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

generate.pl

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use strict;
44
use warnings;
55
use YAML::XS;
6+
use Devel::PatchPerl;
7+
use LWP::Simple;
68

79
sub die_with_sample {
810
die <<EOF;
@@ -42,8 +44,45 @@ sub die_with_sample {
4244
die_with_sample unless defined $yaml->{releases};
4345
die_with_sample unless ref $yaml->{releases} eq "ARRAY";
4446

47+
if (! -d "downloads") {
48+
mkdir "downloads" or die "Couldn't create a downloads directory";
49+
}
50+
4551
for my $release (@{$yaml->{releases}}) {
4652
do { die_with_sample unless $release->{$_}} for (qw(version pause sha1));
53+
54+
die "Bad version: $release->{version}" unless $release->{version} =~ /\A5\.\d+\.\d+\Z/;
55+
56+
my $patch;
57+
my $file = "perl-$release->{version}.tar.bz2";
58+
my $url = "http://www.cpan.org/src/5.0/$file";
59+
if (-f "downloads/$file" &&
60+
`sha1sum downloads/$file` =~ /^\Q$release->{sha1}\E\s+\Qdownloads\/$file\E/) {
61+
print "Skipping download of $file, already current\n";
62+
} else {
63+
print "Downloading $url\n";
64+
getstore($url, "downloads/$file");
65+
}
66+
{
67+
my $dir = "downloads/perl-$release->{version}";
68+
qx{rm -fR $dir};
69+
mkdir $dir or die "Couldn't create $dir";
70+
qx{
71+
tar -C "downloads" -jxf $dir.tar.bz2 &&\
72+
cd $dir &&\
73+
find . -exec chmod u+w {} + &&\
74+
git init &&\
75+
git add . &&\
76+
git commit -m tmp
77+
};
78+
die "Couldn't create a temp git repo for $release->{version}" if $? != 0;
79+
Devel::PatchPerl->patch_source($release->{version}, $dir);
80+
$patch = qx{
81+
cd $dir && git commit -am tmp >/dev/null 2>/dev/null && git format-patch -1 --stdout
82+
};
83+
die "Couldn't create a Devel::PatchPerl patch for $release->{version}" if $? != 0;
84+
}
85+
4786
$release->{pause} =~ s#(((.).).*)#$3/$2/$1#;
4887
$release->{extra_flags} = "" unless defined $release->{extra_flags};
4988

@@ -58,14 +97,10 @@ sub die_with_sample {
5897

5998
mkdir $dir unless -d $dir;
6099

61-
# glob switches behavior in scalar context, so force an intermediate
62-
# list context so we can get the count
63-
if (() = glob "$dir/*.patch") {
64-
$output =~ s#{{copy_patches}}#COPY *.patch /usr/src/perl/#;
65-
$output =~ s#{{apply_patches}}#cat *.patch | patch -p1#;
66-
} else {
67-
$output =~ s/{{copy_patches}}\n//mg;
68-
$output =~ s/.*{{apply_patches}}.*\n//mg;
100+
# Set up the generated DevelPatchPerl.patch
101+
{
102+
open(my $fh, ">$dir/DevelPatchPerl.patch");
103+
print $fh $patch;
69104
}
70105

71106
if (defined $release->{test_parallel} && $release->{test_parallel} eq "no") {
@@ -152,14 +187,14 @@ =head1 DESCRIPTION
152187
&& rm -fr /var/lib/apt/lists/*
153188
154189
RUN mkdir /usr/src/perl
155-
{{copy_patches}}
190+
COPY DevelPatchPerl.patch /usr/src/perl/
156191
WORKDIR /usr/src/perl
157192
158193
RUN curl -SL https://cpan.metacpan.org/authors/id/{{pause}}/perl-{{version}}.tar.bz2 -o perl-{{version}}.tar.bz2 \
159194
&& echo '{{sha1}} *perl-{{version}}.tar.bz2' | sha1sum -c - \
160195
&& tar --strip-components=1 -xjf perl-{{version}}.tar.bz2 -C /usr/src/perl \
161196
&& rm perl-{{version}}.tar.bz2 \
162-
&& {{apply_patches}} \
197+
&& cat DevelPatchPerl.patch | patch -p1
163198
&& ./Configure {{args}} {{extra_flags}} -des \
164199
&& make -j$(nproc) \
165200
&& {{test}} \

0 commit comments

Comments
 (0)