Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
392 dpurdie 1
#! perl
2
########################################################################
7300 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
392 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Build a package specified by a WIP
11
#                 Needs an rtag_id and a pv_id
12
#                 It is expected that Release Manager will provide these
13
#                 details such that they can be cut and pasted.
14
#
15
#                 Will create an auto.pl file
16
#
17
# Usage         : jats jats_build_a_wip.pl ....
18
#
19
# Version   Who      Date        Description
20
#
21
#......................................................................#
22
 
23
require 5.006_001;
24
use strict;
25
use warnings;
26
use JatsError;
27
use JatsSystem;
28
use JatsVersionUtils;
29
use JatsRmApi;
30
 
31
use Cwd;
32
use DBI;
33
use Getopt::Long;
34
use Pod::Usage;                             # required for help support
35
 
36
my $GBE_PERL     = $ENV{'GBE_PERL'};
37
my $GBE_CORE     = $ENV{'GBE_CORE'};
38
 
39
 
40
#
41
#   Release Manager Connection Information
42
#
43
my $RM_DB;
44
 
45
################################################################################
46
#   Global data
47
#
48
my $VERSION = "1.0.0";
49
my %ReleasePackages;            # Packages in the release
50
my %BuildPackages;              # Packages for this build
51
my %TargetPackage;              # Package being processed
52
 
53
#
54
#   Options
55
#
56
my $opt_help = 0;
57
my $opt_manual = 0;
58
my $opt_verbose = 0;
59
 
60
my $result = GetOptions (
61
                "help+"     => \$opt_help,          # flag, multiple use allowed
62
                "manual"    => \$opt_manual,        # flag
63
                "verbose+"  => \$opt_verbose,       # flag
64
                );
65
 
66
#
67
#   Process help and manual options
68
#
69
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
70
pod2usage(-verbose => 1)  if ($opt_help == 2 );
71
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
72
 
73
#
74
#   Configure the error reporting process now that we have the user options
75
#
76
ErrorConfig( 'name'    =>'BUILDAWIP',
77
             'verbose' => $opt_verbose );
78
 
79
 
80
#
81
#   Current interface uses RM line of the form
5710 dpurdie 82
#       http://bms:8002/ManagerSuite/Release_Manager/fixed_issues.asp?pv_id=104240&rtag_id=6924
83
#   This should be replaced - later
392 dpurdie 84
#
85
 
86
Error ("Speficy RM string with pv_id and rtag_id") unless ( $ARGV[0] );
87
my $PV_ID = $1 if ( $ARGV[0] =~ m~pv_id=(\d+)~ );
88
my $RTAG_ID = $1 if ($ARGV[0] =~ m~rtag_id=(\d+)~ );
89
 
90
Error ("Could not extract rtad_id and pv_id from command", $ARGV[0]) unless ( $PV_ID && $RTAG_ID );
91
Verbose( "PV_ID: $PV_ID, RTAG_ID: $RTAG_ID");
92
 
93
#
94
#   Extract information for the target package
95
#
96
GetPackageDetailsByPVID ($PV_ID );
97
GetBuildDetailsByPVID ( $PV_ID );
98
 
99
#
100
#   Create a hash of all the packages in the current release
101
#       Need this generate basis for WIP labels
102
#       Need this to create current versions
103
#
104
getPkgDetailsByRTAG_ID( $RTAG_ID );
105
DebugDumpData("PackageData", \%TargetPackage);
106
 
107
 
108
Message ("Package       : $TargetPackage{name}");
109
Message ("Version   : $TargetPackage{version}");
110
Message ("Label     : $TargetPackage{label}");
111
Message ("Path      : $TargetPackage{path}");
112
Message ("Change    : $TargetPackage{ChangeType}");
113
#Message ("BuildType : $TargetPackage{BuildType}");
114
Message ("BuildStan : $TargetPackage{BS_ID}");
115
#Message ("RTAG_ID: $TargetPackage{RTAG_ID}");
116
 
117
#
118
#   Assume that we need to ripple the current build version
119
#   Generate a new build version. The package may be a WIP
120
#
121
my ($pkg_name, $pkg_ver, $pkg_proj ) = NextBuildVersion( $TargetPackage{name}, $TargetPackage{version} ,'r' );
122
 
123
#
124
#   Body of the process
125
#
126
getPkgDetailsByPV_ID( $RTAG_ID, $PV_ID );
127
 
128
#
129
#   Create a configuration file for use by the JATS rewrite tool
130
#   This will allow the build.pl file to be re-written
131
#
132
my $file = "jats_rewrite.cfg";
133
open CFG, ">$file" || Error("Cannot create $file" );
134
print CFG "${pkg_name} ${pkg_ver}.${pkg_proj}\n";
135
 
