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
#
131
JatsTool ("jats_rewrite.pl", '-conf', $file,
132
                             '-verb', $opt_verbose,
133
                             '-outfile', $opt_outfile,
134
                             '-mode=1' ) && Error("Did not rewrite build.pl file");
135
 
136
exit 0;
137
 
138
#-------------------------------------------------------------------------------
139
# Function        : GetReleaseData
140
#
141
# Description     : Determine the Release Name and associated project
142
#
143
# Inputs          : $rtag_id
144
#
145
# Returns         : 
146
#
147
sub  GetReleaseData
148
{
149
    my ($RTAG_ID) = @_;
150
    my $foundDetails = 0;
151
    my (@row);
152
 
153
    # First get details from pv_id
154
 
155
    my $m_sqlstr = "SELECT rt.RTAG_NAME, p.PROJ_NAME" .
156
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
157
                    " WHERE rt.RTAG_ID = $RTAG_ID AND rt.PROJ_ID = p.PROJ_ID ";
158
 
159
    my $sth = $RM_DB->prepare($m_sqlstr);
160
    if ( defined($sth) )
161
    {
162
        if ( $sth->execute( ) )
163
        {
164
            if ( $sth->rows )
165
            {
166
                while ( @row = $sth->fetchrow_array )
167
                {
168
#                    print "@row\n";
169
                    ($ReleaseName, $ProjectName) = @row;
170
                    last;
171
                }
172
            }
173
            $sth->finish();
174
        }
175
        else
176
        {
177
        Error("Execute failure: GetReleaseData" );
178
        }
179
    }
180
    else
181
    {
182
        Error("Prepare failure: GetReleaseData" );
183
    }
184
}
185
 
186
#-------------------------------------------------------------------------------
187
# Function        : getPkgDetailsByRTAG_ID
188
#
189
# Description     : 
190
#
191
# Inputs          : rtag_id
192
#
193
# Returns         : Populate %ReleasePackages
194
#
195
sub getPkgDetailsByRTAG_ID
196
{
197
    my ($RTAG_ID) = @_;
198
 
199
    # First get details from pv_id
200
 
201
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
202
                    " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
203
                    " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
204
    my $sth = $RM_DB->prepare($m_sqlstr);
205
    if ( defined($sth) )
206
    {
207
        if ( $sth->execute( ) )
208
        {
209
            if ( $sth->rows )
210
            {
211
                while ( my @row = $sth->fetchrow_array )
212
                {
213
                    my $pv_id   = $row[0];
214
                    my $name    = $row[1];
215
                    my $ver     = $row[2];
216
#                    print "$name $ver\n";
217
 
218
                    #
219
                    #   Store data package name and package suffix
220
                    #
221
                    my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
222
                    $ReleasePackages{$pn}{$pp} = $pv;
223
                }
224
            }
225
            $sth->finish();
226
        }
227
    }
228
    else
229
    {
230
        Error("Prepare failure" );
231
    }
232
}
233
 
234
#-------------------------------------------------------------------------------
235
# Function        : show_rtags
236
#
237
# Description     : Display all RTAGS inthe data base
238
#
239
# Inputs          : 
240
#
241
# Returns         : 
242
#
243
sub show_rtags
244
{
245
    my $foundDetails = 0;
246
    my (@row);
247
    $opt_show = quotemeta( $opt_show );
248
 
249
    # First get details from pv_id
250
 
251
    my $m_sqlstr = "SELECT rt.RTAG_ID, p.PROJ_NAME, rt.RTAG_NAME" .
252
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
253
                    " WHERE rt.PROJ_ID = p.PROJ_ID " .
254
                            "AND rt.OFFICIAL != 'A' " .
255
                            "AND rt.OFFICIAL != 'Y' " .
256
                    " ORDER BY p.PROJ_NAME";
257
 
258
    my $sth = $RM_DB->prepare($m_sqlstr);
259
    if ( defined($sth) )
260
    {
261
        if ( $sth->execute( ) )
262
        {
263
            if ( $sth->rows )
264
            {
265
                while ( @row = $sth->fetchrow_array )
266
                {
267
#                    print "@row\n";
268
                    if ( $opt_show )
269
                    {
270
                        next unless ( "$row[1]$row[2]" =~ m/$opt_show/i );
271
                    }
272
                    printf ("%-6d: %s, %s\n", @row);
273
                    $foundDetails = 1;
274
                }
275
            }
276
            $sth->finish();
277
        }
278
        else
279
        {
280
        Error("Execute failure: show_rtags" );
281
        }
282
    }
283
    else
284
    {
285
        Error("Prepare failure: show_rtags" );
286
    }
287
 
288
    Warning ("No Project or Release names Match: \"$opt_show\"")
289
        if ( $opt_show && ! $foundDetails );
290
}
291
 
