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