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;
341 dpurdie 46
my $opt_outfile;
323 dpurdie 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
 
341 dpurdie 70
#
71
#   Allow some comand line options
72
#       -rtag_id=xxx
73
#        rtag_id=xxx
74
#
75
foreach ( @ARGV )
76
{
77
    if ( m~^rtag_id=(.*)~ ) {
78
        $opt_rtagid = $1;
79
    } else {
80
        Error ("Unknown command line argument: $_");
81
    }
82
}
323 dpurdie 83
 
341 dpurdie 84
 
323 dpurdie 85
Error( "No operation specified" )
86
    unless ( $opt_rtagid || defined  $opt_show );
87
 
88
#
341 dpurdie 89
#   Intelligently select output file
90
#       Use auto.pl if it exists
91
#       use build.pl if auto.??? does not exist and its writable
92
#
93
unless ( $opt_outfile )
94
{
95
    if ( -e 'auto.pl' ) {
96
        $opt_outfile = 'auto.pl';
97
    } elsif ( -e 'build.pl' && -w 'build.pl'  ) {
98
        $opt_outfile = 'build.pl';
99
    } else {
100
        $opt_outfile = 'auto.pl';
101
    }
102
}
103
 
104
#
323 dpurdie 105
#   Connect to the RM database
106
#       Uses infor from the JATS environment
107
#           GBE_RM_LOCATION
108
#           GBE_RM_USERNAME
109
#           GBE_RM_PASSWORD
110
#
111
connectRM(\$RM_DB);
112
 
113
#
114
#   Display all the Release Tags in the data base
115
#
116
if ( defined $opt_show )
117
{
118
    show_rtags();
119
    exit (0);
120
}
121
 
122
#
123
#   Ensure that the RTAG exists
124
#   Extract the Release and Project Name
125
#
126
GetReleaseData( $opt_rtagid );
127
Error ("Rtag not found in Release Manager Database: $opt_rtagid") unless ( $ProjectName );
128
Message ("Project Name: $ProjectName");
129
Message ("Release Name: $ReleaseName");
130
#
131
#   Get all package info the specified release
132
#   This is done as one query so it should be fast
133
#
134
getPkgDetailsByRTAG_ID( $opt_rtagid );
135
 
136
#
137
#   Create a configuration file for use by the JATS rewrite tool
138
#   This will allow the build.pl file to be re-written
139
#
140
my $file = "jats_rewrite.cfg";
141
open CFG, ">$file" || Error("Cannot create $file", $! );
142
print CFG "releasemanager.projectname = $ProjectName\n";
143
print CFG "releasemanager.releasename = $ReleaseName\n";
144
 
145
foreach my $pkg ( sort keys %ReleasePackages )
146
{
147
    my $ver;
148
    foreach my $prj ( sort keys %{$ReleasePackages{$pkg}} )
149
    {
150
        $ver  = $ReleasePackages{$pkg}{$prj};
151
        $ver .= '.' . ${prj} if ( $prj );
152
        print CFG "${pkg} ${ver}\n";
153
    }
154
}
155
close CFG;
156
 
157
#
158
#   Massage the build.pl file to create the auto.pl file
159
#   That will be used to create the final package.
160
#
325 dpurdie 161
$result = JatsTool ("jats_rewrite.pl", '-conf', $file,
323 dpurdie 162
                             '-verb', $opt_verbose,
163
                             '-outfile', $opt_outfile,
325 dpurdie 164
                             '-mode=1' );
165
unlink $file;
166
Error("Did not rewrite build.pl file") if ( $result );
323 dpurdie 167
exit 0;
168
 
169
#-------------------------------------------------------------------------------
170
# Function        : GetReleaseData
171
#
172
# Description     : Determine the Release Name and associated project
173
#
174
# Inputs          : $rtag_id
175
#
176
# Returns         : 
177
#
178
sub  GetReleaseData
179
{
180
    my ($RTAG_ID) = @_;
181
    my $foundDetails = 0;
182
    my (@row);
183
 
184
    # First get details from pv_id
185
 
186
    my $m_sqlstr = "SELECT rt.RTAG_NAME, p.PROJ_NAME" .
187
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
188
                    " WHERE rt.RTAG_ID = $RTAG_ID AND rt.PROJ_ID = p.PROJ_ID ";
189
 
190
    my $sth = $RM_DB->prepare($m_sqlstr);
191
    if ( defined($sth) )
192
    {
193
        if ( $sth->execute( ) )
194
        {
195
            if ( $sth->rows )
196
            {
197
                while ( @row = $sth->fetchrow_array )
198
                {
199
#                    print "@row\n";
200
                    ($ReleaseName, $ProjectName) = @row;
201
                    last;
202
                }
203
            }
204
            $sth->finish();
205
        }
206
        else
207
        {
208
        Error("Execute failure: GetReleaseData" );
209
        }
210
    }
211
    else
212
    {
213
        Error("Prepare failure: GetReleaseData" );
214
    }
215
}
216
 
217
#-------------------------------------------------------------------------------
218
# Function        : getPkgDetailsByRTAG_ID
219
#
220
# Description     : 
221
#
222
# Inputs          : rtag_id
223
#
224
# Returns         : Populate %ReleasePackages
225
#
226
sub getPkgDetailsByRTAG_ID
227
{
228
    my ($RTAG_ID) = @_;
229
 
230
    # First get details from pv_id
231
 
232
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
233
                    " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
234
                    " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
235
    my $sth = $RM_DB->prepare($m_sqlstr);
236
    if ( defined($sth) )
237
    {
238
        if ( $sth->execute( ) )
239
        {
240
            if ( $sth->rows )
241
            {
242
                while ( my @row = $sth->fetchrow_array )
243
                {
244
                    my $pv_id   = $row[0];
245
                    my $name    = $row[1];
246
                    my $ver     = $row[2];
247
#                    print "$name $ver\n";
248
 
249
                    #
250
                    #   Store data package name and package suffix
251
                    #
252
                    my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
253
                    $ReleasePackages{$pn}{$pp} = $pv;
254
                }
255
            }
256
            $sth->finish();
257
        }
258
    }
259
    else
260
    {
261
        Error("Prepare failure" );
262
    }
263
}
264
 
