Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
323 dpurdie 1
########################################################################
2
# Copyright (C) 2010 ERG Limited, All rights reserved
3
#
4
# Module name   : jats_upddep.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Jats utility to Update Build File Dependencies
10
#
11
# Usage         : See below
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
 
19
use Pod::Usage;
20
use Getopt::Long;
21
 
22
use JatsError;
23
use JatsVersionUtils;
24
use JatsRmApi;
25
use JatsSystem;
26
use Cwd;
27
 
28
my $RM_DB;
29
 
30
################################################################################
31
#   Global data
32
#
33
my $VERSION = "1.0.0";
34
my %ReleasePackages;            # Packages in the release
35
my %BuildPackages;              # Packages for this build
36
my $ReleaseName;
37
my $ProjectName;
38
 
39
#
40
#   Options
41
#
42
my $opt_help = 0;
43
my $opt_verbose = 0;
44
my $opt_rtagid;
45
my $opt_show;
46
my $opt_outfile = 'auto.pl';
47
 
48
my $result = GetOptions (
49
                "help|h:+"          => \$opt_help,
50
                "manual:3"          => \$opt_help,
51
                "verbose:+"         => \$opt_verbose,       # flag or number
52
                "rtagid|rtag_id=s"  => \$opt_rtagid,
53
                "out=s"             => \$opt_outfile,
54
                'show:s'            => \$opt_show,
55
                );
56
 
57
#
58
#   Process help and manual options
59
#
60
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
61
pod2usage(-verbose => 1)  if ($opt_help == 2);
62
pod2usage(-verbose => 2)  if ($opt_help > 2);
63
 
64
#
65
#   Configure the error reporting process now that we have the user options
66
#
67
ErrorConfig( 'name'    =>'UPDDEP',
68
             'verbose' => $opt_verbose );
69
 
70
 
71
Error( "No operation specified" )
72
    unless ( $opt_rtagid || defined  $opt_show );
73
 
74
#
75
#   Connect to the RM database
76
#       Uses infor from the JATS environment
77
#           GBE_RM_LOCATION
78
#           GBE_RM_USERNAME
79
#           GBE_RM_PASSWORD
80
#
81
connectRM(\$RM_DB);
82
 
83
#
84
#   Display all the Release Tags in the data base
85
#
86
if ( defined $opt_show )
87
{
88
    show_rtags();
89
    exit (0);
90
}
91
 
92
#
93
#   Ensure that the RTAG exists
94
#   Extract the Release and Project Name
95
#
96
GetReleaseData( $opt_rtagid );
97
Error ("Rtag not found in Release Manager Database: $opt_rtagid") unless ( $ProjectName );
98
Message ("Project Name: $ProjectName");
99
Message ("Release Name: $ReleaseName");
100
#
101
#   Get all package info the specified release
102
#   This is done as one query so it should be fast
103
#
104
getPkgDetailsByRTAG_ID( $opt_rtagid );
105
 
106
#
107
#   Create a configuration file for use by the JATS rewrite tool
108
#   This will allow the build.pl file to be re-written
109
#
110
my $file = "jats_rewrite.cfg";
111
open CFG, ">$file" || Error("Cannot create $file", $! );
112
print CFG "releasemanager.projectname = $ProjectName\n";
113
print CFG "releasemanager.releasename = $ReleaseName\n";
114
 
115
foreach my $pkg ( sort keys %ReleasePackages )
116
{
117
    my $ver;
118
    foreach my $prj ( sort keys %{$ReleasePackages{$pkg}} )
119
    {
120
        $ver  = $ReleasePackages{$pkg}{$prj};
121
        $ver .= '.' . ${prj} if ( $prj );
122
        print CFG "${pkg} ${ver}\n";
123
    }
124
}
125
close CFG;
126
 
127
#
128
#   Massage the build.pl file to create the auto.pl file
129
#   That will be used to create the final package.
130
#
325 dpurdie 131
$result = JatsTool ("jats_rewrite.pl", '-conf', $file,
323 dpurdie 132
                             '-verb', $opt_verbose,
133
                             '-outfile', $opt_outfile,
325 dpurdie 134
                             '-mode=1' );
