Subversion Repositories DevTools

Rev

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