265
#-------------------------------------------------------------------------------
266
# Function        : show_rtags
267
#
268
# Description     : Display all RTAGS inthe data base
269
#
270
# Inputs          : 
271
#
272
# Returns         : 
273
#
274
sub show_rtags
275
{
276
    my $foundDetails = 0;
277
    my (@row);
278
    $opt_show = quotemeta( $opt_show );
279
 
280
    # First get details from pv_id
281
 
282
    my $m_sqlstr = "SELECT rt.RTAG_ID, p.PROJ_NAME, rt.RTAG_NAME" .
283
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
284
                    " WHERE rt.PROJ_ID = p.PROJ_ID " .
285
                            "AND rt.OFFICIAL != 'A' " .
286
                            "AND rt.OFFICIAL != 'Y' " .
287
                    " ORDER BY p.PROJ_NAME";
288
 
289
    my $sth = $RM_DB->prepare($m_sqlstr);
290
    if ( defined($sth) )
291
    {
292
        if ( $sth->execute( ) )
293
        {
294
            if ( $sth->rows )
295
            {
296
                while ( @row = $sth->fetchrow_array )
297
                {
298
#                    print "@row\n";
299
                    if ( $opt_show )
300
                    {
301
                        next unless ( "$row[1]$row[2]" =~ m/$opt_show/i );
302
                    }
303
                    printf ("%-6d: %s, %s\n", @row);
304
                    $foundDetails = 1;
305
                }
306
            }
307
            $sth->finish();
308
        }
309
        else
310
        {
311
        Error("Execute failure: show_rtags" );
312
        }
313
    }
314
    else
315
    {
316
        Error("Prepare failure: show_rtags" );
317
    }
318
 
319
    Warning ("No Project or Release names Match: \"$opt_show\"")
320
        if ( $opt_show && ! $foundDetails );
321
}
322
 
323
#-------------------------------------------------------------------------------
324
#   Documentation
325
#
326
 
327
=pod
328
 
329
=head1 NAME
330
 
331
jats upddep - Update Build File Dependencies
332
 
333
=head1 SYNOPSIS
334
 
335
  jats upddep [options]
336
 
337
 Options:
338
    -help               - brief help message
339
    -help -help         - Detailed help message
340
    -man                - Full documentation
341
    -verbose            - Verbose operation
342
    -show[=text]        - Show all Release Tags, that match text
343
    -rtag=nnn           - Release Tag
344
    -out=file           - Output filename [auto.pl]
345
 
346
=head1 OPTIONS
347
 
348
=over 8
349
 
350
=item B<-help>
351
 
352
Print a brief help message and exits.
353
 
354
=item B<-help -help>
355
 
356
Print a detailed help message with an explanation for each option.
357
 
358
=item B<-man>
359
 
360
Prints the manual page and exits.
361
 
362
=item B<-verbose>
363
 
364
Increases program output. This option may be specified multiple times
365
 
366
=item B<-show[=text]>
367
 
368
This option will case the utility to list all the Release Tags in the Release
369
Manager database. It may be used to simplify the selection of the correct tag.
370
 
371
If B<text> is provided, then it will be used to limit the list of tags shown.
372
 
373
Closed and Archived Releases are not shown. The tool can still be used to update
374
the build files against such releases, but the Release Tag must be determined
375
from Release Manager.
376
 
377
=item B<-rtag=nnn>
378
 
379
This option specifies the Release, within the Release Manager Database, that will
380
be used to update the build dependency file.
381
 
382
The Release Tag is provided by the Release Manager Web Page, or by the -Show option
383
of this utility.
384
 
385
=item B<-out=file>
386
 
387
This option specifies the name of the output file in which the modified build
341 dpurdie 388
information will be placed. The utility will use 'auto.pl' unless there is
389
no 'auto.pl' file and the 'build.pl' exists and is writable.
323 dpurdie 390
 
391
=back
392
 
393
=head1 DESCRIPTION
394
 
395
This utilty will update the dependency information within a build file to
396
reflect the desired package-versions within a specified release.
397
 
398
The intent of this utility is to simplify the process of package development by
399
automating the creating of a packages dependencies.
400
 
401
The utility will:
402
 
403
=over 8
404
 
405
=item * Contact the Release Manager Database.
406
 
407
The credentials are provided via JATS environment variables. JATS msut be
408
correctly configured in order for this to work.
409
 
410
=item * Locate the release as specified by the Release Tag
411
 
412
The name of the Release and the containing Project will be displayed.
413
 
414
=item * Extact all package-versions within the release
415
 
416
The information is then written to a file called jats_rewrite.cfg. The file is
417
left in place by the utility. It may be deleted.
418
 
419
=item * Invoke the jats rewrite utility to create or modify the build files.
420
 
421
Only the package dependencies are modified. The package version itself is not modified.
422
 
423
=back
424
 
425
The resultant file will be called 'auto.pl', by default. Jats will use this file
426
in preference to the build.pl file.
427
 
428
This utility will use either the build.pl or auto.pl file as a template for
429
updating version numbers. The tool will not add or remove packages from the
430
build file.
431
 
432
The 'auto.pl' file will be used if it exists and it has a more recent timestamp
433
than the build.pl file. This allows a developer to modify either file without
434
fear of losing the changes.
435
 
436
=cut
437