136
foreach my $pkg ( keys %BuildPackages )
137
{
138
    foreach my $prj ( keys %{$BuildPackages{$pkg}} )
139
    {
140
        my $ver = $BuildPackages{$pkg}{$prj};
141
        if ( $prj )
142
        {
143
            print CFG "${pkg} ${ver}.${prj}\n";
144
        }
145
        else
146
        {
147
            print CFG "${pkg} ${ver}\n";
148
        }
149
    }
150
}
151
close CFG;
152
 
153
#
154
#   Massage the build.pl file to create the auto.pl file
155
#   That will be used to create the final package.
156
#
157
Message "Calling jats_rewrite.pl\n";
158
JatsTool ('jats_rewrite.pl', "-conf", $file, "-verb" ) && Error("Did not rewrite build.pl file");
159
 
160
exit 0;
161
 
162
#-------------------------------------------------------------------------------
163
# Function        : NextBuildVersion
164
#
165
# Description     : Determine the next build version number
166
#                   Assume this is a SIMPLE ripple build
167
#
168
# Inputs          : pkg_name
169
#                   pkg_ver
170
#                   type        - M,m,p,r
171
#                               Major, Minor, Patch or Ripple
172
#
173
# Returns         :
174
#
175
sub NextBuildVersion
176
{
177
    my ( $name, $ver, $type ) = @_;
178
 
179
    #
180
    #   Extract the version number from the project name
181
    #
182
    my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
183
    if ( $pv eq 'WIP' )
184
    {
185
        ($pv) = keys %{$ReleasePackages{$pn}{$pp}};
186
        Error ("Cannot determine current version for package", "$name $ver" ) unless ( $pv );
187
 
188
        $type = $TargetPackage{ChangeType};
189
        Error ("Cannot determine WIP change Type", "$name $ver" ) unless ( $type );
190
    }
191
 
192
    #
193
    #   Create a hash of existing versions for the required package
194
    #   These will be used to assist in determing the next version number
195
    #
196
    my $versions = GetPackageVersions( $name );
197
    $versions = $versions->{$pp};
198
 
199
    #
200
    #   Scan the versions and create a hash to assist in determing if a version
201
    #   already exists.
202
    #       Key it by MAJOR, MINOR, PATCH
203
    #
204
    my %vhash;
205
    foreach ( @{$versions} )
206
    {
207
        next if ( m/WIP/i );
208
        my ($major, $minor, $patch, $build ) = SplitVersion( $_ );
209
        $vhash{$major}{$minor}{$patch}{$build} = 1;
210
    }
211
#    DebugDumpData ("VVVV", \%vhash );
212
 
213
    #
214
    #   Extract the major, minor, patch and build number
215
    #
216
    my ($major, $minor, $patch, $build ) = SplitVersion( $pv );
217
 
218
#print "Base: $major, $minor, $patch, $build, Type: $type\n";
219
    my $done = 0;
220
    while ( !$done )
221
    {
222
        #
223
        #   Bump the reqired part of the version number
224
        #
225
        if ( $type eq 'M' ) {
226
            $major++;
227
            next if ( exists $vhash{$major} );
228
            $minor = 0;
229
            $patch = 0;
230
            $build = 0;
231
 
232
        } elsif ( $type eq 'm' || $type eq 'N' ) {
233
            $minor++;
234
            next if ( exists $vhash{$major}{$minor} );
235
            $patch = 0;
236
            $build = 0;
237
 
238
        } elsif ( $type eq 'p' || $type eq 'P' ) {
239
            $patch++;
240
            next if ( exists $vhash{$major}{$minor}{$patch} );
241
            $build = 0;
242
 
243
        } else {
244
            $build++;
245
            next if ( exists $vhash{$major}{$minor}{$patch}{$build} );
246
        }
247
        $done = 1;
248
    }
249
 
250
    #
251
    #   Build number retains its 3 character extension
252
    #
253
    Error ("Build number is too big: $build" )
254
        if ( $build >= 999 );
255
    $build = sprintf( "%-03.3d", $build );
256
 
257
 
258
    #
259
    #   Join them back again
260
    #
261
    Message "Current Version: $name, $ver",
262
            "Next Version:    $name, $major.$minor.${patch}${build}.$pp\n";
263
    return ( $name, "$major.$minor.${patch}${build}", $pp  );
264
}
265
 
