/
build.pl
executable file
·233 lines (175 loc) · 5.73 KB
/
build.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env perl
use Data::Dumper;
use File::Slurp;
use Perl::MinimumVersion;
use strict;
### Handle version tasks if asked
for my $arg (@ARGV) {
version_bump() and last if $arg eq '--bump';
if ( $arg eq '--retag' ) { version_retag(); exit; }
if ( $arg eq '--version' ) { print version_current(), "\n"; exit; }
}
### Validate we have what we need to build
# These will be necessary for Make Maker to make the module with proper files.
require CPAN::Meta;
require CPAN::Meta::Converter;
require CPAN::Meta::YAML;
require ExtUtils::MakeMaker;
print "Using ExtUtils::MakeMaker ($ExtUtils::MakeMaker::VERSION)\n";
print "Using CPAN::Meta ($CPAN::Meta::VERSION)\n";
die "You need a modern version of ExtUtils::MakeMaker." unless $ExtUtils::MakeMaker::VERSION > 6;
### Read the config.txt and try to process it
die "No config.txt present." unless -f 'config.txt';
my ($module, $author, $license, $abstract, $description, $perl_ver, %requires);
my $text = read_file('config.txt') ;
1 while chomp $text;
die "No config data." unless length $text;
eval $text;
die $@ if $@;
die "Bad config." unless $module && $author && $license &&
$abstract && $description && %requires;
warn "WARNING: Perl Version is now generated, so you don't need it in the config anymnore.\n";
### Post config
my $path_chunk = $module;
$path_chunk =~ s/::/-/g;
my $bug = 'https://rt.cpan.org/Dist/Display.html?Name='.$path_chunk;
my $repo = 'http://github.com/bennie/perl-' . $path_chunk;
my $git = 'git://github.com/bennie/perl-'.$path_chunk.'.git';
my $sourcefile = 'lib/' . $module . '.pm';
$sourcefile =~ s/::/\//g;
my $require_text = Dumper(\%requires);
$require_text =~ s/\$VAR1 = //;
$require_text =~ s/;$//;
1 while chomp($require_text);
### External data
my $version = version_current();
my $date = `date '+%Y/%m/%d'`;
my $year = `date '+%Y'`;
my $distdir = $path_chunk .'-' . $version;
chomp $date;
chomp $year;
chomp $distdir;
print "
Version : $version
Date : $date
Year : $year
Dist : $distdir
";
### Figure out the provides
my %provides; my $provides;
for my $file ( `find lib -type f -name "*.pm"` ) {
chomp $file;
die "Can't figure out what is provided." unless $file =~ /^lib\/(.+).pm$/;
my $name = $1;
$name =~ s/\//::/g;
$provides{$name} = { file => $file, version => $version };
my $min = Perl::MinimumVersion->new( $file );
$perl_ver = $min->minimum_version;
print "Perl Min Version for $name is $perl_ver\n\n";
}
$provides = Dumper(\%provides);
$provides =~ s/\$VAR1 = //;
$provides =~ s/;$//;
1 while chomp($provides);
### Write Makefile.PL
open MAKEFILE, '>', 'Makefile.PL';
print MAKEFILE "use ExtUtils::MakeMaker;
WriteMakefile(
ABSTRACT => \"$abstract\",
AUTHOR => '$author',
LICENSE => '$license',
NAME => '$module',
VERSION => '$version',
PREREQ_PM => $require_text,
( \$ExtUtils::MakeMaker::VERSION < 6.46
? ()
: ( META_MERGE => {
'meta-spec' => { version => 2 },
no_index => {directory => [qw/t/]},
provides =>
$provides,
release_status => 'stable',
resources => {
repository => {
type => 'git',
url => '$git',
web => '$repo',
},
bugtracker => {
web => '$bug',
},
},
},
)
),
( \$ExtUtils::MakeMaker::VERSION < 6.48
? ()
: ( MIN_PERL_VERSION => '$perl_ver' )
)
);";
close MAKEFILE;
### Build the distribution directory
print `perl Makefile.PL`;
print `make distmeta`;
### Updating the tags
print "\nUpdating DATETAG -> $date\n";
system "find $distdir -type f | xargs perl -p -i -e 's|DATETAG|$date|g'";
print "Updating VERSIONTAG -> $version\n";
system "find $distdir -type f | xargs perl -p -i -e 's|VERSIONTAG|$version|g'";
print "Updating YEARTAG -> $year\n";
system "find $distdir -type f | xargs perl -p -i -e 's|YEARTAG|$year|g'";
print "\n";
### Build the tarball
unlink($distdir.'.tar') if -f $distdir.'.tar';
unlink($distdir.'.tar.gz') if -f $distdir.'.tar.gz';
system "tar cvf $distdir.tar $distdir && gzip --best $distdir.tar";
### META.json check
warn "\nSomething is odd! We didn't build a META.json\n\n"
unless -f $distdir.'/META.json';
### Cleanup
unlink('Makefile');
unlink('Makefile.old');
unlink('Makefile.PL');
unlink('MYMETA.json');
unlink('MYMETA.yml');
print "\nDONE!\n";
### Subroutines
sub version_bump {
my $version = version_current();
my $next_version = version_next($version);
print "Bumping version from $version to $next_version\n";
system("git tag -a $next_version -m 'Version $next_version'");
system("git push --tags origin master");
system("git push --tags github master");
our $version = $next_version;
}
sub version_current {
our $version;
return $version if defined $version and length $version;
$version = `git describe --long | tr '-' ' ' | awk '{ print \$1 }'`;
chomp $version;
$version = '0.01' unless length $version;
return $version;
}
sub version_next {
my $old = shift @_;
$old =~ /^(.+)\.(.+?)$/;
my ($main,$sub) = ($1,$2);
my $length = length($sub);
$sub++;
if ( length($sub) > $length ) {
warn "WARNING: Version length now larger! (From $length digits to ", length($sub), ")\n";
$length = length($sub);
}
return sprintf('%s.%0'.$length.'d',$main,$sub);
}
sub version_retag {
my $tag = version_current();
system("git tag -d $tag");
system("git push origin :refs/tags/$tag");
system("git push github :refs/tags/$tag");
print "\nTagging current as $tag\n";
system("git tag -a $tag -m 'Version $tag'");
system("git push --tags origin master");
system("git push --tags github master");
}