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->{eximpkgdir}, 'doc', 'doc-docbook' );
227 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
228 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
230 # move generated documents from docbook stuff
231 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
232 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
235 # move text documents across
236 foreach my $file ( glob( File::Spec->catfile( 'doc/doc-txt', '*' ) ) ) {
238 # skip a few we dont want
239 my $fn = ( File::Spec->splitpath($file) )[2];
241 if ( ( $fn eq 'ABOUT' )
242 || ( $fn eq 'ChangeLog.0' )
243 || ( $fn eq 'test-harness.txt' ) );
244 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
248 # ------------------------------------------------------------------
250 sub build_pspdfinfo_directory {
253 ##foreach my $format (qw/pdf postscript texinfo info/) {
254 foreach my $format (qw/pdf postscript/) {
255 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
256 mkpath( $target, { verbose => ( $verbose || $debug ) } );
258 # move documents across
262 $context->{release_tree},
266 ( $format eq 'postscript' )
274 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
279 # ------------------------------------------------------------------
281 sub build_main_package_directory {
284 # build the exim package directory path
285 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
287 # initially we move the exim-src directory to the new directory name
288 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
289 || croak "Rename of src dir failed - $!";
291 # add Local subdirectory
292 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
294 # now add the text docs
295 move_text_docs_into_pkg($context);
298 # ------------------------------------------------------------------
300 sub build_package_directories {
303 build_main_package_directory($context);
304 build_pspdfinfo_directory($context);
307 # ------------------------------------------------------------------
312 print "Cleaning up\n" if ($verbose);
313 rmtree( $context->{release_tree}, { verbose => $debug } );
314 rmtree( $context->{docbook}, { verbose => $debug } );
315 rmtree( $context->{pkgdirs}, { verbose => $debug } );
318 # ------------------------------------------------------------------
320 sub create_tar_files {
323 my $pkgs = $context->{pkgs};
324 my $pkgdirs = $context->{pkgdirs};
325 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
326 my $dirname = ( File::Spec->splitdir($dir) )[-1];
327 system("tar cfz ${pkgs}/${dirname}.tar.gz -C ${pkgdirs} ${dirname}");
328 system("tar cfj ${pkgs}/${dirname}.tar.bz2 -C ${pkgdirs} ${dirname}");
332 # ------------------------------------------------------------------
338 orig_dir => File::Spec->curdir(),
339 tmp_dir => File::Temp->newdir(),
340 webgen_base => "$FindBin::Bin/../../../exim-website",
344 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
348 'directory=s' => \$context->{directory},
349 'webgen_base=s' => \$context->{webgen_base},
350 'verbose!' => \$verbose,
354 'delete!' => \$delete,
355 'cleanup!' => \$cleanup,
359 pod2usage( -exitval => 1, -verbose => 0 );
361 pod2usage(0) if $help;
362 pod2usage( -verbose => 2 ) if $man;
364 get_and_check_version( shift, $context );
365 $context->{tag} = build_tag($context);
366 deal_with_working_directory( $context, $delete );
367 export_git_tree($context);
368 chdir( $context->{directory} ) || die;
369 unpack_tree($context);
370 adjust_version_extension($context);
371 build_documentation($context);
372 build_package_directories($context);
373 create_tar_files($context);
374 do_cleanup($context) if ($cleanup);
383 mk_exim_release.pl - Build an exim release
387 mk_exim_release.pl [options] version
390 --debug force debug mode (SQL Trace)
391 --verbose force verbose mode
392 --help display this help and exits
393 --man displays man page
394 --directory=dir dir to package
395 --delete Delete packaging directory at start
403 Forces debug mode cause all SQL statements generated by L<DBIx::Class>
408 Force verbose mode - currently this has no effect
412 Display help and exits
422 Builds an exim release.
424 Starting in a populated git repo that has already been tagged for
425 release, build docs, build packages etc.
427 Parameter is the version number to build as - ie 4.72 4.72RC1 etc
431 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
435 Copyright 2010 Exim Maintainers. All rights reserved.