292
#-------------------------------------------------------------------------------
293
#   Documentation
294
#
295
 
296
=pod
297
 
298
=head1 NAME
299
 
300
jats upddep - Update Build File Dependencies
301
 
302
=head1 SYNOPSIS
303
 
304
  jats upddep [options]
305
 
306
 Options:
307
    -help               - brief help message
308
    -help -help         - Detailed help message
309
    -man                - Full documentation
310
    -verbose            - Verbose operation
311
    -show[=text]        - Show all Release Tags, that match text
312
    -rtag=nnn           - Release Tag
313
    -out=file           - Output filename [auto.pl]
314
 
315
=head1 OPTIONS
316
 
317
=over 8
318
 
319
=item B<-help>
320
 
321
Print a brief help message and exits.
322
 
323
=item B<-help -help>
324
 
325
Print a detailed help message with an explanation for each option.
326
 
327
=item B<-man>
328
 
329
Prints the manual page and exits.
330
 
331
=item B<-verbose>
332
 
333
Increases program output. This option may be specified multiple times
334
 
335
=item B<-show[=text]>
336
 
337
This option will case the utility to list all the Release Tags in the Release
338
Manager database. It may be used to simplify the selection of the correct tag.
339
 
340
If B<text> is provided, then it will be used to limit the list of tags shown.
341
 
342
Closed and Archived Releases are not shown. The tool can still be used to update
343
the build files against such releases, but the Release Tag must be determined
344
from Release Manager.
345
 
346
=item B<-rtag=nnn>
347
 
348
This option specifies the Release, within the Release Manager Database, that will
349
be used to update the build dependency file.
350
 
351
The Release Tag is provided by the Release Manager Web Page, or by the -Show option
352
of this utility.
353
 
354
=item B<-out=file>
355
 
356
This option specifies the name of the output file in which the modified build
357
information will be placed. The default name is auto.pl'.
358
 
359
=back
360
 
361
=head1 DESCRIPTION
362
 
363
This utilty will update the dependency information within a build file to
364
reflect the desired package-versions within a specified release.
365
 
366
The intent of this utility is to simplify the process of package development by
367
automating the creating of a packages dependencies.
368
 
369
The utility will:
370
 
371
=over 8
372
 
373
=item * Contact the Release Manager Database.
374
 
375
The credentials are provided via JATS environment variables. JATS msut be
376
correctly configured in order for this to work.
377
 
378
=item * Locate the release as specified by the Release Tag
379
 
380
The name of the Release and the containing Project will be displayed.
381
 
382
=item * Extact all package-versions within the release
383
 
384
The information is then written to a file called jats_rewrite.cfg. The file is
385
left in place by the utility. It may be deleted.
386
 
387
=item * Invoke the jats rewrite utility to create or modify the build files.
388
 
389
Only the package dependencies are modified. The package version itself is not modified.
390
 
391
=back
392
 
393
The resultant file will be called 'auto.pl', by default. Jats will use this file
394
in preference to the build.pl file.
395
 
396
This utility will use either the build.pl or auto.pl file as a template for
397
updating version numbers. The tool will not add or remove packages from the
398
build file.
399
 
400
The 'auto.pl' file will be used if it exists and it has a more recent timestamp
401
than the build.pl file. This allows a developer to modify either file without
402
fear of losing the changes.
403
 
404
=cut
405