Commit | Line | Data |
---|---|---|
46c573de | 1 | #!/usr/bin/env perl |
3634fc25 | 2 | |
8a483da6 NM |
3 | use strict; |
4 | use warnings; | |
5 | use Carp; | |
6 | use File::Copy; | |
7 | use File::Spec; | |
8 | use File::Path; | |
8f29c950 | 9 | use File::Temp; |
be914e6c | 10 | use FindBin; |
8a483da6 | 11 | use Getopt::Long; |
ba41f854 | 12 | use IO::File; |
8a483da6 NM |
13 | use Pod::Usage; |
14 | ||
15 | my $debug = 0; | |
16 | my $verbose = 0; | |
17 | ||
18 | # ------------------------------------------------------------------ | |
19 | ||
20 | sub 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 | 39 | sub 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 | ||
52 | sub 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 | 83 | sub 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 |
98 | sub 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 | 111 | sub 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 |
138 | sub 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 | ||
cd6d74ab NM |
149 | my @cmd = ( |
150 | $genpath, '--spec', $spec, '--filter', | |
151 | $filter, '--latest', $context->{trelease}, '--tmpl', | |
e14fcb3b | 152 | $templates, '--docroot', $dir, '--localstatic' |
cd6d74ab | 153 | ); |
e14fcb3b | 154 | push @cmd, '--verbose' if $verbose or $debug; |
be914e6c NM |
155 | |
156 | print "Executing ", join( ' ', @cmd ), "\n"; | |
157 | system(@cmd); | |
158 | ||
159 | # move directory into right place | |
46c573de NM |
160 | my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' ); |
161 | ||
162 | rename( | |
163 | File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ), | |
164 | File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) ) | |
165 | ); | |
166 | } | |
167 | ||
168 | # ------------------------------------------------------------------ | |
169 | ||
170 | sub copy_docbook_files { | |
171 | my $context = shift; | |
172 | ||
173 | # where the generated docbook files can be found | |
174 | my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' ); | |
175 | ||
176 | # where the website docbook source dir is - push files to here | |
177 | my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} ); | |
178 | mkpath( $webdir, { verbose => ( $verbose || $debug ) } ); | |
179 | ||
180 | foreach my $file ( 'spec.xml', 'filter.xml' ) { | |
181 | my $from = File::Spec->catfile( $docdir, $file ); | |
182 | my $to = File::Spec->catfile( $context->{docbook}, $file ); | |
183 | my $webto = File::Spec->catfile( $webdir, $file ); | |
184 | copy( $from, $to ); | |
185 | copy( $from, $webto ); | |
186 | } | |
be914e6c NM |
187 | } |
188 | ||
189 | # ------------------------------------------------------------------ | |
190 | ||
8a483da6 | 191 | sub build_documentation { |
be914e6c NM |
192 | my $context = shift; |
193 | ||
46c573de | 194 | my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' ); |
39d16d73 | 195 | # documentation building gets the truncated release, without RC |
a7637438 | 196 | system("cd '$docdir' && ./OS-Fixups && $context->{make_cmd} EXIM_VER=$context->{trelease} everything") == 0 |
8a483da6 | 197 | || croak "Doc build failed"; |
be914e6c | 198 | |
46c573de | 199 | copy_docbook_files($context); |
be914e6c | 200 | build_html_documentation($context); |
8a483da6 NM |
201 | } |
202 | ||
203 | # ------------------------------------------------------------------ | |
204 | ||
205 | sub move_text_docs_into_pkg { | |
206 | my $context = shift; | |
207 | ||
821bc55f PP |
208 | my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' ); |
209 | my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' ); | |
46c573de | 210 | my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' ); |
8a483da6 NM |
211 | mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } ); |
212 | ||
213 | # move generated documents from docbook stuff | |
214 | foreach my $file (qw/exim.8 spec.txt filter.txt/) { | |
215 | move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) ); | |
216 | } | |
217 | ||
218 | # move text documents across | |
821bc55f | 219 | foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) { |
8a483da6 NM |
220 | |
221 | # skip a few we dont want | |
222 | my $fn = ( File::Spec->splitpath($file) )[2]; | |
223 | next | |
224 | if ( ( $fn eq 'ABOUT' ) | |
225 | || ( $fn eq 'ChangeLog.0' ) | |
3394b36a TL |
226 | || ( $fn eq 'test-harness.txt' ) |
227 | # Debian issue re licensing of RFCs | |
228 | || ( $fn =~ /^draft-ietf-.*/ ) | |
229 | || ( $fn =~ /^rfc.*/ ) | |
230 | ); | |
8a483da6 NM |
231 | move( $file, File::Spec->catfile( $new_docdir, $fn ) ); |
232 | } | |
233 | } | |
234 | ||
235 | # ------------------------------------------------------------------ | |
236 | ||
237 | sub build_pspdfinfo_directory { | |
238 | my $context = shift; | |
239 | ||
240 | ##foreach my $format (qw/pdf postscript texinfo info/) { | |
241 | foreach my $format (qw/pdf postscript/) { | |
46c573de | 242 | my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' ); |
8a483da6 NM |
243 | mkpath( $target, { verbose => ( $verbose || $debug ) } ); |
244 | ||
245 | # move documents across | |
246 | foreach my $file ( | |
247 | glob( | |
248 | File::Spec->catfile( | |
46c573de NM |
249 | $context->{release_tree}, |
250 | 'doc', | |
251 | 'doc-docbook', | |
8a483da6 NM |
252 | ( |
253 | ( $format eq 'postscript' ) | |
254 | ? '*.ps' | |
255 | : ( '*.' . $format ) | |
256 | ) | |
257 | ) | |
258 | ) | |
259 | ) | |
260 | { | |
46c573de | 261 | move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) ); |
8a483da6 NM |
262 | } |
263 | } | |
264 | } | |
265 | ||
266 | # ------------------------------------------------------------------ | |
267 | ||
8a483da6 NM |
268 | sub build_main_package_directory { |
269 | my $context = shift; | |
270 | ||
46c573de NM |
271 | # build the exim package directory path |
272 | $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) ); | |
273 | ||
8a483da6 | 274 | # initially we move the exim-src directory to the new directory name |
46c573de NM |
275 | rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} ) |
276 | || croak "Rename of src dir failed - $!"; | |
8a483da6 NM |
277 | |
278 | # add Local subdirectory | |
46c573de | 279 | mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } ); |
8a483da6 NM |
280 | |
281 | # now add the text docs | |
282 | move_text_docs_into_pkg($context); | |
283 | } | |
284 | ||
285 | # ------------------------------------------------------------------ | |
286 | ||
287 | sub build_package_directories { | |
288 | my $context = shift; | |
289 | ||
290 | build_main_package_directory($context); | |
291 | build_pspdfinfo_directory($context); | |
8a483da6 NM |
292 | } |
293 | ||
294 | # ------------------------------------------------------------------ | |
295 | ||
46c573de NM |
296 | sub do_cleanup { |
297 | my $context = shift; | |
298 | ||
299 | print "Cleaning up\n" if ($verbose); | |
300 | rmtree( $context->{release_tree}, { verbose => $debug } ); | |
301 | rmtree( $context->{docbook}, { verbose => $debug } ); | |
302 | rmtree( $context->{pkgdirs}, { verbose => $debug } ); | |
303 | } | |
304 | ||
305 | # ------------------------------------------------------------------ | |
306 | ||
9d0311ff PP |
307 | # We prefer gtar to tar if gtar exists in $PATH |
308 | ||
309 | sub fix_paths_tar { | |
310 | my $context = shift; | |
311 | my $tar = $context->{tar_cmd}; | |
312 | ||
313 | return unless $tar eq 'tar'; | |
314 | ||
315 | foreach my $d (File::Spec->path()) { | |
316 | my $p = File::Spec->catfile($d, 'gtar'); | |
317 | if (-x $p) { | |
318 | $context->{tar_cmd} = $p; | |
319 | print "Switched tar command to: $p\n" if ($verbose); | |
320 | return; | |
321 | } | |
322 | } | |
323 | } | |
324 | ||
325 | # ------------------------------------------------------------------ | |
326 | ||
8a483da6 NM |
327 | sub create_tar_files { |
328 | my $context = shift; | |
329 | ||
46c573de NM |
330 | my $pkgs = $context->{pkgs}; |
331 | my $pkgdirs = $context->{pkgdirs}; | |
9d0311ff PP |
332 | my $tar = $context->{tar_cmd}; |
333 | if ($verbose) { | |
334 | foreach my $c (keys %{ $context->{compressors} }) { | |
335 | print "Compression: $c\t$context->{compressors}{$c}\n"; | |
336 | } | |
337 | } | |
338 | ||
46c573de NM |
339 | foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) { |
340 | my $dirname = ( File::Spec->splitdir($dir) )[-1]; | |
9d0311ff | 341 | if ($context->{compressors}{gzip}) { |
03b76468 | 342 | print "Creating: ${pkgs}/${dirname}.tar.gz\n" if ($verbose || $debug); |
9d0311ff PP |
343 | system("$tar cf ${pkgs}/${dirname}.tar.gz --gzip -C ${pkgdirs} ${dirname}") |
344 | } | |
345 | if ($context->{compressors}{bzip2}) { | |
03b76468 | 346 | print "Creating: ${pkgs}/${dirname}.tar.bz2\n" if ($verbose || $debug); |
9d0311ff PP |
347 | system("$tar cf ${pkgs}/${dirname}.tar.bz2 --bzip2 -C ${pkgdirs} ${dirname}") |
348 | } | |
349 | if ($context->{compressors}{lzip}) { | |
03b76468 | 350 | print "Creating: ${pkgs}/${dirname}.tar.lz\n" if ($verbose || $debug); |
9d0311ff PP |
351 | system("$tar cf ${pkgs}/${dirname}.tar.lz --lzip -C ${pkgdirs} ${dirname}") |
352 | } | |
8a483da6 NM |
353 | } |
354 | } | |
355 | ||
356 | # ------------------------------------------------------------------ | |
357 | { | |
358 | my $man; | |
359 | my $help; | |
360 | my $context = { | |
be914e6c NM |
361 | pkgname => 'exim', |
362 | orig_dir => File::Spec->curdir(), | |
363 | tmp_dir => File::Temp->newdir(), | |
364 | webgen_base => "$FindBin::Bin/../../../exim-website", | |
9d0311ff | 365 | tar_cmd => 'tar', |
a7637438 | 366 | make_cmd => 'make', |
9d0311ff PP |
367 | compressors => { |
368 | gzip => 1, | |
369 | bzip2 => 1, | |
e099cd0d | 370 | lzip => 0, |
9d0311ff | 371 | }, |
8a483da6 NM |
372 | }; |
373 | my $delete; | |
46c573de | 374 | my $cleanup = 1; |
8f29c950 | 375 | ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'}; |
8a483da6 NM |
376 | |
377 | unless ( | |
378 | GetOptions( | |
be914e6c NM |
379 | 'directory=s' => \$context->{directory}, |
380 | 'webgen_base=s' => \$context->{webgen_base}, | |
a7637438 PP |
381 | 'tar=s' => \$context->{tar_cmd}, |
382 | 'make=s' => \$context->{make_cmd}, | |
9d0311ff | 383 | 'lzip!' => \$context->{compressors}{lzip}, |
be914e6c NM |
384 | 'verbose!' => \$verbose, |
385 | 'debug!' => \$debug, | |
386 | 'help|?' => \$help, | |
387 | 'man!' => \$man, | |
388 | 'delete!' => \$delete, | |
46c573de | 389 | 'cleanup!' => \$cleanup, |
8a483da6 NM |
390 | ) |
391 | ) | |
392 | { | |
393 | pod2usage( -exitval => 1, -verbose => 0 ); | |
394 | } | |
395 | pod2usage(0) if $help; | |
396 | pod2usage( -verbose => 2 ) if $man; | |
397 | ||
be914e6c | 398 | get_and_check_version( shift, $context ); |
9d0311ff | 399 | fix_paths_tar($context); |
be914e6c | 400 | $context->{tag} = build_tag($context); |
8a483da6 | 401 | deal_with_working_directory( $context, $delete ); |
8f29c950 | 402 | export_git_tree($context); |
8a483da6 | 403 | chdir( $context->{directory} ) || die; |
8f29c950 | 404 | unpack_tree($context); |
5901f0ab | 405 | make_version_script($context); |
8a483da6 NM |
406 | build_documentation($context); |
407 | build_package_directories($context); | |
408 | create_tar_files($context); | |
46c573de | 409 | do_cleanup($context) if ($cleanup); |
8a483da6 NM |
410 | } |
411 | ||
412 | 1; | |
413 | ||
414 | __END__ | |
415 | ||
416 | =head1 NAME | |
417 | ||
418 | mk_exim_release.pl - Build an exim release | |
419 | ||
420 | =head1 SYNOPSIS | |
421 | ||
422 | mk_exim_release.pl [options] version | |
423 | ||
424 | Options: | |
425 | --debug force debug mode (SQL Trace) | |
426 | --verbose force verbose mode | |
427 | --help display this help and exits | |
428 | --man displays man page | |
9d0311ff | 429 | --tar=cmd command to use for tar |
a7637438 | 430 | --make=cmd command to use for make |
8a483da6 | 431 | --directory=dir dir to package |
9d0311ff | 432 | --no-lzip do not create .tar.lz files |
8a483da6 NM |
433 | --delete Delete packaging directory at start |
434 | ||
435 | =head1 OPTIONS | |
436 | ||
437 | =over 4 | |
438 | ||
439 | =item B<--debug> | |
440 | ||
441 | Forces debug mode cause all SQL statements generated by L<DBIx::Class> | |
442 | to be output. | |
443 | ||
9d0311ff PP |
444 | =item B<--tar> |
445 | ||
446 | Use to override the path to the tar command; without this, will search for | |
447 | gtar, and if not found use tar. Need GNU tar for lzip, unless --no-lzip is | |
448 | used. | |
449 | ||
a7637438 PP |
450 | =item B<--make> |
451 | ||
452 | Use to override the path/name of the make command. | |
453 | Useful sometimes to force gmake. | |
454 | ||
e099cd0d | 455 | =item B<--lzip> |
9d0311ff | 456 | |
e099cd0d | 457 | Build the lzip tarballs. |
9d0311ff | 458 | |
8a483da6 NM |
459 | =item B<--verbose> |
460 | ||
9d0311ff | 461 | Force verbose mode |
8a483da6 NM |
462 | |
463 | =item B<--help> | |
464 | ||
465 | Display help and exits | |
466 | ||
467 | =item B<--man> | |
468 | ||
469 | Display man page | |
470 | ||
471 | =back | |
472 | ||
473 | =head1 DESCRIPTION | |
474 | ||
475 | Builds an exim release. | |
476 | ||
8f29c950 NM |
477 | Starting in a populated git repo that has already been tagged for |
478 | release, build docs, build packages etc. | |
8a483da6 NM |
479 | |
480 | Parameter is the version number to build as - ie 4.72 4.72RC1 etc | |
481 | ||
482 | =head1 AUTHOR | |
483 | ||
484 | Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk> | |
485 | ||
486 | =head1 COPYRIGHT | |
487 | ||
8f29c950 | 488 | Copyright 2010 Exim Maintainers. All rights reserved. |
8a483da6 NM |
489 | |
490 | =cut | |
9d0311ff | 491 | # vim: set sw=4 et : |