Subversion Repositories DevTools

Rev

Rev 227 | Rev 243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 227 Rev 229
Line 1... Line 1...
1
#! perl
1
#! perl
2
########################################################################
2
########################################################################
3
# Copyright (C) 2004 ERG Limited, All rights reserved
3
# Copyright (C) 2007 ERG Limited, All rights reserved
4
#
4
#
5
# Module name   : jats.sh
5
# Module name   : MakePackage.pl
6
# Module type   : Makefile system
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
7
# Compiler(s)   : n/a
8
# Environment(s): jats
8
# Environment(s): jats
9
#
9
#
10
# Description:
10
# Description   : This script is invoked by the builder to:
-
 
11
#                   1) Perform sanity tests
-
 
12
#                   2) Package up jats
-
 
13
#                 This script is really used to 'release' JATS.
-
 
14
#
-
 
15
#                 This script must be executed within a JATS environment
-
 
16
#                 JATS required JATS to build itself.
11
#
17
#
12
# Usage:
18
# Usage:
13
#
19
#
14
# Version   Who      Date        Description
-
 
15
#     1.0   DDP      08-Sep-04   Created
-
 
16
#......................................................................#
20
#......................................................................#
17
 
21
 
18
require 5.6.1;
22
require 5.6.1;
19
use strict;
23
use strict;
20
use warnings;
24
use warnings;
21
use Cwd;
25
use Cwd;
22
use Getopt::Long;
26
use Getopt::Long;
-
 
27
use Pod::Usage;
-
 
28
use File::Basename;
-
 
29
use File::Find;
-
 
30
use File::Path;
-
 
31
use File::Copy;
-
 
32
use JatsError;
-
 
33
use JatsSystem;
23
 
34
 
-
 
35
my $VERSION = "1.0.0";
24
my $opt_help;
36
my $opt_help = 0;
-
 
37
my $opt_manual = 0;
-
 
38
my $opt_buildname;
-
 
39
my $opt_buildversion;
-
 
40
my $opt_package;
25
my $version;
41
my $opt_root;
-
 
42
my $opt_verbose = $ENV{'GBE_VERBOSE'};
-
 
43
my $opt_vargs;
26
 
44
 
27
#
45
#
28
#   Parse the user options
46
#   Parse the user options
29
#
47
#
30
my $result = GetOptions (
48
my $result = GetOptions (
31
                "help+"         => \$opt_help,
49
                "help+"             => \$opt_help,
-
 
50
                "manual"            => \$opt_manual,
-
 
51
 
-
 
52
                "BuildName=s"       => \$opt_buildname,
-
 
53
                "BuildVersion=s"    => \$opt_buildversion,
-
 
54
                "PackageDir=s"      => \$opt_package,
-
 
55
                "BuildRoot=s"       => \$opt_root,
-
 
56
                "Verbose:s"         => \$opt_vargs,
-
 
57
 
32
                );
58
                );
33
help() if ( !$result || $opt_help );
-
 
34
help ("Expecting one command line argument" )
-
 
