Subversion Repositories DevTools

Rev

Rev 243 | Rev 275 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! perl
########################################################################
# Copyright (C) 2007 ERG Limited, All rights reserved
#
# Module name   : MakePackage.pl
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description   : This script is invoked by the builder to:
#                   1) Perform sanity tests
#                   2) Package up jats
#                 This script is really used to 'release' JATS.
#
#                 This script must be executed within a JATS environment
#                 JATS required JATS to build itself.
#
# Usage:
#
#......................................................................#

use strict;
use warnings;
use Cwd;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use File::Find;
use File::Path;
use File::Copy;
use JatsError;
use JatsSystem;

my $VERSION = "1.0.0";
my $opt_help = 0;
my $opt_manual = 0;
my $opt_buildname;
my $opt_buildversion;
my $opt_package;
my $opt_root;
my $opt_verbose = $ENV{'GBE_VERBOSE'};
my $opt_vargs;

#
#   Parse the user options
#
my $result = GetOptions (
                "help+"             => \$opt_help,
                "manual"            => \$opt_manual,

                "BuildName=s"       => \$opt_buildname,
                "BuildVersion=s"    => \$opt_buildversion,
                "PackageDir=s"      => \$opt_package,
                "BuildRoot=s"       => \$opt_root,
                "Verbose:s"         => \$opt_vargs,

                );

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
pod2usage(-verbose => 1)  if ($opt_help == 2 );
pod2usage(-verbose => 2)  if ($opt_manual || $opt_help > 2);

#
#   Init the error and message subsystem
#
$opt_verbose += 2 unless ( $opt_vargs eq '@' );
ErrorConfig( 'name'    => 'RELEASE_JATS',
             'verbose' => $opt_verbose );

SystemConfig ('ExitOnError' => 1 );

#
#   Sanity Test arguments
#
Error ("Not expecting any command line arguments" )
    if ( $#ARGV >= 0);

#
#   Ensure we have all required parameters
#
Error ("No build name provided" ) unless ( $opt_buildname );
Error ("No build version provided" ) unless ( $opt_buildversion );
Error ("No package directory provided" ) unless ( $opt_package );
Error ("No build root provided" ) unless ( $opt_root );
Error ("Build root is not a directory " ) unless ( -d $opt_root );

#
#   Import Environment Variables
#
my $GBE_PERL = $ENV{GBE_PERL} || Error ("Environment variable GBE_PERL not set");
my $GBE_CORE = $ENV{GBE_CORE} || Error ("Environment variable GBE_CORE not set");

#
#   Remove any existing package directory
#
if ( -d $opt_package )
{
    Message ("Removing existing package image");
    rmtree( $opt_package);
}

Message "Create package image: $opt_package";
mkpath($opt_package, 0, 0775);


for my $dir (glob ("$opt_root/BIN.*" ))
{
    Message "Copy in: $dir";
    System ("cp -r $dir $opt_package")
}

for my $dir qw(CFG TEMPLATES TOOLS)
{
    Message "Copy in: $dir";
    System ("cp -r $opt_root/$dir $opt_package")
}

for my $dir qw(TOOLS/LOCAL)
{
    Message "Remove: $dir";
    rmtree( "$opt_package/$dir" );
}

for my $file qw(Readme.txt ChangeLog.txt)
{
    Message "Copy in: $file";
    System ("cp -r $opt_root/$file $opt_package")
}

for my $file qw(PostInstall.sh)
{
    Message "Copy in: $file";
    System ("cp -r $file $opt_package")
}

#
#   Update version info in some files
#
foreach my $file qw( TOOLS/jats.sh TOOLS/jats.bat TOOLS/jats.pl )
{
    Message "Insert version into: $file";
    my @opts;
    push @opts, ( $file =~ m~\.bat$~ ? '-dos' : '-unix' );
    unlink "$opt_package/$file";
    System ( "$GBE_PERL", "$GBE_CORE/TOOLS/jats_transform_file.pl",
             "-infile=$opt_root/$file",
             "-outfile=$opt_package/$file",
             "-tag=VERSION_TAG,$opt_buildversion",
             "-tag=PACKAGE_TAG,$opt_buildname",
             "-tag=RELEASE_TAG,",
             @opts
            );
}

#
#   Ensure that the jats.pl file has the correct version information
#   inserted into it, by this tool
#
Message ("Validate version embedded into jats.pl" );
my $file = "$opt_package/TOOLS/jats.pl";
my $jversion;
open ( FH, '<', $file ) || Error ("Cannot open: $file", "Reason: $!");
while ( <FH> )
{
    next unless ( m~\s*my\s+\$GBE_VERSION\s+=\s+['"](.*)['"]~ );
    $jversion = $1;
    last;

}
close FH;

Error ("Cannot locate GBE_VERSION in jats.p" ) unless ( $jversion );
Error ("GBE_VERSION definition in jats.pl Does not match released version.",
        "Expecting: $opt_buildversion",
        "Got      : $jversion") unless( $jversion eq $opt_buildversion );



exit 0;

#-------------------------------------------------------------------------------
#   Documentation
#

=pod

=head1 NAME

MakePackage - Release Jats

=head1 SYNOPSIS

 MakePackage [options]

 Options:
    -help               - Brief help message
    -help -help         - Detailed help message
    -man                - Full documentation
    -BuildName=text     - Name of the package being built
    -BuildVersion=text  - Version of the package being built
    -PackageDir=path    - Path to the packaging target directory
    -BuildRoot=path     - Path to the root of the build
    -Verbose=text       - Verbosity control
    

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-help -help>

Print a detailed help message with an explanation for each option.

=item B<-man>

Prints the manual page and exits.

=head1 DESCRIPTION

No user servicable parts in this script.

=cut