266
#-------------------------------------------------------------------------------
267
# Function        : GetPackageVersions
268
#
269
# Description     : Get a hash of package versions for the named package
270
#
271
# Inputs          : $name           - Package name
272
#
273
# Returns         :
274
#
275
sub GetPackageVersions
276
{
277
    my ($name ) = @_;
278
 
279
    my $foundDetails = 0;
280
    my (@row);
281
    my %versions;
282
 
283
    # if we are not or cannot connect then return 0 as we have not found anything
284
    connectRM(\$RM_DB) unless ( $RM_DB );
285
 
286
    #
287
    #   Determine all versions of the named package
288
    #
289
 
290
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION FROM PACKAGES pkg, PACKAGE_VERSIONS pv WHERE pkg.PKG_NAME = \'$name\' AND pkg.PKG_ID = pv.PKG_ID";
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
                    my $id = $row[1];
301
                    my ( $name, $ver, $proj ) = SplitPackage( $row[0], $row[2] );
302
                    push @{$versions{$proj}}, $ver;
303
                }
304
            }
305
            $sth->finish();
306
        }
307
    }
308
    else
309
    {
310
        Error("GetPackageVersions:Prepare failure" );
311
    }
312
 
313
#    $RM_DB->disconnect() || Error ("Disconnect failed");
314
#    DebugDumpData("Versions", \%versions );
315
    return \%versions;
316
}
317
 
318
 
319
#-------------------------------------------------------------------------------
320
# Function        : getPkgDetailsByPV_ID
321
#
322
# Description     : Extract the dependancies for a specified package
323
#                   This is not a function of RTAG_ID, only the PV_ID
324
#
325
# Inputs          : RTAG_ID
326
#                   PV_ID
327
#
328
# Returns         :
329
#
330
sub getPkgDetailsByPV_ID
331
{
332
    my ( $rtag_id, $pv_id ) = @_;
333
    my (@row);
334
 
335
    # if we are not or cannot connect then return 0 as we have not found anything
336
    connectRM(\$RM_DB) unless ( $RM_DB );
337
 
338
    #
339
    #   Extract the package dependacies
340
    #
341
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION" .
342
                " FROM PACKAGE_DEPENDENCIES pd, PACKAGE_VERSIONS pv, PACKAGES pkg" .
343
                " WHERE pd.PV_ID = \'$pv_id\' AND pd.DPV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
344
    my $sth = $RM_DB->prepare($m_sqlstr);
345
    if ( defined($sth) )
346
    {
347
        if ( $sth->execute( ) )
348
        {
349
            if ( $sth->rows )
350
            {
351
                while ( @row = $sth->fetchrow_array )
352
                {
353
                    my ( $pn, $pv, $pp ) = SplitPackage( $row[0], $row[1] );
354
                    my ($rp) = keys %{$ReleasePackages{$pn}{$pp}};
355
 
356
                    $BuildPackages{$pn}{$pp} = $rp;
357
 
358
#                    print  ' ' x 4, "$pn $pv $pp\n";
359
#                    if ( $rp ne $pv )
360
#                    {
361
#                        print "  ----- Package not in release. Needs $rp";
362
#                    }
363
#                    print "\n";
364
                }
365
            }
366
            $sth->finish();
367
        }
368
    }
369
    else
370
    {
371
        Error("GetDepends:Prepare failure" );
372
    }
373
}
374
 
375
#-------------------------------------------------------------------------------
376
# Function        : getPkgDetailsByRTAG_ID
377
#
378
# Description     : Build up a structure for all the currently released
379
#                   packages in a given release
380
#
381
# Inputs          : rtag_id
382
#
383
# Returns         : Hash
384
#
385
 
386
sub getPkgDetailsByRTAG_ID
387
{
388
    my ($RTAG_ID) = @_;
389
    my $foundDetails = 0;
390
    my (@row);
391
 
392
    # if we are not or cannot connect then return 0 as we have not found anything
393
    connectRM(\$RM_DB) unless ( $RM_DB );
394
 
395
    # First get details from pv_id
396
 
397
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
398
                   " FROM RELEASE_CONTENT rc, PACKAGE_VERSIONS pv, PACKAGES pkg" .
399
                   " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
400
    my $sth = $RM_DB->prepare($m_sqlstr);
401
    if ( defined($sth) )
402
    {
403
        if ( $sth->execute( ) )
404
        {
405
            if ( $sth->rows )
406
            {
407
                while ( @row = $sth->fetchrow_array )
408
                {
409
                    my $pv_id   = $row[0];
410
                    my $name    = $row[1];
411
                    my $version = $row[2];
412
 
413
                    my ( $pn, $pv, $pp ) = SplitPackage( $name,  $version );
414
                    $ReleasePackages{$pn}{$pp}{$pv} = $pv_id;
415
                }
416
            }
417
            $sth->finish();
418
        }
419
        else
420
        {
421
            Error ("getPkgDetailsByRTAG_ID: Execute error");
422
        }
423
    }
424
    else
425
    {
426
        Error("getPkgDetailsByRTAG_ID: Prepare failure" );
427
    }
428
}
429
 