35
    if ( $#ARGV != 0);
-
 
36
 
-
 
37
$version = $ARGV[0];
-
 
38
$version =~ s~^JATS_~~;
-
 
39
help ("Bad format for package version. Need nn.nn.nn" )
-
 
40
    unless ( $version =~ m~^(\d+\.\d+\.\d+)$~ );
-
 
41
 
59
 
42
#
60
#
43
#   Ensure that the jats.pl file has the correct version information
-
 
44
#   The version number in this file is important as it is published as
-
 
45
#   the JATS version number
61
#   Process help and manual options
46
#
62
#
47
my $line = qx(grep \"my.*\$GBE_VERSION\" ../TOOLS/jats.pl);
63
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
-
 
64
pod2usage(-verbose => 1)  if ($opt_help == 2 );
48
Error ('Cannot locate GBE_VERSION in jats.pl' ) unless ( $line );
65
pod2usage(-verbose => 2)  if ($opt_manual || $opt_help > 2);
49
 
66
 
-
 
67
#
50
$line =~ s~['"](.*).cr['"]~~;
68
#   Init the error and message subsystem
51
$line = $1;
69
#
52
Error ("GBE_VERSION definition in jats.pl Does not match released version.",
70
$opt_verbose += 2 unless ( $opt_vargs eq '@' );
53
        "Expecting: $version",
71
ErrorConfig( 'name'    => 'RELEASE_JATS',
54
        "Got      : $line") unless( $line eq $version );
72
             'verbose' => $opt_verbose );
-
 
73
 
-
 
74
SystemConfig ('ExitOnError' => 1 );
55
 
75
 
56
#
76
#
57
#   Remove any existing package directory
77
#   Sanity Test arguments
58
#
78
#
59
if ( -d "./pkg" )
-
 
60
{
-
 
61
    print "Removing existing package image\n";
79
Error ("Not expecting any command line arguments" )
62
    system ("rm -rf ./pkg");
80
    if ( $#ARGV >= 0);
63
}
-
 
64
 
81
 
-
 
82
#
65
print "Create package image\n";
83
#   Ensure we have all required parameters
-
 
84
#
-
 
85
Error ("No build name provided" ) unless ( $opt_buildname );
-
 
86
Error ("No build version provided" ) unless ( $opt_buildversion );
66
mkdir  ("./pkg");
87
Error ("No package directory provided" ) unless ( $opt_package );
67
mkdir  ("./pkg/core_devl");
88
Error ("No build root provided" ) unless ( $opt_root );
-
 
89
Error ("Build root is not a directory " ) unless ( -d $opt_root );
68
 
90
 
69
#
91
#
70
#   Create a new format descpkg file
92
#   Import Environment Variables
71
#
93
#
72
my $pkgfile = "./pkg/core_devl/descpkg";
-
 
73
my $BUILDNAME_PACKAGE = "core_devl";
94
my $GBE_PERL = $ENV{GBE_PERL} || Error ("Environment variable GBE_PERL not set");
74
my $BUILDNAME_VERSION = $version;
95
my $GBE_CORE = $ENV{GBE_CORE} || Error ("Environment variable GBE_CORE not set");
75
my $BUILDNAME_PROJECT= "cr",
-
 
76
my $CurrentTime = localtime;
-
 
77
my $USER = $ENV{'USER'};
-
 
78
my $Cwd = getcwd();
-
 
79
 
96
 
-
 
97
#
-
 
98
#   Remove any existing package directory
-
 
99
#
-
 
100
if ( -d $opt_package )
-
 
101
{
-
 
102
    Message ("Removing existing package image");
-
 
103
    rmtree( $opt_package);
-
 
104
}
80
 
105
 
81
open( DESCPKG, ">$pkgfile" ) ||
106
Message "Create package image: $opt_package";
82
    Error( "cannot create $pkgfile" );
107
mkpath($opt_package, 0, 0775);
83
 
108
 
84
print DESCPKG "Package Name: $BUILDNAME_PACKAGE\n";
-
 
85
print DESCPKG "Version:      $BUILDNAME_VERSION.$BUILDNAME_PROJECT\n";
-
 
86
print DESCPKG "Released By:  $USER\n";
-
 
87
print DESCPKG "Released On:  $CurrentTime\n";
-
 
88
print DESCPKG "Path:         $Cwd\n";
-
 
89
print DESCPKG "\n";
-
 
90
print DESCPKG "Build Dependencies:\n";
-
 
91
print DESCPKG "\n";
-
 
92
close DESCPKG;
-
 
93
 
109
 
94
for my $dir (glob ('../BIN.*' ))
110
for my $dir (glob ("$opt_root/BIN.*" ))
95
{
111
{
96
    print "Copy in: $dir\n";
112
    Message "Copy in: $dir";
97
    system ("cp -r $dir ./pkg/core_devl")
113
    System ("cp -r $dir $opt_package")
98
}
114
}
99
 
115
 
100
for my $dir qw(CFG TEMPLATES TOOLS)
116
for my $dir qw(CFG TEMPLATES TOOLS)
101
{
117
{
102
    print "Copy in: $dir\n";
118
    Message "Copy in: $dir";
103
    system ("cp -r ../$dir ./pkg/core_devl")
119
    System ("cp -r $opt_root/$dir $opt_package")
104
}
120
}
105
 
121
 
106
for my $dir qw(TOOLS/LOCAL)
122
for my $dir qw(TOOLS/LOCAL)
107
{
123
{
108
    print "Remove in: $dir\n";
124
    Message "Remove: $dir";
109
    system ("rm -rf ./pkg/core_devl/$dir")
125
    rmtree( "$opt_package/$dir" );
110
}
126
}
111
 
127
 
112
for my $file qw(Readme.txt PostInstall.sh ChangeLog.txt)
128
for my $file qw(Readme.txt PostInstall.sh ChangeLog.txt)
113
{
129
{
114
    print "Copy in: $file\n";
130
    Message "Copy in: $file";
115
    system ("cp -r ../$file ./pkg/core_devl")
131
    System ("cp -r $opt_root/$file $opt_package")
116
}
132
}
117
 
133
 
118
#
134
#
119
#   Update version info in some files
135
#   Update version info in some files
120
#
136
#
121
foreach my $file qw( TOOLS/jats.sh TOOLS/jats.bat )
137
foreach my $file qw( TOOLS/jats.sh TOOLS/jats.bat TOOLS/jats.pl )
122
{
138
{
123
    print "Insert version into: $file\n";
139
    Message "Insert version into: $file";
-
 
140
    my @opts;
124
    system "sed -i -e 's~VERSION_TAG~${version}.cr~' ./pkg/core_devl/$file";
141
    push @opts, ( $file =~ m~\.bat$~ ? '-dos' : '-unix' );
125
    if ( $? )
142
    unlink "$opt_package/$file";
-
 
143
    System ( "$GBE_PERL", "$GBE_CORE/TOOLS/jats_transform_file.pl",
126
    {
144
             "-infile=$opt_root/$file",
127
        Error("Failure in SED command. Result: $?");
145
             "-outfile=$opt_package/$file",
-
 
146
             "-tag=VERSION_TAG,$opt_buildversion",
-
 
147
             "-tag=PACKAGE_TAG,$opt_buildname",
-
 
148
             "-tag=RELEASE_TAG,",
-
 
149
             @opts
128
    }
150
            );
129
}
151
}
130
 
152
 
131
system ( "jats.bat -here create_dpkg" );
-
 
132
 
-
 
133
print "Removing existing package image\n";
-
 
134
system ("rm -rf ./pkg");
-
 
135
exit 0;
-
 
136
 
-
 
137
########################################################################
-
 
138
#
153
#
-
 
154
#   Ensure that the jats.pl file has the correct version information
139
#   Give the user a clue
155
#   inserted into it, by this tool
140
#
156
#
-
 
157
Message ("Validate version embedded into jats.pl" );
-
 
158
my $file = "$opt_package/TOOLS/jats.pl";
141
sub help
159
my $jversion;
-
 
160
open ( FH, '<', $file ) || Error ("Cannot open: $file", "Reason: $!");
-
 
161
while ( <FH> )
142
{
162
{
143
    if ( $#_ >= 0 )
-
 
144
    {
-
 
145
        print STDERR    '-' x 80 . "\n";
163
    next unless ( m~\s*my\s+\$GBE_VERSION\s+=\s+['"](.*)['"]~ );
146
        print STDERR    "ERROR: @_\n";
164
    $jversion = $1;
147
        print STDERR    '-' x 80 . "\n\n";
-
 
148
    }
165
    last;
149
 
166
 
150
    print STDERR    "Package JATS ready for release\n";
-
 
151
    print STDERR    "\n";
-
 
152
    print STDERR    "Usage: perl MakePackage nn.nn.nn\n";
-
 
153
    print STDERR    "\n";
-
 
154
    print STDERR    "Where opts:\n";
-
 
155
    print STDERR    "   -h              - Help message\n";
-
 
156
    print STDERR    "\n";
-
 
157
    print STDERR    "Where arguments:\n";
-
 
158
    print STDERR    "   nn.nn.nn        - The version of the release\n";
-
 
159
    print STDERR    "                     This should be based on the \n";
-
 
160
    print STDERR    "                     label applied to the package\n";
-
 
161
    print STDERR    "\n";
-
 
162
    exit 1;
-
 
163
}
167
}
-
 
168
close FH;
-
 
169
 
-
 
170
Error ("Cannot locate GBE_VERSION in jats.p" ) unless ( $jversion );
-
 
171
Error ("GBE_VERSION definition in jats.pl Does not match released version.",
-
 
172
        "Expecting: $opt_buildversion",
-
 
173
        "Got      : $jversion") unless( $jversion eq $opt_buildversion );
-
 
174
 
-
 
175
 
-
 
176
 
-
 
177
exit 0;
164
 
178
 
165
#-------------------------------------------------------------------------------
179
#-------------------------------------------------------------------------------
166
# Function        : Message
-
 
167
#                   Warning
-
 
168
#                   Error
180
#   Documentation
169
#                   _Message ( Internal use only )
-
 
170
#
-
 
171
# Description     : Error, Warning and Message routines
-
 
172
#                   These routines will display a message to the user
-
 
173
#                   with the module name.
-
 
174
#
181
#
175
#                   Multiple arguments are displayed on their own line
-
 
176
#                   with suitable spacing.
-
 
177
#
-
 
178
# Inputs          : Lines of text to display
-
 
179
#
-
 
180
# Returns         : Error() does not return
-
 
181
#
-
 
182
sub _Message
-
 
183
{
-
 
184
    my $tag = shift;                # First argument is a tag
-
 
185
 
182
 
186
    my $prefix = "";
-
 
187
    my $count = 0;
183
=pod
188
 
184
 
189
    #
-
 
190
    #   Generate the message prefix
-
 
191
    #   This will only be used on the first line
-
 
192
    #   All other lines will have a space filled prefix
-
 
193
    #
185
=head1 NAME
194
    $prefix .= $tag;
-
 
195
 
186
 
196
    foreach my $nextline ( @_ )
187
MakePackage - Release Jats
197
    {
-
 
198
        chomp( my $line = $nextline );
-
 
199
        $prefix = ' ' x length($prefix)
-
 
200
            if ( $count eq 1 );
-
 
201
 
188
 
202
        print "$prefix $line\n";
-
 
203
        $count++;
189
=head1 SYNOPSIS
204
    }
-
 
205
}
-
 
206
 
190
 
-
 
191
 MakePackage [options]
-
 
192
 
-
 
193
 Options:
-
 
194
    -help               - Brief help message
-
 
195
    -help -help         - Detailed help message
-
 
196
    -man                - Full documentation
-
 
197
    -BuildName=text     - Name of the package being built
-
 
198
    -BuildVersion=text  - Version of the package being built
-
 
199
    -PackageDir=path    - Path to the packaging target directory
-
 
200
    -BuildRoot=path     - Path to the root of the build
-
 
201
    -Verbose=text       - Verbosity control
-
 
202
    
-
 
203
 
-
 
204
=head1 OPTIONS
-
 
205
 
207
sub Error
206
=over 8
-
 
207
 
-
 
208
=item B<-help>
208
{
209
 
209
    _Message '(E)', @_;
210
Print a brief help message and exits.
-
 
211
 
-
 
212
=item B<-help -help>
-
 
213
 
-
 
214
Print a detailed help message with an explanation for each option.
-
 
215
 
210
    exit 1;
216
=item B<-man>
-
 
217
 
-
 
218
Prints the manual page and exits.
-
 
219
 
-
 
220
=head1 DESCRIPTION
211
}
221
 
-
 
222
No user servicable parts in this script.
212
 
223
 
-
 
224
=cut
213
 
225
 
214
 
226