135
unlink $file;
136
Error("Did not rewrite build.pl file") if ( $result );
323 dpurdie 137
exit 0;
138
 
139
#-------------------------------------------------------------------------------
140
# Function        : GetReleaseData
141
#
142
# Description     : Determine the Release Name and associated project
143
#
144
# Inputs          : $rtag_id
145
#
146
# Returns         : 
147
#
148
sub  GetReleaseData
149
{
150
    my ($RTAG_ID) = @_;
151
    my $foundDetails = 0;
152
    my (@row);
153
 
154
    # First get details from pv_id
155
 
156
    my $m_sqlstr = "SELECT rt.RTAG_NAME, p.PROJ_NAME" .
157
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
158
                    " WHERE rt.RTAG_ID = $RTAG_ID AND rt.PROJ_ID = p.PROJ_ID ";
159
 
160
    my $sth = $RM_DB->prepare($m_sqlstr);
161
    if ( defined($sth) )
162
    {
163
        if ( $sth->execute( ) )
164
        {
165
            if ( $sth->rows )
166
            {
167
                while ( @row = $sth->fetchrow_array )
168
                {
169
#                    print "@row\n";
170
                    ($ReleaseName, $ProjectName) = @row;
171
                    last;
172
                }
173
            }
174
            $sth->finish();
175
        }
176
        else
177
        {
178
        Error("Execute failure: GetReleaseData" );
179
        }
180
    }
181
    else
182
    {
183
        Error("Prepare failure: GetReleaseData" );
184
    }
185
}
186
 
187
#-------------------------------------------------------------------------------
188
# Function        : getPkgDetailsByRTAG_ID
189
#
190
# Description     : 
191
#
192
# Inputs          : rtag_id
193
#
194
# Returns         : Populate %ReleasePackages
195
#
196
sub getPkgDetailsByRTAG_ID
197
{
198
    my ($RTAG_ID) = @_;
199
 
200
    # First get details from pv_id
201
 
202
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
203
                    " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
204
                    " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
205
    my $sth = $RM_DB->prepare($m_sqlstr);
206
    if ( defined($sth) )
207
    {
208
        if ( $sth->execute( ) )
209
        {
210
            if ( $sth->rows )
211
            {
212
                while ( my @row = $sth->fetchrow_array )
213
                {
214
                    my $pv_id   = $row[0];
215
                    my $name    = $row[1];
216
                    my $ver     = $row[2];
217
#                    print "$name $ver\n";
218
 
219
                    #
220
                    #   Store data package name and package suffix
221
                    #
222
                    my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
223
                    $ReleasePackages{$pn}{$pp} = $pv;
224
                }
225
            }
226
            $sth->finish();
227
        }
228
    }
229
    else
230
    {
231
        Error("Prepare failure" );
232
    }
233
}
234
 
235
#-------------------------------------------------------------------------------
236
# Function        : show_rtags
237
#
238
# Description     : Display all RTAGS inthe data base
239
#
240
# Inputs          : 
241
#
242
# Returns         : 
243
#
244
sub show_rtags
245
{
246
    my $foundDetails = 0;
247
    my (@row);
248
    $opt_show = quotemeta( $opt_show );
249
 
250
    # First get details from pv_id
251
 
252
    my $m_sqlstr = "SELECT rt.RTAG_ID, p.PROJ_NAME, rt.RTAG_NAME" .
253
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
254
                    " WHERE rt.PROJ_ID = p.PROJ_ID " .
255
                            "AND rt.OFFICIAL != 'A' " .
256
                            "AND rt.OFFICIAL != 'Y' " .
257
                    " ORDER BY p.PROJ_NAME";
258
 
259
    my $sth = $RM_DB->prepare($m_sqlstr);
260
    if ( defined($sth) )
261
    {
262
        if ( $sth->execute( ) )
263
        {
264
            if ( $sth->rows )
265
            {
266
                while ( @row = $sth->fetchrow_array )
267
                {
268
#                    print "@row\n";
269
                    if ( $opt_show )
270
                    {
271
                        next unless ( "$row[1]$row[2]" =~ m/$opt_show/i );
272
                    }
273
                    printf ("%-6d: %s, %s\n", @row);
274
                    $foundDetails = 1;
275
                }
276
            }
277
            $sth->finish();
278
        }
279
        else
280
        {
281
        Error("Execute failure: show_rtags" );
282
        }
283
    }
284
    else
285
    {
286
        Error("Prepare failure: show_rtags" );
287
    }
288
 
289
    Warning ("No Project or Release names Match: \"$opt_show\"")
290
        if ( $opt_show && ! $foundDetails );
291
}
292
 
