3 # $Cambridge: exim/release-process/scripts/mk_exim_release.pl,v 1.1 2010/06/03 12:00:38 nm4 Exp $
20 # ------------------------------------------------------------------
22 sub get_and_check_version {
26 # make sure this looks like a real release version
27 # which should (currently) be 4.xx or 4.xx_RCx
28 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
29 croak "The given version number does not look right - $release";
31 my $full_release = $1; # untainted here...
32 my $trunc_release = $full_release;
33 $trunc_release =~ s/^(4\.\d\d)(?:_RC\d+)?$/$1/;
35 $context->{release} = $full_release;
36 $context->{trelease} = $trunc_release;
39 # ------------------------------------------------------------------
44 # The CVS tag consists of exim-$version where $version
45 # is the version number with . replaced with _
46 my $modversion = $context->{release};
47 $modversion =~ tr/0-9RC/_/cs;
49 return sprintf( 'exim-%s', $modversion );
52 # ------------------------------------------------------------------
54 sub deal_with_working_directory {
58 # Set default directory
59 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
60 my $directory = $context->{directory};
62 # ensure the working directory is not in place
63 if ( -d $directory ) {
65 print "Deleting existing $directory\n" if ($verbose);
66 rmtree( $directory, { verbose => $debug } );
68 if ( -d $directory ) {
69 croak "Working directory $directory exists";
73 # create base directory
74 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
76 # set and create subdirectories
77 foreach (qw(release_tree pkgs pkgdirs docbook)) {
78 $context->{$_} = File::Spec->catdir( $context->{directory}, $_ );
79 mkpath( $context->{$_}, { verbose => ( $verbose || $debug ) } );
83 # ------------------------------------------------------------------
89 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp_dir}, $context->{pkgname}, $context->{release} );
90 $context->{tmp_archive_file} = $archive_file;
91 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
94 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
95 system(@cmd) == 0 || croak "Export failed";
98 # ------------------------------------------------------------------
103 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
104 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file}, '-C', $context->{release_tree} );
107 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
108 system(@cmd) == 0 || croak "Unpack failed";
111 # ------------------------------------------------------------------
113 sub adjust_version_extension {
116 return if ($context->{release} eq $context->{trelease});
118 my $variant = substr( $context->{release}, length($context->{trelease}) );
119 if ( $context->{release} ne $context->{trelease} . $variant ) {
120 die "Broken version numbering, I'm buggy";
123 my $srcdir = File::Spec->catdir( $context->{release_tree}, 'src', 'src' );
124 my $version_h = File::Spec->catfile( $srcdir, 'version.h' );
126 my $fh = new IO::File $version_h, 'r';
127 die "Cannot read version.h: $!\n" unless ( defined $fh );
129 $fh->close() or die "Failed to close-read($version_h): $!\n";
133 for ( $i = 0 ; $i < @lines ; ++$i ) {
134 if ( $lines[$i] =~ /EXIM_VARIANT_VERSION/ ) {
139 die "Cannot find version.h EXIM_VARIANT_VERSION\n" unless $found;
140 unless ( $lines[$i] =~ m/^\s* \# \s* define \s+ EXIM_VARIANT_VERSION \s+ "(.*)" \s* $/x ) {
141 die "Broken version.h EXIM_VARIANT_VERSION line\n";
144 print( "WARNING: version.h has a variant tag already defined: $1\n" );
145 print( " not changing that tag\n" );
149 $lines[$i] = qq{#define EXIM_VARIANT_VERSION\t\t"$variant"\n};
150 # deliberately not verbose constrained:
151 print( "Adjusting version.h for $variant release.\n" );
153 $fh = new IO::File $version_h, "w";
154 die "Cannot write version.h: $!\n" unless ( defined $fh );
155 $fh->print( @lines );
156 $fh->close() or die "Failed to close-write($version_h): $!\n";
159 # ------------------------------------------------------------------
161 sub build_html_documentation {
164 my $genpath = $context->{webgen_base} . '/script/gen.pl';
165 my $templates = $context->{webgen_base} . '/templates';
166 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
167 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
168 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
173 ( $genpath, '--spec', $spec, '--filter', $filter, '--latest', $context->{trelease}, '--tmpl', $templates, '--docroot', $dir );
175 print "Executing ", join( ' ', @cmd ), "\n";
178 # move directory into right place
179 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
182 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
183 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
187 # ------------------------------------------------------------------
189 sub copy_docbook_files {
192 # where the generated docbook files can be found
193 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
195 # where the website docbook source dir is - push files to here
196 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
197 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
199 foreach my $file ( 'spec.xml', 'filter.xml' ) {
200 my $from = File::Spec->catfile( $docdir, $file );
201 my $to = File::Spec->catfile( $context->{docbook}, $file );
202 my $webto = File::Spec->catfile( $webdir, $file );
204 copy( $from, $webto );
208 # ------------------------------------------------------------------
210 sub build_documentation {
213 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
214 system("cd '$docdir' && ./OS-Fixups && make everything") == 0
215 || croak "Doc build failed";
217 copy_docbook_files($context);
218 build_html_documentation($context);
221 # ------------------------------------------------------------------
223 sub move_text_docs_into_pkg {
226 my $old_docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
227 my $old_txtdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-txt' );
228 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
229 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
231 # move generated documents from docbook stuff
232 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
233 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
236 # move text documents across
237 foreach my $file ( glob( File::Spec->catfile( $old_txtdir, '*' ) ) ) {
239 # skip a few we dont want
240 my $fn = ( File::Spec->splitpath($file) )[2];
242 if ( ( $fn eq 'ABOUT' )
243 || ( $fn eq 'ChangeLog.0' )
244 || ( $fn eq 'test-harness.txt' ) );
245 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
249 # ------------------------------------------------------------------
251 sub build_pspdfinfo_directory {
254 ##foreach my $format (qw/pdf postscript texinfo info/) {
255 foreach my $format (qw/pdf postscript/) {
256 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
257 mkpath( $target, { verbose => ( $verbose || $debug ) } );
259 # move documents across
263 $context->{release_tree},
267 ( $format eq 'postscript' )
275 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
280 # ------------------------------------------------------------------
282 sub build_main_package_directory {
285 # build the exim package directory path
286 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
288 # initially we move the exim-src directory to the new directory name
289 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
290 || croak "Rename of src dir failed - $!";
292 # add Local subdirectory
293 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
295 # now add the text docs
296 move_text_docs_into_pkg($context);
299 # ------------------------------------------------------------------
301 sub build_package_directories {
304 build_main_package_directory($context);
305 build_pspdfinfo_directory($context);
308 # ------------------------------------------------------------------
313 print "Cleaning up\n" if ($verbose);
314 rmtree( $context->{release_tree}, { verbose => $debug } );
315 rmtree( $context->{docbook}, { verbose => $debug } );
316 rmtree( $context->{pkgdirs}, { verbose => $debug } );
319 # ------------------------------------------------------------------
321 sub create_tar_files {
324 my $pkgs = $context->{pkgs};
325 my $pkgdirs = $context->{pkgdirs};
326 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
327 my $dirname = ( File::Spec->splitdir($dir) )[-1];
328 system("tar cfz ${pkgs}/${dirname}.tar.gz -C ${pkgdirs} ${dirname}");
329 system("tar cfj ${pkgs}/${dirname}.tar.bz2 -C ${pkgdirs} ${dirname}");
333 # ------------------------------------------------------------------
339 orig_dir => File::Spec->curdir(),
340 tmp_dir => File::Temp->newdir(),
341 webgen_base => "$FindBin::Bin/../../../exim-website",
345 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
349 'directory=s' => \$context->{directory},
350 'webgen_base=s' => \$context->{webgen_base},
351 'verbose!' => \$verbose,
355 'delete!' => \$delete,
356 'cleanup!' => \$cleanup,
360 pod2usage( -exitval => 1, -verbose => 0 );
362 pod2usage(0) if $help;
363 pod2usage( -verbose => 2 ) if $man;
365 get_and_check_version( shift, $context );
366 $context->{tag} = build_tag($context);
367 deal_with_working_directory( $context, $delete );
368 export_git_tree($context);
369 chdir( $context->{directory} ) || die;
370 unpack_tree($context);
371 adjust_version_extension($context);
372 build_documentation($context);
373 build_package_directories($context);
374 create_tar_files($context);
375 do_cleanup($context) if ($cleanup);
384 mk_exim_release.pl - Build an exim release
388 mk_exim_release.pl [options] version
391 --debug force debug mode (SQL Trace)
392 --verbose force verbose mode
393 --help display this help and exits
394 --man displays man page
395 --directory=dir dir to package
396 --delete Delete packaging directory at start
404 Forces debug mode cause all SQL statements generated by L<DBIx::Class>
409 Force verbose mode - currently this has no effect
413 Display help and exits
423 Builds an exim release.
425 Starting in a populated git repo that has already been tagged for
426 release, build docs, build packages etc.
428 Parameter is the version number to build as - ie 4.72 4.72RC1 etc
432 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
436 Copyright 2010 Exim Maintainers. All rights reserved.