3 # $Cambridge: exim/release-process/scripts/mk_exim_release.pl,v 1.1 2010/06/03 12:00:38 nm4 Exp $
19 # ------------------------------------------------------------------
21 sub get_and_check_version {
25 # make sure this looks like a real release version
26 # which should (currently) be 4.xx or 4.xx_RCx
27 unless ( $release =~ /^(4\.\d\d(?:_RC\d+)?)$/ ) {
28 croak "The given version number does not look right - $release";
30 my $full_release = $1; # untainted here...
31 my $trunc_release = $full_release;
32 $trunc_release =~ s/^(4\.\d\d)(?:_RC\d+)?$/$1/;
34 $context->{release} = $full_release;
35 $context->{trelease} = $trunc_release;
38 # ------------------------------------------------------------------
43 # The CVS tag consists of exim-$version where $version
44 # is the version number with . replaced with _
45 my $modversion = $context->{release};
46 $modversion =~ tr/0-9RC/_/cs;
48 return sprintf( 'exim-%s', $modversion );
51 # ------------------------------------------------------------------
53 sub deal_with_working_directory {
57 # Set default directory
58 $context->{directory} ||= File::Spec->rel2abs( sprintf( 'exim-packaging-%s', $context->{release} ) );
59 my $directory = $context->{directory};
61 # ensure the working directory is not in place
62 if ( -d $directory ) {
64 print "Deleting existing $directory\n" if ($verbose);
65 rmtree( $directory, { verbose => $debug } );
67 if ( -d $directory ) {
68 croak "Working directory $directory exists";
72 # create base directory
73 mkpath( $context->{directory}, { verbose => ( $verbose || $debug ) } );
75 # set and create subdirectories
76 foreach (qw(release_tree pkgs pkgdirs docbook)) {
77 $context->{$_} = File::Spec->catdir( $context->{directory}, $_ );
78 mkpath( $context->{$_}, { verbose => ( $verbose || $debug ) } );
82 # ------------------------------------------------------------------
88 my $archive_file = sprintf( '%s/%s-%s.tar', $context->{tmp_dir}, $context->{pkgname}, $context->{release} );
89 $context->{tmp_archive_file} = $archive_file;
90 my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{tag} );
93 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
94 system(@cmd) == 0 || croak "Export failed";
97 # ------------------------------------------------------------------
102 die "Cannot see archive file\n" unless ( -f $context->{tmp_archive_file} );
103 my @cmd = ( 'tar', 'xf', $context->{tmp_archive_file}, '-C', $context->{release_tree} );
106 print( "Running: ", join( ' ', @cmd ), "\n" ) if ($verbose);
107 system(@cmd) == 0 || croak "Unpack failed";
110 # ------------------------------------------------------------------
112 sub build_html_documentation {
115 my $genpath = $context->{webgen_base} . '/script/gen.pl';
116 my $templates = $context->{webgen_base} . '/templates';
117 my $dir = File::Spec->catdir( $context->{release_tree}, 'html' );
118 my $spec = File::Spec->catfile( $context->{docbook}, 'spec.xml' );
119 my $filter = File::Spec->catfile( $context->{docbook}, 'filter.xml' );
124 ( $genpath, '--spec', $spec, '--filter', $filter, '--latest', $context->{trelease}, '--tmpl', $templates, '--docroot', $dir );
126 print "Executing ", join( ' ', @cmd ), "\n";
129 # move directory into right place
130 my $sourcedir = File::Spec->catdir( $context->{docbook}, 'filter.xml' );
133 File::Spec->catdir( $dir, sprintf( 'exim-html-%s', $context->{trelease} ) ),
134 File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-html-%s', $context->{release} ) )
138 # ------------------------------------------------------------------
140 sub copy_docbook_files {
143 # where the generated docbook files can be found
144 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
146 # where the website docbook source dir is - push files to here
147 my $webdir = File::Spec->catdir( $context->{webgen_base}, 'docbook', $context->{trelease} );
148 mkpath( $webdir, { verbose => ( $verbose || $debug ) } );
150 foreach my $file ( 'spec.xml', 'filter.xml' ) {
151 my $from = File::Spec->catfile( $docdir, $file );
152 my $to = File::Spec->catfile( $context->{docbook}, $file );
153 my $webto = File::Spec->catfile( $webdir, $file );
155 copy( $from, $webto );
159 # ------------------------------------------------------------------
161 sub build_documentation {
164 my $docdir = File::Spec->catdir( $context->{release_tree}, 'doc', 'doc-docbook' );
165 system("cd '$docdir' && ./OS-Fixups && make everything") == 0
166 || croak "Doc build failed";
168 copy_docbook_files($context);
169 build_html_documentation($context);
172 # ------------------------------------------------------------------
174 sub move_text_docs_into_pkg {
177 my $old_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc', 'doc-docbook' );
178 my $new_docdir = File::Spec->catdir( $context->{eximpkgdir}, 'doc' );
179 mkpath( $new_docdir, { verbose => ( $verbose || $debug ) } );
181 # move generated documents from docbook stuff
182 foreach my $file (qw/exim.8 spec.txt filter.txt/) {
183 move( File::Spec->catfile( $old_docdir, $file ), File::Spec->catfile( $new_docdir, $file ) );
186 # move text documents across
187 foreach my $file ( glob( File::Spec->catfile( 'doc/doc-txt', '*' ) ) ) {
189 # skip a few we dont want
190 my $fn = ( File::Spec->splitpath($file) )[2];
192 if ( ( $fn eq 'ABOUT' )
193 || ( $fn eq 'ChangeLog.0' )
194 || ( $fn eq 'test-harness.txt' ) );
195 move( $file, File::Spec->catfile( $new_docdir, $fn ) );
199 # ------------------------------------------------------------------
201 sub build_pspdfinfo_directory {
204 ##foreach my $format (qw/pdf postscript texinfo info/) {
205 foreach my $format (qw/pdf postscript/) {
206 my $target = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s-%s', $format, $context->{release} ), 'doc' );
207 mkpath( $target, { verbose => ( $verbose || $debug ) } );
209 # move documents across
213 $context->{release_tree},
217 ( $format eq 'postscript' )
225 move( $file, File::Spec->catfile( $target, ( File::Spec->splitpath($file) )[2] ) );
230 # ------------------------------------------------------------------
232 sub build_main_package_directory {
235 # build the exim package directory path
236 $context->{eximpkgdir} = File::Spec->catdir( $context->{pkgdirs}, sprintf( 'exim-%s', $context->{release} ) );
238 # initially we move the exim-src directory to the new directory name
239 rename( File::Spec->catdir( $context->{release_tree}, 'src' ), $context->{eximpkgdir} )
240 || croak "Rename of src dir failed - $!";
242 # add Local subdirectory
243 mkpath( File::Spec->catdir( $context->{eximpkgdir}, 'Local' ), { verbose => ( $verbose || $debug ) } );
245 # now add the text docs
246 move_text_docs_into_pkg($context);
249 # ------------------------------------------------------------------
251 sub build_package_directories {
254 build_main_package_directory($context);
255 build_pspdfinfo_directory($context);
258 # ------------------------------------------------------------------
263 print "Cleaning up\n" if ($verbose);
264 rmtree( $context->{release_tree}, { verbose => $debug } );
265 rmtree( $context->{docbook}, { verbose => $debug } );
266 rmtree( $context->{pkgdirs}, { verbose => $debug } );
269 # ------------------------------------------------------------------
271 sub create_tar_files {
274 my $pkgs = $context->{pkgs};
275 my $pkgdirs = $context->{pkgdirs};
276 foreach my $dir ( glob( File::Spec->catdir( $pkgdirs, ( 'exim*-' . $context->{release} ) ) ) ) {
277 my $dirname = ( File::Spec->splitdir($dir) )[-1];
278 system("tar cfz ${pkgs}/${dirname}.tar.gz -C ${pkgdirs} ${dirname}");
279 system("tar cfj ${pkgs}/${dirname}.tar.bz2 -C ${pkgdirs} ${dirname}");
283 # ------------------------------------------------------------------
289 orig_dir => File::Spec->curdir(),
290 tmp_dir => File::Temp->newdir(),
291 webgen_base => "$FindBin::Bin/../../../exim-website",
295 ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'};
299 'directory=s' => \$context->{directory},
300 'webgen_base=s' => \$context->{webgen_base},
301 'verbose!' => \$verbose,
305 'delete!' => \$delete,
306 'cleanup!' => \$cleanup,
310 pod2usage( -exitval => 1, -verbose => 0 );
312 pod2usage(0) if $help;
313 pod2usage( -verbose => 2 ) if $man;
315 get_and_check_version( shift, $context );
316 $context->{tag} = build_tag($context);
317 deal_with_working_directory( $context, $delete );
318 export_git_tree($context);
319 chdir( $context->{directory} ) || die;
320 unpack_tree($context);
321 build_documentation($context);
322 build_package_directories($context);
323 create_tar_files($context);
324 do_cleanup($context) if ($cleanup);
333 mk_exim_release.pl - Build an exim release
337 mk_exim_release.pl [options] version
340 --debug force debug mode (SQL Trace)
341 --verbose force verbose mode
342 --help display this help and exits
343 --man displays man page
344 --directory=dir dir to package
345 --delete Delete packaging directory at start
353 Forces debug mode cause all SQL statements generated by L<DBIx::Class>
358 Force verbose mode - currently this has no effect
362 Display help and exits
372 Builds an exim release.
374 Starting in a populated git repo that has already been tagged for
375 release, build docs, build packages etc.
377 Parameter is the version number to build as - ie 4.72 4.72RC1 etc
381 Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>
385 Copyright 2010 Exim Maintainers. All rights reserved.