Updated mk_exim_release.pl to work with git
[exim.git] / release-process / scripts / mk_exim_release.pl
CommitLineData
8a483da6
NM
1#!/usr/bin/perl
2#
3# $Cambridge: exim/release-process/scripts/mk_exim_release.pl,v 1.1 2010/06/03 12:00:38 nm4 Exp $
4#
5use strict;
6use warnings;
7use Carp;
8use File::Copy;
9use File::Spec;
10use File::Path;
8f29c950 11use File::Temp;
8a483da6
NM
12use Getopt::Long;
13use Pod::Usage;
14
15my $debug = 0;
16my $verbose = 0;
17
18# ------------------------------------------------------------------
19
20sub get_and_check_version {
21 my $release = shift;
22
23 # make sure this looks like a real release version
8f29c950 24 # which should (currently) be 4.xx or 4.xx_RCx
8a483da6
NM
25 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
26 croak "The given version number does not look right - $release";
27 }
28 return $1; # untainted here...
29}
30
31# ------------------------------------------------------------------
32
8f29c950 33sub build_tag {
8a483da6
NM
34 my $context = shift;
35
36 # The CVS tag consists of exim-$version where $version
37 # is the version number with . replaced with _
38 my $modversion = $context->{release};
39 $modversion =~ tr/0-9RC/_/cs;
40
41 return sprintf( 'exim-%s', $modversion );
42}
43
44# ------------------------------------------------------------------
45
46sub deal_with_working_directory {
47 my $context = shift;
48 my $delete = shift;
49
50 # Set default directory
51 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
52 my $directory = $context->{directory};
53
54 # ensure the working directory is not in place
55 if ( -d $directory ) {
56 if ($delete) {
57 print "Deleting existing $directory\n" if ($verbose);
58 rmtree( $directory, { verbose => $debug } );
59 }
60 if ( -d $directory ) {
61 croak "Working directory $directory exists";
62 }
63 }
64
65 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
66}
67
68# ------------------------------------------------------------------
69
8f29c950 70sub export_git_tree {
8a483da6
NM
71 my $context = shift;
72
8f29c950
NM
73 # build git command
74 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp_dir}, $context->{pkgname}, $context->{release} );
75 $context->{tmp_archive_file} = $archive_file;
76 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
8a483da6 77
8f29c950 78 # run git command
8a483da6
NM
79 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
80 system(@cmd) == 0 || croak "Export failed";
81}
82
83# ------------------------------------------------------------------
84
8f29c950
NM
85sub unpack_tree {
86 my $context = shift;
87
88 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
89 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file} );
90
91 # run command
92 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
93 system(@cmd) == 0 || croak "Unpack failed";
94}
95
96# ------------------------------------------------------------------
97
8a483da6 98sub build_documentation {
8f29c950 99 system("cd doc/doc-docbook && ./OS-Fixups && make everything") == 0
8a483da6
NM
100 || croak "Doc build failed";
101}
102
103# ------------------------------------------------------------------
104
105sub move_text_docs_into_pkg {
106 my $context = shift;
107
8f29c950 108 my $old_docdir = 'doc/doc-docbook';
8a483da6
NM
109 my $new_docdir = File::Spec->catdir( $context->{pkgdir}, 'doc' );
110 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
111
112 # move generated documents from docbook stuff
113 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
114 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
115 }
116
117 # move text documents across
8f29c950 118 foreach my $file ( glob( File::Spec->catfile( 'doc/doc-txt', '*' ) ) ) {
8a483da6
NM
119
120 # skip a few we dont want
121 my $fn = ( File::Spec->splitpath($file) )[2];
122 next
123 if ( ( $fn eq 'ABOUT' )
124 || ( $fn eq 'ChangeLog.0' )
125 || ( $fn eq 'test-harness.txt' ) );
126 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
127 }
128}
129
130# ------------------------------------------------------------------
131
132sub build_pspdfinfo_directory {
133 my $context = shift;
134
135 ##foreach my $format (qw/pdf postscript texinfo info/) {
136 foreach my $format (qw/pdf postscript/) {
137 my $dir = sprintf( 'exim-%s-%s', $format, $context->{release} );
138 my $target = File::Spec->catdir( $dir, 'doc' );
139 mkpath( $target, { verbose => ( $verbose || $debug ) } );
140
141 # move documents across
142 foreach my $file (
143 glob(
144 File::Spec->catfile(
8f29c950 145 'doc/doc-docbook',
8a483da6
NM
146 (
147 ( $format eq 'postscript' )
148 ? '*.ps'
149 : ( '*.' . $format )
150 )
151 )
152 )
153 )
154 {
155 my $fn = ( File::Spec->splitpath($file) )[2];
156 move( $file, File::Spec->catfile( $target, $fn ) );
157 }
158 }
159}
160
161# ------------------------------------------------------------------
162
163sub build_html_directory {
164 my $context = shift;
165
166 my $dir = sprintf( 'exim-%s-%s', 'html', $context->{release} );
167 my $target = File::Spec->catdir( $dir, 'doc', 'html' );
168 mkpath( $target, { verbose => ( $verbose || $debug ) } );
169
170 # move documents across
8f29c950
NM
171 move( File::Spec->catdir( 'doc/doc-docbook', 'spec_html' ), File::Spec->catdir( $target, 'spec_html' ) );
172 foreach my $file ( glob( File::Spec->catfile( 'doc/doc-docbook', '*.html' ) ) ) {
8a483da6
NM
173 my $fn = ( File::Spec->splitpath($file) )[2];
174 move( $file, File::Spec->catfile( $target, $fn ) );
175 }
176}
177
178# ------------------------------------------------------------------
179
180sub build_main_package_directory {
181 my $context = shift;
182
183 # initially we move the exim-src directory to the new directory name
184 my $pkgdir = sprintf( 'exim-%s', $context->{release} );
185 $context->{pkgdir} = $pkgdir;
8f29c950 186 rename( 'src', $pkgdir ) || croak "Rename of src dir failed - $!";
8a483da6
NM
187
188 # add Local subdirectory
189 my $target = File::Spec->catdir( $pkgdir, 'Local' );
190 mkpath( $target, { verbose => ( $verbose || $debug ) } );
191
192 # now add the text docs
193 move_text_docs_into_pkg($context);
194}
195
196# ------------------------------------------------------------------
197
198sub build_package_directories {
199 my $context = shift;
200
201 build_main_package_directory($context);
202 build_pspdfinfo_directory($context);
203 build_html_directory($context);
204}
205
206# ------------------------------------------------------------------
207
208sub create_tar_files {
209 my $context = shift;
210
211 foreach my $dir ( glob( 'exim*-' . $context->{release} ) ) {
212 system("tar cfz ${dir}.tar.gz ${dir}");
213 system("tar cfj ${dir}.tar.bz2 ${dir}");
214 }
215}
216
217# ------------------------------------------------------------------
218{
219 my $man;
220 my $help;
221 my $context = {
8a483da6
NM
222 pkgname => 'exim',
223 orig_dir => File::Spec->curdir(),
8f29c950 224 tmp_dir => File::Temp->newdir(),
8a483da6
NM
225 };
226 my $delete;
8f29c950 227 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
8a483da6
NM
228
229 unless (
230 GetOptions(
231 'directory=s' => \$context->{directory},
8a483da6
NM
232 'verbose!' => \$verbose,
233 'debug!' => \$debug,
234 'help|?' => \$help,
235 'man!' => \$man,
236 'delete!' => \$delete,
237 )
238 )
239 {
240 pod2usage( -exitval => 1, -verbose => 0 );
241 }
242 pod2usage(0) if $help;
243 pod2usage( -verbose => 2 ) if $man;
244
245 $context->{release} = get_and_check_version(shift);
8f29c950 246 $context->{tag} = build_tag($context);
8a483da6 247 deal_with_working_directory( $context, $delete );
8f29c950 248 export_git_tree($context);
8a483da6 249 chdir( $context->{directory} ) || die;
8f29c950 250 unpack_tree($context);
8a483da6
NM
251 build_documentation($context);
252 build_package_directories($context);
253 create_tar_files($context);
254}
255
2561;
257
258__END__
259
260=head1 NAME
261
262mk_exim_release.pl - Build an exim release
263
264=head1 SYNOPSIS
265
266mk_exim_release.pl [options] version
267
268 Options:
269 --debug force debug mode (SQL Trace)
270 --verbose force verbose mode
271 --help display this help and exits
272 --man displays man page
273 --directory=dir dir to package
8a483da6
NM
274 --delete Delete packaging directory at start
275
276=head1 OPTIONS
277
278=over 4
279
280=item B<--debug>
281
282Forces debug mode cause all SQL statements generated by L<DBIx::Class>
283to be output.
284
285=item B<--verbose>
286
287Force verbose mode - currently this has no effect
288
289=item B<--help>
290
291Display help and exits
292
293=item B<--man>
294
295Display man page
296
297=back
298
299=head1 DESCRIPTION
300
301Builds an exim release.
302
8f29c950
NM
303Starting in a populated git repo that has already been tagged for
304release, build docs, build packages etc.
8a483da6
NM
305
306Parameter is the version number to build as - ie 4.72 4.72RC1 etc
307
308=head1 AUTHOR
309
310Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
311
312=head1 COPYRIGHT
313
8f29c950 314Copyright 2010 Exim Maintainers. All rights reserved.
8a483da6
NM
315
316=cut