293
#-------------------------------------------------------------------------------
294
#   Documentation
295
#
296
 
297
=pod
298
 
299
=head1 NAME
300
 
301
jats upddep - Update Build File Dependencies
302
 
303
=head1 SYNOPSIS
304
 
305
  jats upddep [options]
306
 
307
 Options:
308
    -help               - brief help message
309
    -help -help         - Detailed help message
310
    -man                - Full documentation
311
    -verbose            - Verbose operation
312
    -show[=text]        - Show all Release Tags, that match text
313
    -rtag=nnn           - Release Tag
314
    -out=file           - Output filename [auto.pl]
315
 
316
=head1 OPTIONS
317
 
318
=over 8
319
 
320
=item B<-help>
321
 
322
Print a brief help message and exits.
323
 
324
=item B<-help -help>
325
 
326
Print a detailed help message with an explanation for each option.
327
 
328
=item B<-man>
329
 
330
Prints the manual page and exits.
331
 
332
=item B<-verbose>
333
 
334
Increases program output. This option may be specified multiple times
335
 
336
=item B<-show[=text]>
337
 
338
This option will case the utility to list all the Release Tags in the Release
339
Manager database. It may be used to simplify the selection of the correct tag.
340
 
341
If B<text> is provided, then it will be used to limit the list of tags shown.
342
 
343
Closed and Archived Releases are not shown. The tool can still be used to update
344
the build files against such releases, but the Release Tag must be determined
345
from Release Manager.
346
 
347
=item B<-rtag=nnn>
348
 
349
This option specifies the Release, within the Release Manager Database, that will
350
be used to update the build dependency file.
351
 
352
The Release Tag is provided by the Release Manager Web Page, or by the -Show option
353
of this utility.
354
 
355
=item B<-out=file>
356
 
357
This option specifies the name of the output file in which the modified build
358
information will be placed. The default name is auto.pl'.
359
 
360
=back
361
 
362
=head1 DESCRIPTION
363
 
364
This utilty will update the dependency information within a build file to
365
reflect the desired package-versions within a specified release.
366
 
367
The intent of this utility is to simplify the process of package development by
368
automating the creating of a packages dependencies.
369
 
370
The utility will:
371
 
372
=over 8
373
 
374
=item * Contact the Release Manager Database.
375
 
376
The credentials are provided via JATS environment variables. JATS msut be
377
correctly configured in order for this to work.
378
 
379
=item * Locate the release as specified by the Release Tag
380
 
381
The name of the Release and the containing Project will be displayed.
382
 
383
=item * Extact all package-versions within the release
384
 
385
The information is then written to a file called jats_rewrite.cfg. The file is
386
left in place by the utility. It may be deleted.
387
 
388
=item * Invoke the jats rewrite utility to create or modify the build files.
389
 
390
Only the package dependencies are modified. The package version itself is not modified.
391
 
392
=back
393
 
394
The resultant file will be called 'auto.pl', by default. Jats will use this file
395
in preference to the build.pl file.
396
 
397
This utility will use either the build.pl or auto.pl file as a template for
398
updating version numbers. The tool will not add or remove packages from the
399
build file.
400
 
401
The 'auto.pl' file will be used if it exists and it has a more recent timestamp
402
than the build.pl file. This allows a developer to modify either file without
403
fear of losing the changes.
404
 
405
=cut
406