release: don't try to sign .tar.lz files
[exim.git] / release-process / scripts / mk_exim_release.pl
CommitLineData
46c573de 1#!/usr/bin/env perl
3634fc25 2
8a483da6
NM
3use strict;
4use warnings;
5use Carp;
6use File::Copy;
7use File::Spec;
8use File::Path;
8f29c950 9use File::Temp;
be914e6c 10use FindBin;
8a483da6 11use Getopt::Long;
ba41f854 12use IO::File;
8a483da6
NM
13use Pod::Usage;
14
15my $debug = 0;
16my $verbose = 0;
17
18# ------------------------------------------------------------------
19
20sub get_and_check_version {
21 my $release = shift;
be914e6c 22 my $context = shift;
8a483da6
NM
23
24 # make sure this looks like a real release version
8f29c950 25 # which should (currently) be 4.xx or 4.xx_RCx
8a483da6
NM
26 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
27 croak "The given version number does not look right - $release";
28 }
be914e6c
NM
29 my $full_release = $1; # untainted here...
30 my $trunc_release = $full_release;
31 $trunc_release =~ s/^(4\.\d\d)(?:_RC\d+)?$/$1/;
32
33 $context->{release} = $full_release;
34 $context->{trelease} = $trunc_release;
8a483da6
NM
35}
36
37# ------------------------------------------------------------------
38
8f29c950 39sub build_tag {
8a483da6
NM
40 my $context = shift;
41
42 # The CVS tag consists of exim-$version where $version
43 # is the version number with . replaced with _
44 my $modversion = $context->{release};
45 $modversion =~ tr/0-9RC/_/cs;
46
47 return sprintf( 'exim-%s', $modversion );
48}
49
50# ------------------------------------------------------------------
51
52sub deal_with_working_directory {
53 my $context = shift;
54 my $delete = shift;
55
56 # Set default directory
57 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
58 my $directory = $context->{directory};
59
60 # ensure the working directory is not in place
61 if ( -d $directory ) {
62 if ($delete) {
63 print "Deleting existing $directory\n" if ($verbose);
64 rmtree( $directory, { verbose => $debug } );
65 }
66 if ( -d $directory ) {
67 croak "Working directory $directory exists";
68 }
69 }
70
46c573de 71 # create base directory
8a483da6 72 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
46c573de
NM
73
74 # set and create subdirectories
5901f0ab 75 foreach (qw(release_tree pkgs pkgdirs docbook tmp)) {
46c573de
NM
76 $context->{$_} = File::Spec->catdir( $context->{directory}, $_ );
77 mkpath( $context->{$_}, { verbose => ( $verbose || $debug ) } );
78 }
8a483da6
NM
79}
80
81# ------------------------------------------------------------------
82
8f29c950 83sub export_git_tree {
8a483da6
NM
84 my $context = shift;
85
8f29c950 86 # build git command
5901f0ab 87 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp}, $context->{pkgname}, $context->{release} );
8f29c950
NM
88 $context->{tmp_archive_file} = $archive_file;
89 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
8a483da6 90
8f29c950 91 # run git command
8a483da6
NM
92 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
93 system(@cmd) == 0 || croak "Export failed";
94}
95
96# ------------------------------------------------------------------
97
8f29c950
NM
98sub unpack_tree {
99 my $context = shift;
100
101 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
46c573de 102 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file}, '-C', $context->{release_tree} );
8f29c950
NM
103
104 # run command
105 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
106 system(@cmd) == 0 || croak "Unpack failed";
107}
108
109# ------------------------------------------------------------------
110
5901f0ab 111sub make_version_script {
ba41f854
PP
112 my $context = shift;
113
ba41f854
PP
114 my $variant = substr( $context->{release}, length($context->{trelease}) );
115 if ( $context->{release} ne $context->{trelease} . $variant ) {
116 die "Broken version numbering, I'm buggy";
117 }
5901f0ab 118
ba41f854 119 my $srcdir = File::Spec->catdir( $context->{release_tree}, 'src', 'src' );
5901f0ab
TF
120 chdir $srcdir or die "chdir $srcdir: $\n";
121
122 if ( -f "version.sh" ) {
123 print( "WARNING: version.sh already exists - leaving it in place\n" );
ba41f854
PP
124 return;
125 }
126
5901f0ab
TF
127 my @cmd = ("../scripts/reversion", "release");
128 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
129 system(@cmd) == 0 || croak "reversion failed";
130
131 unlink "version.h";
ba41f854 132
5901f0ab 133 -f "version.sh" or die "failed to create version.h";
ba41f854
PP
134}
135
136# ------------------------------------------------------------------
137
be914e6c
NM
138sub build_html_documentation {
139 my $context = shift;
140
141 my $genpath = $context->{webgen_base} . '/script/gen.pl';
142 my $templates = $context->{webgen_base} . '/templates';
46c573de
NM
143 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
144 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
145 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
146
be914e6c
NM
147 mkdir($dir);
148
46c573de
NM
149 my @cmd =
150 ( $genpath, '--spec', $spec, '--filter', $filter, '--latest', $context->{trelease}, '--tmpl', $templates, '--docroot', $dir );
be914e6c
NM
151
152 print "Executing ", join( ' ', @cmd ), "\n";
153 system(@cmd);
154
155 # move directory into right place
46c573de
NM
156 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
157
158 rename(
159 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
160 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
161 );
162}
163
164# ------------------------------------------------------------------
165
166sub copy_docbook_files {
167 my $context = shift;
168
169 # where the generated docbook files can be found
170 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
171
172 # where the website docbook source dir is - push files to here
173 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
174 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
175
176 foreach my $file ( 'spec.xml', 'filter.xml' ) {
177 my $from = File::Spec->catfile( $docdir, $file );
178 my $to = File::Spec->catfile( $context->{docbook}, $file );
179 my $webto = File::Spec->catfile( $webdir, $file );
180 copy( $from, $to );
181 copy( $from, $webto );
182 }
be914e6c
NM
183}
184
185# ------------------------------------------------------------------
186
8a483da6 187sub build_documentation {
be914e6c
NM
188 my $context = shift;
189
46c573de
NM
190 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
191 system("cd '$docdir' && ./OS-Fixups && make everything") == 0
8a483da6 192 || croak "Doc build failed";
be914e6c 193
46c573de 194 copy_docbook_files($context);
be914e6c 195 build_html_documentation($context);
8a483da6
NM
196}
197
198# ------------------------------------------------------------------
199
200sub move_text_docs_into_pkg {
201 my $context = shift;
202
821bc55f
PP
203 my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
204 my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
46c573de 205 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
8a483da6
NM
206 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
207
208 # move generated documents from docbook stuff
209 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
210 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
211 }
212
213 # move text documents across
821bc55f 214 foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
8a483da6
NM
215
216 # skip a few we dont want
217 my $fn = ( File::Spec->splitpath($file) )[2];
218 next
219 if ( ( $fn eq 'ABOUT' )
220 || ( $fn eq 'ChangeLog.0' )
221 || ( $fn eq 'test-harness.txt' ) );
222 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
223 }
224}
225
226# ------------------------------------------------------------------
227
228sub build_pspdfinfo_directory {
229 my $context = shift;
230
231 ##foreach my $format (qw/pdf postscript texinfo info/) {
232 foreach my $format (qw/pdf postscript/) {
46c573de 233 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
8a483da6
NM
234 mkpath( $target, { verbose => ( $verbose || $debug ) } );
235
236 # move documents across
237 foreach my $file (
238 glob(
239 File::Spec->catfile(
46c573de
NM
240 $context->{release_tree},
241 'doc',
242 'doc-docbook',
8a483da6
NM
243 (
244 ( $format eq 'postscript' )
245 ? '*.ps'
246 : ( '*.' . $format )
247 )
248 )
249 )
250 )
251 {
46c573de 252 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
8a483da6
NM
253 }
254 }
255}
256
257# ------------------------------------------------------------------
258
8a483da6
NM
259sub build_main_package_directory {
260 my $context = shift;
261
46c573de
NM
262 # build the exim package directory path
263 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
264
8a483da6 265 # initially we move the exim-src directory to the new directory name
46c573de
NM
266 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
267 || croak "Rename of src dir failed - $!";
8a483da6
NM
268
269 # add Local subdirectory
46c573de 270 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
8a483da6
NM
271
272 # now add the text docs
273 move_text_docs_into_pkg($context);
274}
275
276# ------------------------------------------------------------------
277
278sub build_package_directories {
279 my $context = shift;
280
281 build_main_package_directory($context);
282 build_pspdfinfo_directory($context);
8a483da6
NM
283}
284
285# ------------------------------------------------------------------
286
46c573de
NM
287sub do_cleanup {
288 my $context = shift;
289
290 print "Cleaning up\n" if ($verbose);
291 rmtree( $context->{release_tree}, { verbose => $debug } );
292 rmtree( $context->{docbook}, { verbose => $debug } );
293 rmtree( $context->{pkgdirs}, { verbose => $debug } );
294}
295
296# ------------------------------------------------------------------
297
9d0311ff
PP
298# We prefer gtar to tar if gtar exists in $PATH
299
300sub fix_paths_tar {
301 my $context = shift;
302 my $tar = $context->{tar_cmd};
303
304 return unless $tar eq 'tar';
305
306 foreach my $d (File::Spec->path()) {
307 my $p = File::Spec->catfile($d, 'gtar');
308 if (-x $p) {
309 $context->{tar_cmd} = $p;
310 print "Switched tar command to: $p\n" if ($verbose);
311 return;
312 }
313 }
314}
315
316# ------------------------------------------------------------------
317
8a483da6
NM
318sub create_tar_files {
319 my $context = shift;
320
46c573de
NM
321 my $pkgs = $context->{pkgs};
322 my $pkgdirs = $context->{pkgdirs};
9d0311ff
PP
323 my $tar = $context->{tar_cmd};
324 if ($verbose) {
325 foreach my $c (keys %{ $context->{compressors} }) {
326 print "Compression: $c\t$context->{compressors}{$c}\n";
327 }
328 }
329
46c573de
NM
330 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
331 my $dirname = ( File::Spec->splitdir($dir) )[-1];
9d0311ff
PP
332 if ($context->{compressors}{gzip}) {
333 print "Creating: ${pkgs}/${dirname}.tar.gz\n" if ($verbose);
334 system("$tar cf ${pkgs}/${dirname}.tar.gz --gzip -C ${pkgdirs} ${dirname}")
335 }
336 if ($context->{compressors}{bzip2}) {
337 print "Creating: ${pkgs}/${dirname}.tar.bz2\n" if ($verbose);
338 system("$tar cf ${pkgs}/${dirname}.tar.bz2 --bzip2 -C ${pkgdirs} ${dirname}")
339 }
340 if ($context->{compressors}{lzip}) {
341 print "Creating: ${pkgs}/${dirname}.tar.lz\n" if ($verbose);
342 system("$tar cf ${pkgs}/${dirname}.tar.lz --lzip -C ${pkgdirs} ${dirname}")
343 }
8a483da6
NM
344 }
345}
346
347# ------------------------------------------------------------------
348{
349 my $man;
350 my $help;
351 my $context = {
be914e6c
NM
352 pkgname => 'exim',
353 orig_dir => File::Spec->curdir(),
354 tmp_dir => File::Temp->newdir(),
355 webgen_base => "$FindBin::Bin/../../../exim-website",
9d0311ff
PP
356 tar_cmd => 'tar',
357 compressors => {
358 gzip => 1,
359 bzip2 => 1,
e099cd0d 360 lzip => 0,
9d0311ff 361 },
8a483da6
NM
362 };
363 my $delete;
46c573de 364 my $cleanup = 1;
8f29c950 365 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
8a483da6
NM
366
367 unless (
368 GetOptions(
be914e6c
NM
369 'directory=s' => \$context->{directory},
370 'webgen_base=s' => \$context->{webgen_base},
9d0311ff
PP
371 'tar' => \$context->{tar_cmd},
372 'lzip!' => \$context->{compressors}{lzip},
be914e6c
NM
373 'verbose!' => \$verbose,
374 'debug!' => \$debug,
375 'help|?' => \$help,
376 'man!' => \$man,
377 'delete!' => \$delete,
46c573de 378 'cleanup!' => \$cleanup,
8a483da6
NM
379 )
380 )
381 {
382 pod2usage( -exitval => 1, -verbose => 0 );
383 }
384 pod2usage(0) if $help;
385 pod2usage( -verbose => 2 ) if $man;
386
be914e6c 387 get_and_check_version( shift, $context );
9d0311ff 388 fix_paths_tar($context);
be914e6c 389 $context->{tag} = build_tag($context);
8a483da6 390 deal_with_working_directory( $context, $delete );
8f29c950 391 export_git_tree($context);
8a483da6 392 chdir( $context->{directory} ) || die;
8f29c950 393 unpack_tree($context);
5901f0ab 394 make_version_script($context);
8a483da6
NM
395 build_documentation($context);
396 build_package_directories($context);
397 create_tar_files($context);
46c573de 398 do_cleanup($context) if ($cleanup);
8a483da6
NM
399}
400
4011;
402
403__END__
404
405=head1 NAME
406
407mk_exim_release.pl - Build an exim release
408
409=head1 SYNOPSIS
410
411mk_exim_release.pl [options] version
412
413 Options:
414 --debug force debug mode (SQL Trace)
415 --verbose force verbose mode
416 --help display this help and exits
417 --man displays man page
9d0311ff 418 --tar=cmd command to use for tar
8a483da6 419 --directory=dir dir to package
9d0311ff 420 --no-lzip do not create .tar.lz files
8a483da6
NM
421 --delete Delete packaging directory at start
422
423=head1 OPTIONS
424
425=over 4
426
427=item B<--debug>
428
429Forces debug mode cause all SQL statements generated by L<DBIx::Class>
430to be output.
431
9d0311ff
PP
432=item B<--tar>
433
434Use to override the path to the tar command; without this, will search for
435gtar, and if not found use tar. Need GNU tar for lzip, unless --no-lzip is
436used.
437
e099cd0d 438=item B<--lzip>
9d0311ff 439
e099cd0d 440Build the lzip tarballs.
9d0311ff 441
8a483da6
NM
442=item B<--verbose>
443
9d0311ff 444Force verbose mode
8a483da6
NM
445
446=item B<--help>
447
448Display help and exits
449
450=item B<--man>
451
452Display man page
453
454=back
455
456=head1 DESCRIPTION
457
458Builds an exim release.
459
8f29c950
NM
460Starting in a populated git repo that has already been tagged for
461release, build docs, build packages etc.
8a483da6
NM
462
463Parameter is the version number to build as - ie 4.72 4.72RC1 etc
464
465=head1 AUTHOR
466
467Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
468
469=head1 COPYRIGHT
470
8f29c950 471Copyright 2010 Exim Maintainers. All rights reserved.
8a483da6
NM
472
473=cut
9d0311ff 474# vim: set sw=4 et :