430
#-------------------------------------------------------------------------------
431
# Function        : GetPackageDetailsByPVID
432
#
433
# Description     : Determine the package details
434
#
435
#
436
# Inputs          : PV_ID
437
#
438
# Returns         :
439
#
440
sub GetPackageDetailsByPVID
441
{
442
    my ($pv_id) = @_;
443
    my (@row);
444
 
445
    #
446
    #   Establish a connection to Release Manager
447
    #
448
    connectRM(\$RM_DB) unless ( $RM_DB );
449
 
450
    #
451
    #   Extract data from Release Manager
452
    #   Note: The required package may be in one of a number of tables
453
    #
454
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION, pv.PV_ID, pv.SRC_PATH, pv.PKG_LABEL, pv.CHANGE_TYPE ,pv.BUILD_TYPE, pv.BS_ID" .
455
                   " FROM PACKAGES pkg, PACKAGE_VERSIONS pv" .
456
                   " WHERE pv.PV_ID = $pv_id AND pkg.PKG_ID = pv.PKG_ID";
457
 
458
    my $sth = $RM_DB->prepare($m_sqlstr);
459
    if ( defined($sth) )
460
    {
461
        if ( $sth->execute( ) )
462
        {
463
            if ( $sth->rows )
464
            {
465
                while ( @row = $sth->fetchrow_array )
466
                {
467
                    $TargetPackage{name} = $row[0];
468
                    $TargetPackage{version} = $row[2];
469
                    $TargetPackage{path} = $row[4] || Error("Package path not in RM");
470
                    $TargetPackage{PKG_ID} = $row[1];
471
                    $TargetPackage{PV_ID} = $row[3];
472
                    $TargetPackage{label} = $row[5] || Error("Package Label not in RM");
473
                    $TargetPackage{ChangeType} = $row[6] || 'None';
474
                    $TargetPackage{BuildType} = $row[7] || '';
475
                    $TargetPackage{BS_ID} = $row[8] || '';
476
 
477
 
478
                    Verbose ("DATA: @row");
479
                    last;
480
                }
481
            }
482
            else
483
            {
484
                Error("Package with PV_ID of $PV_ID not found in RM");
485
            }
486
            $sth->finish();
487
        }
488
    }
489
    else
490
    {
491
        Error("GetData:Prepare failure" );
492
    }
493
 
494
#    DebugDumpData("PackageData", \%TargetPackage);
495
}
496
 
497
#-------------------------------------------------------------------------------
498
# Function        : GetBuildDetailsByPVID
499
#
500
# Description     : Determine the package details
501
#
502
#
503
# Inputs          : PV_ID
504
#
505
# Returns         :
506
#
507
sub GetBuildDetailsByPVID
508
{
509
    my ($pv_id) = @_;
510
    my (@row);
511
 
512
    #
513
    #   Establish a connection to Release Manager
514
    #
515
    connectRM(\$RM_DB) unless ( $RM_DB );
516
 
517
    #
518
    #   Extract data from Release Manager
519
    #
520
    my $m_sqlstr = "SELECT pbi.BSA_ID, pbi.BM_ID" .
521
                    " FROM PACKAGE_BUILD_INFO pbi" .
522
                    " WHERE pbi.PV_ID = \'$pv_id\'";
523
 
524
 
525
    my $sth = $RM_DB->prepare($m_sqlstr);
526
    if ( defined($sth) )
527
    {
528
        if ( $sth->execute( ) )
529
        {
530
            if ( $sth->rows )
531
            {
532
                while ( @row = $sth->fetchrow_array )
533
                {
534
 
535
                    #
536
                    #   BSA_ID: 1:debug, 2:prod, 3:debug+prod, 4:Java1.4 5: Java 1.5
537
                    #   BM_ID : 1:solaris, 2:win32, 3: linux, 4:generic
538
                    #
539
                    Verbose ("DATA: @row");
540
                    print "----- BM_ID : $row[1]\n";
541
                    print "----- BSA_ID: $row[0]\n";
542
                    $TargetPackage{BUILD}{$row[1]} = $row[0];
543
 
544
 
545
                }
546
            }
547
            else
548
            {
549
                Error("Package with PV_ID of $PV_ID not found in RM");
550
            }
551
            $sth->finish();
552
        }
553
    }
554
    else
555
    {
556
        Error("GetData:Prepare failure" );
557
    }
558
 
559
#    DebugDumpData("PackageData", \%TargetPackage);
560
}
561
 
562