Thread: [Amavisadmin-svn] SF.net SVN: amavisadmin: [46] amavisadmin/trunk/tools/build_script.pl
Status: Beta
Brought to you by:
streindl
From: <str...@us...> - 2007-01-24 21:20:59
|
Revision: 46 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=46&view=rev Author: streindl Date: 2007-01-24 13:20:59 -0800 (Wed, 24 Jan 2007) Log Message: ----------- Initial build script Added Paths: ----------- amavisadmin/trunk/tools/build_script.pl Added: amavisadmin/trunk/tools/build_script.pl =================================================================== --- amavisadmin/trunk/tools/build_script.pl (rev 0) +++ amavisadmin/trunk/tools/build_script.pl 2007-01-24 21:20:59 UTC (rev 46) @@ -0,0 +1,209 @@ +#!/usr/bin/perl -w + +# Script to create a target distribution +# +# it creates a directory dist in the current directory and compiles a ready to use +# war file, database scripts and compiled documentation as well as API +# documentation into this folder. + +use strict; +use English; +use Getopt::Long; +use Pod::Usage; +use File::Path; +use File::stat; + + +my $distdir = "dist"; +my $cleandir = 0; +my $help=0; +my $man=0; +my $createtar=undef; + +GetOptions("path|p=s" => \$distdir, + "tar|t:s" => \$createtar, + "clean|c!" => \$cleandir, + "help|h" => \$help, + "man|m" => \$man) or pod2usage (2); +pod2usage(1) if ($help); +pod2usage(-exitstatus => 0, -verbose => 2) if ($man); + +if (-d "$distdir") { + if ($cleandir) { + my $stat = stat($distdir); + if ($stat->uid() != $UID) { + die "Cannot delete other user's file (security)"; + } + rmtree($distdir); + if (-d "$distdir") { + die "Cannot remove $distdir"; + } + } else { + die "$distdir does already exist"; + } +} + +mkpath ($destdir) or die "Cannot create directory $destdir"; + + + +__END__ + +=head1 NAME + +build_script.pl - Create distribution for AmavisAdmin + +=head1 SYNOPSIS + +build_script.pl [options...] + + Options: + -path=path Destination directory + -clean Clean destination directory if exist + -tar=[file] Create tar output file + -bzip2 Compress output file as bzip2 + -gzip Compress output file as gzip + -help brief help message + -man full documentation + +=head1 OPTIONS + +=over 8 + +=item B<-path> + +You can specify a different output directory for the destination where +the build script will put it's output. For example the command + + B<tools/build_script.pl> -path=I</tmp/dist> + +will build the output into the directory F</tmp/dist>. + +If the target directory does already exist, the script will die with an +error. This can be prevented by using the L</-clean> option. + +The target directory might contain several special tokens which will be +replaced before creating the actual directory. The following tokens are +defined: + +=over 8 + +=item B<%p> + +This token will be replaced by the application name (e.g. B<AmavisAdmin>). + +=item B<%v> + +This token will be replaced by the version (taken from F<conf/version.data>). +The version will be in the form C<major.minor>, e.g. B<1.0>. + +=item B<%V> + +The token will be replaced by the full version number including SVN revision +and branch type together with the information, if the build is based on +modified sources. As this is used in filenames, the version string will +not contain any spaces. An example for B<%V> might look like this: + + 1.0-r123-alpha2-modified + +where C<1.0> is the same as given by B<%v>, the string C<r123> gives the +current SVN revision, C<alpha2> denotes the current tag (see the description +for B<%T> for details).In case the build is based on uncommitted changes to +the repository, the term C<-modified> will be added to the version. This token +is actually a shortcut for + + %v-r%r-%T%m + +=item B<%r> + +This token will be replaced by the subversion revision number (e.g. C<123>). + +=item B<%T> + +This token will be replaced by the branch that is going to be build. In case +of building the trunk you will see the string C<trunk> here, for working in +branches you will see C<branch-> followed by the branch-name +(e.g. C<branch-V1_X>). If you build a tagged version (located under the +F<tags> folder in the subversion repository), only the tag-name itself is +returned (e.g. C<V_1_3_1>). + +=item B<%m> + +This token will be replaced with the string C<-modified> in case the current +working directory has been modified (i.e. the command C<svn status> returns +any output). + +=item B<%d> + +This token will be replaced by the date in the form C<YYYY-MM-DD>. + +=item B<%t> + +This token will be replaced by the current timestamp in the form +C<YYYYMMDDhhmmss>. + +=back + +=item B<-clean> + +If the target directory does already exist, delete the contents before +continuing. This option does nothing if the target directory does not +exist. + +=item B<-tar> + +If set, create a tar file with the contents of the directory just being build. +If the argument is passed without a parameter, the filename will be the name +of the B<-path> parameter followed by C<.tar>. In case no path is given on the +command line, the name will be C<dist.tar>. Please look also for B<-bzip2> and +B<-gzip> for compression. + +The filename can contain the same tokens as defined in the B<-path> option. + +=item B<-bzip2> + +If B<-tar> was given the output tar file will be compressed by using the +L<bzip2> tool. The output file type will be renamed to C<.tar.bzip2>. + +=item B<-bzip2> + +If B<-tar> was given the output tar file will be compressed by using the +L<gzip> tool. The output file type will be renamed to C<.tar.gz>. + +=item B<-help> + +Print a brief help message and exits. + +=item B<-man> + +Prints the manual page and exits. + +=back + +=head1 DESCRIPTION + +This script is used to create a distribution directory and (optionally) a tar +file containing the distribution. + +The script is compiling the web application and creating out of the generated +.war file and other files a directory which follows the following structure: + + path + +---+-LICENSE + +-README + +-NOTES + +-TODO + +-AmavisAdmin.war + +-db (contents of the db sub directory) + +-docs + +----+pdf (generated PDF documentation) + +html(generated HTML documentation) + +txt (generated TXT documentation) + +=head1 AUTHOR + +Stephen Reindl <sr...@sr...> + +=head1 BUGS + +Probably many as this tool is used for development purposes only. Property changes on: amavisadmin/trunk/tools/build_script.pl ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <str...@us...> - 2007-01-24 21:32:39
|
Revision: 48 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=48&view=rev Author: streindl Date: 2007-01-24 13:32:40 -0800 (Wed, 24 Jan 2007) Log Message: ----------- More changes to build script Modified Paths: -------------- amavisadmin/trunk/tools/build_script.pl Modified: amavisadmin/trunk/tools/build_script.pl =================================================================== --- amavisadmin/trunk/tools/build_script.pl 2007-01-24 21:32:13 UTC (rev 47) +++ amavisadmin/trunk/tools/build_script.pl 2007-01-24 21:32:40 UTC (rev 48) @@ -12,7 +12,10 @@ use Pod::Usage; use File::Path; use File::stat; +use Cwd; +use SVN::Client; +sub replaceParams(); my $distdir = "dist"; my $cleandir = 0; @@ -28,6 +31,42 @@ pod2usage(1) if ($help); pod2usage(-exitstatus => 0, -verbose => 2) if ($man); +my $_info; + +sub funcRev { + my( $path, $info, $pool ) = @_; + $_info = $info; +}; + +my $modified = 0; + +my $funcStatus = sub { + $modified = "-modified"; +}; + +my $ctx = SVN::Client->new(); + +my $cwd = getcwd(); +$ctx->info( $cwd, undef, undef, \&funcRev, 0 ); +$ctx->status( $cwd, undef, $funcStatus, 1, 0, 0, 0); +my $revision = $_info->rev; +my $branch="unknown"; + +my $url = $_info->URL; +if ($url =~ /trunk/) { + $branch="trunk"; +} elsif ($url =~ /branches\/([^\/]+)/) { + $branch="b-$1"; +} elsif ($url =~ /tags\/([^\/]+)/) { + $branch="$1"; +} + +replaceParams(); + +print $distdir, "\n"; + +exit 0; + if (-d "$distdir") { if ($cleandir) { my $stat = stat($distdir); @@ -43,8 +82,18 @@ } } -mkpath ($destdir) or die "Cannot create directory $destdir"; +mkpath ($distdir) or die "Cannot create directory $distdir"; +sub replaceParams() { + $distdir =~ s/\%V/\%v-r\%r-\%T\%m/g; + $distdir =~ s/\%v/1.0/g; + $distdir =~ s/\%r/$revision/g; + $distdir =~ s/\%d/YYYY-MM-DD/g; + $distdir =~ s/\%t/YYYYMMDDhhmmss/g; + $distdir =~ s/\%T/$branch/g; + $distdir =~ s/\%m/$modified/g; + $distdir =~ s/\%p/AmavisAdmin/g; +} __END__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <str...@us...> - 2007-01-28 16:44:41
|
Revision: 58 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=58&view=rev Author: streindl Date: 2007-01-28 08:44:38 -0800 (Sun, 28 Jan 2007) Log Message: ----------- Filter tokens in XML sources Modified Paths: -------------- amavisadmin/trunk/tools/build_script.pl Modified: amavisadmin/trunk/tools/build_script.pl =================================================================== --- amavisadmin/trunk/tools/build_script.pl 2007-01-28 12:24:03 UTC (rev 57) +++ amavisadmin/trunk/tools/build_script.pl 2007-01-28 16:44:38 UTC (rev 58) @@ -24,6 +24,7 @@ use File::stat; use File::Basename; use File::Find; +use File::MimeInfo qw(mimetype); use File::Copy; use Cwd; @@ -34,7 +35,7 @@ sub createTar(); sub copy_dir($); -sub replaceParams(); +sub replaceParams($); sub copy_file($$); sub copy_doc_dir(); sub create_file_list(); @@ -45,10 +46,12 @@ my $man=0; my $compressbzip2 = 0; my $compressgzip = 0; -my $createtar=undef; +my $do_createtar=1; +my $createtar; +my $buildtime = time; GetOptions("path|p=s" => \$distdir, - "tar|t:s" => \$createtar, + "tar|t!" => \$do_createtar, "clean|c!" => \$cleandir, "bzip2" => \$compressbzip2, "gzip" => \$compressgzip, @@ -87,13 +90,10 @@ $branch="$1"; } -replaceParams(); +$distdir = replaceParams($distdir); -if (defined $createtar) { - if ($createtar eq "") { - $createtar = $distdir . ".tar"; - } -} +$createtar = $distdir . ".tar"; + my $tempdir = "$distdir/temp"; @@ -111,7 +111,7 @@ print "Output to $distdir\n"; -if (defined $createtar) { +if ($do_createtar) { print "Creating tar file $createtar\n"; } @@ -197,7 +197,7 @@ close OUT; # step 6: Tar and compression -if (defined $createtar) { +if ($do_createtar) { createTar(); if ($compressbzip2) { @@ -246,6 +246,29 @@ find ({wanted => \&file_list_item, no_chdir => 1 }, $distdir); } +sub filter_copy($$) { + my ($from, $to) = @_; + + if ($from =~ /.xml$/) { + my $distfile = basename($distdir); + + open IN, "<$from" or die "Cannot open $from for reading ($!)"; + open OUT, ">$to" or die "Cannot open $to for writing ($!)"; + while (<IN>) { + my $line = $_; + $line =~ s/\@version\@/$version::AmavisVersion/g; + $line =~ s/\@distname\@/$distfile/g; + $line =~ s/\@distfile\@/$createtar/g; + print OUT $line; + } + close IN; + close OUT; + } else { + # fast copy + copy ($from, $to); + } +} + sub callback_doc_file() { my $name = $File::Find::name; return if ($name =~ /\.svn/); @@ -256,7 +279,7 @@ } elsif (-d $name) { mkdir "$tempdir/$name"; } else { - copy ($name, "$tempdir/$name"); + filter_copy ($name, "$tempdir/$name"); } } @@ -298,18 +321,22 @@ copy ($from, $to) or die "Copy failed ($!)"; } -sub replaceParams() { - $distdir =~ s/\%V/\%v-r\%r-\%T\%m/g; +sub replaceParams($) { + my $parm = shift; + + $parm =~ s/\%V/\%v-r\%r-\%T\%m/g; my $version = $version::AmavisVersion; - $distdir =~ s/\%v/$version/g; - $distdir =~ s/\%r/$revision/g; - my $datestamp=time2str("%Y-%m-%d", time()); - my $timestamp=time2str("%Y%m%d%I%M%S", time()); - $distdir =~ s/\%d/$datestamp/g; - $distdir =~ s/\%t/$timestamp/g; - $distdir =~ s/\%T/$branch/g; - $distdir =~ s/\%m/$modified/g; - $distdir =~ s/\%p/AmavisAdmin/g; + $parm =~ s/\%v/$version/g; + $parm =~ s/\%r/$revision/g; + my $datestamp=time2str("%Y-%m-%d", $buildtime); + my $timestamp=time2str("%Y%m%d%I%M%S", $buildtime); + $parm =~ s/\%d/$datestamp/g; + $parm =~ s/\%t/$timestamp/g; + $parm =~ s/\%T/$branch/g; + $parm =~ s/\%m/$modified/g; + $parm =~ s/\%p/AmavisAdmin/g; + + return $parm; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |