Subversion Repositories DevTools

Rev

Rev 6177 | Details | Compare with Previous | Last modification | View Log | RSS feed

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