Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : cc2svn_gendata.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Get all packages that are used in all releases
10
#                 Create a data file that can be used offline
11
#
12
#                 The process will exclude some old releases
13
#
14
#                 Generate data on Essential Package Versions to be
15
#                 transferred from CC to Subversion
16
#
17
#......................................................................#
18
 
19
require 5.006_001;
20
use strict;
21
use warnings;
22
use JatsError;
23
use JatsSystem;
24
use Getopt::Long;
25
use Pod::Usage;                             # required for help support
26
use JatsRmApi;
27
use ConfigurationFile;
28
 
29
use DBI;
30
use HTTP::Date;
31
 
32
my $VERSION = "1.2.3";                      # Update this
33
my $opt_verbose = 0;
34
my $opt_help = 0;
35
my $opt_manual;
36
my $opt_test;
37
my $opt_limit;
38
my $opt_quick;
1197 dpurdie 39
my $opt_mode = '';
392 dpurdie 40
my $RM_DB;
41
my $now = time();
42
 
43
#
44
#   Package information
45
#
46
my %Releases;
47
my %Packages;
48
my %Suffixes;
49
my @StrayPackages;
50
my %AllPackages;
51
 
52
my $doAllReleases = 0;
53
my $doIncludeOnly = 0;
54
my @includedProjects = (
55
#        481,    # UK BUS HOPS
56
);
57
 
58
my @includedReleases = (
59
        6222,   # HOME > UK STAGE COACH (SSW) > Mainline
60
        14503,  # HOME > UK STAGE COACH (SSW) > ITSO_HOPS_3
61
        21303,  # HOME > UK STAGE COACH (SSW) > SUPPORT_HOPS_REPORTS
62
        21343,  # HOME > UK STAGE COACH (SSW) > SUPPORT_CIPP
63
        17223,  # HOME > UK STAGE COACH (SSW) > ITSO HOPS 4
64
);
65
 
66
 
67
my @excludeProjects = ( 162,            # WASHINGTON (WDC)
68
                        341,            # TUTORIAL (TUT)
69
                        142,            # SYDNEY (SYD)
70
                        182 ,           # ROME (ROM)
71
                        6 ,             # GMPTE/PCL (GMP)
72
                        521,            # NSW CLUB CARD
73
                        221,            # NZ STAGE COACH (NZS)
1197 dpurdie 74
                        82,             # LVS
75
                        42,             # SFO
76
                        641,            # BCC Releaeses
77
                        62,             # OSLO
78
                        4,              # Singapore
79
                        441,            # Tas
80
                        102,            # Ventura
392 dpurdie 81
                        );
82
my @excludeReleases = ( 20424,          # MASS_REF (MAS) > test
1197 dpurdie 83
                        # RJACK 9043,           # TECHNOLOGY GROUP > Development Environment - For Test Setup
84
                        # RJACK 14383,          # TECHNOLOGY GROUP > eBrio TDS
85
                        # RJACK 20463,          # TECHNOLOGY GROUP > TPIT - BackOffice Linux build
86
                        # RJACK 14603,          # TECHNOLOGY GROUP > TPIT - BackOffice 64 bit [CCB Mode!]
392 dpurdie 87
                        #9263,           # TECHNOLOGY GROUP > Buildtool DEVI&TEST
88
                        22163,          # GLOBAL PRODUCT MGMT > Rio Tinto - Remote Draught Survey
89
                        19483,          # SEATTLE (SEA) > Phase 2 - I18 [backup] [Restrictive Mode]
90
                        20403,          # SEATTLE (SEA) > Phase 2 - I19 [backup]
91
                        20983,          # ??? May have been deleted
395 dpurdie 92
                        13083,          # TECHNOLOGY GROUP > TRACS
93
                        15224,          # 64Bit Solaris Test
1197 dpurdie 94
 
392 dpurdie 95
                        );
96
 
97
my %sillyVersions =
98
(
99
    '2b6'           => '2.6.0.cots',
100
    '1.0b2'         => '1.0.2.cots',
101
    '1.6.x'         => '1.6.0.cots',
102
    '3.5beta12.5'   => '3.5.12.5.cots',
1197 dpurdie 103
    '1.0b1.1.mas'   => '1.1.1.mas',
392 dpurdie 104
);
1197 dpurdie 105
 
106
my %suffixFixup = (
107
    '.sf'           => '.sfo',
108
    '.vt'           => '.vtk',
109
    '.lv'           => '.lvs',
110
    '.was'          => '.wdc',
111
    '.uk.1'         => '.uk',
112
    '.ssts.demo'    => '.ssts',
113
    '.u244.syd'     => '.syd',
114
    '.pxxx.sea'     => '.sea',
115
    '.pxxx.syd'     => '.syd',
116
    '.pxxx.sydddd'  => '.syd',
117
    '.oslo'         => '.oso',
118
);
392 dpurdie 119
 
120
#-------------------------------------------------------------------------------
121
# Function        : Main Entry
122
#
123
# Description     :
124
#
125
# Inputs          :
126
#
127
# Returns         :
128
#
129
my $result = GetOptions (
130
                "help+"         => \$opt_help,          # flag, multiple use allowed
131
                "manual"        => \$opt_manual,        # flag
132
                "verbose+"      => \$opt_verbose,       # flag
133
                "test:s"        => \$opt_test,          # Test a version string
134
                "limit:n"       => \$opt_limit,         #
135
                "quick"         => \$opt_quick,         # Don't look for indirects
1197 dpurdie 136
                'mode:s'        => \$opt_mode,          # Mode of operation
392 dpurdie 137
                );
138
 
139
#
140
#   Process help and manual options
141
#
142
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
143
pod2usage(-verbose => 1)  if ($opt_help == 2 );
144
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
1197 dpurdie 145
ErrorConfig( 'name'    =>'CC2SVN_GENDATA' );
392 dpurdie 146
 
147
if ( $opt_test )
148
{
149
    my @results = massageVersion( $opt_test, 'DummyName' );
150
    Message ("Version", $opt_test, @results);
151
    exit 1;
152
}
153
 
1197 dpurdie 154
#
155
#   Set up the mode
156
#   Must be specified
157
#
158
if ( $opt_mode eq 'all' ) {
159
    $doAllReleases = 1;
160
    $doIncludeOnly = 0;
161
 
162
} elsif ( $opt_mode eq 'hops' ) {
163
    $doAllReleases = 0;
164
    $doIncludeOnly = 1;
392 dpurdie 165
 
1197 dpurdie 166
} elsif ( $opt_mode eq 'standard' ) {
167
    $doAllReleases = 0;
168
    $doIncludeOnly = 0;
169
 
170
} else {
171
    Error ("Mode not specified: all, hops, standard");
172
}
173
 
392 dpurdie 174
GetAllPackageNames();
175
getReleaseDetails();
176
getPkgDetailsByRTAG_ID();
1197 dpurdie 177
my ($pcount, $vcount) = countPackages();
178
print "Directly referenced Packages: $pcount Versions: $vcount\n";
392 dpurdie 179
LocateStrays() unless ($opt_quick);
1197 dpurdie 180
($pcount, $vcount) = countPackages();
181
print "Indirectly referenced Packages: $pcount Versions: $vcount\n";
182
processData();
392 dpurdie 183
outputData();
184
 
185
if ( $opt_verbose > 1 )
186
{
187
    print "=========================================================================\n";
188
    DebugDumpData("Releases", \%Releases);
189
    print "=========================================================================\n";
190
    DebugDumpData("Packages", \%Packages );
191
    print "=========================================================================\n";
192
    DebugDumpData("Suffixes", \%Suffixes );
193
}
194
 
1197 dpurdie 195
($pcount, $vcount) = countPackages();
196
print "Total References Packages: $pcount Versions: $vcount\n";
392 dpurdie 197
exit;
198
 
199
#-------------------------------------------------------------------------------
200
# Function        : getReleaseDetails
201
#
202
# Description     : Determine all candiate releases
203
#
204
# Inputs          : 
205
#
206
# Returns         : 
207
#
208
sub getReleaseDetails
209
{
210
    my (@row);
211
 
212
    # if we are not or cannot connect then return 0 as we have not found anything
213
    connectRM(\$RM_DB) unless $RM_DB;
214
 
215
    # First get all packages that are referenced in a Release
216
    # This will only get the top level packages
217
    # From non-archived releases
218
 
219
    my $m_sqlstr = "SELECT prj.PROJ_NAME, rt.RTAG_NAME, rt.PROJ_ID, rt.RTAG_ID, rt.official" .
220
                   " FROM release_manager.release_tags rt, release_manager.projects prj" .
221
                   " WHERE prj.PROJ_ID = rt.PROJ_ID " .
1197 dpurdie 222
#                   "   AND rt.official != 'A' ".
223
#                   "   AND rt.official != 'Y'" .
392 dpurdie 224
                   " order by prj.PROJ_NAME";
225
    my $sth = $RM_DB->prepare($m_sqlstr);
226
    if ( defined($sth) )
227
    {
228
        if ( $sth->execute( ) )
229
        {
230
#            print "--- Execute\n";
231
            if ( $sth->rows )
232
            {
233
#                print "--- Execute ROWS\n";
234
                while ( @row = $sth->fetchrow_array )
235
                {
236
                    my $rtag_id =$row[3];
237
                    my $proj_id = $row[2];
238
 
239
                    $Releases{$rtag_id}{pName} = $row[0];
240
                    $Releases{$rtag_id}{name} = $row[1];
241
                    $Releases{$rtag_id}{proj_id} = $proj_id;
242
                    $Releases{$rtag_id}{rtag_id} = $rtag_id;
243
                    $Releases{$rtag_id}{official} = $row[4];
244
 
245
                    unless ( $doAllReleases )
246
                    {
247
                        if (grep {$_ eq $proj_id} @excludeProjects) {
248
                            $Releases{$rtag_id}{excluded} = 'E';
249
                        }
250
 
251
                        if (grep {$_ eq $rtag_id} @excludeReleases) {
252
                            $Releases{$rtag_id}{excluded} = 'E';
253
                        }
254
                    }
255
 
256
                    if ( $doIncludeOnly )
257
                    {
258
 
259
                        if (grep {$_ eq $proj_id} @includedProjects)
260
                        {
261
                            delete $Releases{$rtag_id}{excluded};
262
                        }
263
                        else
264
                        {
265
                            $Releases{$rtag_id}{excluded} = 'E';
266
                        }
267
 
268
                        if (grep {$_ eq $rtag_id} @includedReleases)
269
                        {
270
                            delete $Releases{$rtag_id}{excluded};
271
                        }
272
                    }
273
 
274
                    unshift @row, $Releases{$rtag_id}{excluded} || ' ';
275
                    print join (',',@row), "\n" if ($opt_verbose);
276
                }
277
            }
278
#            print "--- Finish\n";
279
            $sth->finish();
280
        }
281
        else
282
        {
283
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
284
        }
285
    }
286
    else
287
    {
288
        Error("Prepare failure" );
289
    }
290
}
291
 
292
 
1197 dpurdie 293
sub getPkgDetailsByPVID
294
{
295
    my ($pv_id) = @_;
296
    my (@row);
297
 
298
    #
299
    #   Only do once
300
    #
301
    return if ( exists $Packages{$pv_id}{name} );
302
 
303
    # if we are not or cannot connect then return 0 as we have not found anything
304
    connectRM(\$RM_DB) unless $RM_DB;
305
 
306
    my $m_sqlstr = "SELECT" .
307
                        " pv.PV_ID, ".                                          #[0]
308
                        " pkg.PKG_NAME, ".                                      #[1]
309
                        " pv.PKG_VERSION, ".                                    #[2]
310
                        " pv.DLOCKED," .                                        #[3]
311
                        " release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), ". #[4]
312
                        " pv.PKG_ID," .                                         #[5]
313
                        " pv.MODIFIED_STAMP  ".                                 #[6]
314
                   " FROM RELEASE_MANAGER.PACKAGE_VERSIONS pv,".
315
                   "      RELEASE_MANAGER.PACKAGES pkg ".
316
                   " WHERE pv.PV_ID = \'$pv_id\' ".
317
                   "   AND pv.PKG_ID = pkg.PKG_ID" ;
318
    my $sth = $RM_DB->prepare($m_sqlstr);
319
    if ( defined($sth) )
320
    {
321
        if ( $sth->execute( ) )
322
        {
323
#            print "--- Execute\n";
324
            if ( $sth->rows )
325
            {
326
#                print "--- Execute ROWS\n";
327
                while ( @row = $sth->fetchrow_array )
328
                {
329
                    print join (',',@row), "\n" if ($opt_verbose);
330
 
331
                    my $pvid = $row[0];
332
                    $Packages{$pvid}{name} = $row[1];
333
                    $Packages{$pvid}{version} = $row[2];
334
                    $Packages{$pvid}{locked} = $row[3];
335
                    $row[4] =~ tr~\\/~/~;
336
                    $Packages{$pvid}{vcstag} = $row[4];
337
                    $Packages{$pvid}{pkgid} = $row[5];
338
#                    $Packages{$pvid}{tlp} = 1;
339
                    ($Packages{$pvid}{suffix}, $Packages{$pvid}{fullVersion},$Packages{$pvid}{isaRipple} ) = massageVersion( $Packages{$pvid}{version}, $Packages{$pvid}{name} );
340
                    $Suffixes{$Packages{$pvid}{suffix}}++;
341
                    $Packages{$pvid}{Age} = ($now - str2time( $row[6] )) / (60 * 60 * 24);
342
                }
343
            }
344
#            print "--- Finish\n";
345
            $sth->finish();
346
        }
347
        else
348
        {
349
            Error("getPkgDetailsByPVID:Execute failure: $m_sqlstr", $sth->errstr() );
350
        }
351
    }
352
    else
353
    {
354
        Error("getPkgDetailsByPVID:Prepare failure" );
355
    }
356
}
357
 
358
 
392 dpurdie 359
sub getPkgDetailsByRTAG_ID
360
{
361
    my (@row);
362
    my $excludes = '';
363
    my $count = 0;
364
 
365
    # if we are not or cannot connect then return 0 as we have not found anything
366
    connectRM(\$RM_DB) unless $RM_DB;
367
 
368
    Message ("Extract toplevel dependencies");
369
 
370
    # First get all packages that are referenced in a Release
371
    # This will only get the top level packages
372
    # From non-archived releases
373
 
374
    unless ($doAllReleases)
375
    {
376
        foreach  ( @excludeProjects )
377
        {
378
            $excludes .= " AND prj.PROJ_ID != $_ ";
379
        }
380
        foreach  ( @excludeReleases )
381
        {
382
            $excludes .= " AND rt.RTAG_ID != $_ ";
383
        }
384
    }
385
 
386
    my $m_sqlstr = "SELECT DISTINCT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION, pv.DLOCKED" .
387
                   "    , release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), pv.PKG_ID" .
388
                   "    , rt.RTAG_ID, rmv.VIEW_NAME, pv.MODIFIED_STAMP, prj.PROJ_ID" .
389
                   " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv,".
390
                   "      RELEASE_MANAGER.PACKAGES pkg, release_manager.release_tags rt, release_manager.projects prj" .
391
                   "    , release_manager.views rmv" .
392
                   " WHERE rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID" .
393
                   "   AND rmv.VIEW_ID = rc.BASE_VIEW_ID" .
394
                   "   AND prj.PROJ_ID = rt.PROJ_ID and rt.RTAG_ID = rc.RTAG_ID" .
1197 dpurdie 395
#                   "   AND rt.official != 'A'" .
396
#                   "   AND rt.official != 'Y' " .
392 dpurdie 397
                   $excludes .
398
                   " order by pkg.PKG_NAME";
399
    my $sth = $RM_DB->prepare($m_sqlstr);
400
    if ( defined($sth) )
401
    {
402
        if ( $sth->execute( ) )
403
        {
404
#            print "--- Execute\n";
405
            if ( $sth->rows )
406
            {
407
#                print "--- Execute ROWS\n";
408
                while ( @row = $sth->fetchrow_array )
409
                {
410
                    print join (',',@row), "\n" if ($opt_verbose);
411
                    my $pvid = $row[0];
412
                    unless ( exists $Packages{$pvid}{name} )
413
                    {
414
                        $Packages{$pvid}{name} = $row[1];
415
                        $Packages{$pvid}{version} = $row[2];
416
                        $Packages{$pvid}{locked} = $row[3];
417
                        $row[4] =~ tr~\\/~/~;
418
                        $Packages{$pvid}{vcstag} = $row[4];
419
                        $Packages{$pvid}{pkgid} = $row[5];
420
                        $Packages{$pvid}{tlp} = 1;
421
                        ($Packages{$pvid}{suffix}, $Packages{$pvid}{fullVersion},$Packages{$pvid}{isaRipple} ) = massageVersion( $Packages{$pvid}{version}, $Packages{$pvid}{name} );
422
                        $Suffixes{$Packages{$pvid}{suffix}}++;
423
 
424
                        push @StrayPackages, $pvid;
425
                    }
426
 
427
                    my $rtag_id = $row[6];
428
                    push @{$Packages{$pvid}{release}}, $rtag_id;
429
                    $Packages{$pvid}{view}{$row[7]}++ if ( $row[7] );
430
 
431
                    $Packages{$pvid}{Age} = ($now - str2time( $row[8] )) / (60 * 60 * 24);
432
 
433
                    my $proj_id = $row[9];
1197 dpurdie 434
                    push @{$Packages{$pvid}{projects}}, $proj_id
435
                        unless (grep {$_ eq $proj_id} @{$Packages{$pvid}{projects}});
392 dpurdie 436
 
437
                    if ( $doIncludeOnly )
438
                    {
439
                        if (grep {$_ eq $proj_id} @includedProjects)
440
                        {
441
                            $Packages{$pvid}{NamedProject} = 1;
442
                        }
443
                        if (grep {$_ eq $rtag_id} @includedReleases)
444
                        {
1197 dpurdie 445
                            $Packages{$pvid}{NamedProject} = 2;
392 dpurdie 446
                        }
447
                    }
448
                    else
449
                    {
1197 dpurdie 450
                        $Packages{$pvid}{NamedProject} = 3;
392 dpurdie 451
                    }
452
 
453
 
454
                    if ( $opt_limit )
455
                    {
456
                        last if ( $count++ > $opt_limit );
457
                    }
458
                }
459
            }
460
#            print "--- Finish\n";
461
            $sth->finish();
462
        }
463
        else
464
        {
465
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
466
        }
467
    }
468
    else
469
    {
470
        Error("Prepare failure" );
471
    }
472
}
473
 
474
#-------------------------------------------------------------------------------
475
# Function        : GetDepends
476
#
477
# Description     :
478
#
479
# Inputs          : $pvid
480
#
481
# Returns         :
482
#
483
sub GetDepends
484
{
485
    my ($pv_id ) = @_;
486
 
487
    #
1197 dpurdie 488
    #   Ensure we have package information
489
    #
490
    getPkgDetailsByPVID( $pv_id );
491
    return if ( $Packages{$pv_id}{depend} );
492
    $Packages{$pv_id}{depend} = 1;
493
 
494
    #
392 dpurdie 495
    #   Now extract the package dependacies
1197 dpurdie 496
    #   There may not be any
392 dpurdie 497
    #
1197 dpurdie 498
    my $m_sqlstr = "SELECT ".
499
                    " pd.PV_ID, ".
500
                    " pd.DPV_ID " .
501
                  " FROM    RELEASE_MANAGER.PACKAGE_DEPENDENCIES pd ".
502
                  " WHERE pd.PV_ID = \'$pv_id\'";
392 dpurdie 503
    my $sth = $RM_DB->prepare($m_sqlstr);
504
    if ( defined($sth) )
505
    {
506
        if ( $sth->execute( ) )
507
        {
508
            if ( $sth->rows )
509
            {
510
                while ( my @row = $sth->fetchrow_array )
511
                {
512
                    my $pvid = $row[0];
1197 dpurdie 513
                    my $dpvid = $row[1];
514
                    push @StrayPackages, $dpvid;
515
                    push @{$Packages{$dpvid}{usedBy}}, $pvid;
392 dpurdie 516
                }
517
            }
518
            $sth->finish();
519
        }
520
        else
521
        {
1197 dpurdie 522
            Error("GetDepends:Execute failure: $m_sqlstr", $sth->errstr() );
392 dpurdie 523
        }
524
    }
525
    else
526
    {
527
        Error("GetDepends:Prepare failure" );
528
    }
529
}
530
 
531
#-------------------------------------------------------------------------------
532
# Function        : GetAllPackageNames
533
#
534
# Description     :
535
#
536
# Inputs          : None
537
#
538
# Returns         :
539
#
540
sub GetAllPackageNames
541
{
542
    # if we are not or cannot connect then return 0 as we have not found anything
543
    connectRM(\$RM_DB) unless $RM_DB;
544
 
545
    #
546
    #   Now extract all the package names
547
    #
548
    my $m_sqlstr = "SELECT pkg.PKG_ID, pkg.PKG_NAME" .
549
                  " FROM RELEASE_MANAGER.PACKAGES pkg";
550
    my $sth = $RM_DB->prepare($m_sqlstr);
551
    if ( defined($sth) )
552
    {
553
        if ( $sth->execute( ) )
554
        {
555
            if ( $sth->rows )
556
            {
557
                while ( my @row = $sth->fetchrow_array )
558
                {
559
                    my $id = $row[0];
560
                    my $name = $row[1];
561
                    next unless ( $id );
562
                    $AllPackages{$id} = $name;
563
                }
564
            }
565
            $sth->finish();
566
        }
567
        else
568
        {
569
        Error("GetAllPackageNames:Execute failure" );
570
        }
571
    }
572
    else
573
    {
574
        Error("GetAllPackageNames:Prepare failure" );
575
    }
576
}
577
 
578
 
579
#-------------------------------------------------------------------------------
580
# Function        : massageVersion
581
#
582
# Description     : Process a version number and return usful bits
583
#
584
# Inputs          : Version Number
585
#                   Package Name - debug only
586
#
587
# Returns         : An array
588
#                       suffix
589
#                       multipart version string useful for text comparisons
590
#
591
sub massageVersion
592
{
593
    my ($version, $name) = @_;
594
    my ($major, $minor, $patch, $build, $suffix);
595
    my $result;
1197 dpurdie 596
    my $buildVersion;
392 dpurdie 597
    my $isaRipple;
598
    my $isaWIP;
599
    $build = 0;
600
 
1197 dpurdie 601
#print "--- $name, $version\n";
602
    $version =~ s~^_~~;
603
    $version =~ s~^\Q${name}\E_~~;
604
 
392 dpurdie 605
    #
606
    #   Pre-massage some silly ones
607
    #
608
    if ( exists $sillyVersions{$version} ) {
609
        $version = $sillyVersions{$version};
610
    }
611
 
1197 dpurdie 612
    if ( $name eq 'ReleaseName' ) {
613
        $version =~ s~[a-z]~.~g;
614
        $version =~ s~\.+~.~g;
615
        $version =~ s~\.$~~g
616
    }
392 dpurdie 617
 
1197 dpurdie 618
    #
619
    #   xxxxxxxxx.nnnn.cots
620
    #
392 dpurdie 621
    if ( $version =~ m~(.*)\.cots$~ ) {
622
        my $cots_base = $1;
623
        $suffix = '.cots';
624
        if ( $version =~ m~(.*?)\.([0-9]{4})\.cots$~ )
625
        {
626
            $result = $1 . sprintf (".%4.4d", $2) . $suffix;
627
        }
628
        else
629
        {
630
            $result = $cots_base . '.0000.cots';
631
        }
632
    }
633
    #
634
    #   Convert version into full form for comparisions
635
    #       nnn.nnn.nnn.[p]nnn.xxx
636
    #       nnn.nnn.nnn.[p]nnn-xxx
637
    #       nnn.nnn.nnn-[p]nnn.xxx
638
    #       nnn.nnn.nnn-[p]nnn-xxx
639
    #       nnn.nnn.nnn[p]nnn-xxx
1197 dpurdie 640
    #   Don't flag as ripples - they are patches
392 dpurdie 641
    #
642
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-.p][p]?(\d+)([-.](.*))?$~ ) {
643
        $major = $1;
644
        $minor = $2;
645
        $patch = $3;
646
        $build = $4;
647
        $suffix = defined $6 ? ".$6" : '';
1197 dpurdie 648
        $isaRipple = 0;
392 dpurdie 649
    }
650
    #
651
    #       nn.nnn.nnnnn.xxx
652
    #       nn.nnn.nnnnn-xxx
1197 dpurdie 653
    #       nnn.nnn.nnnx.xxx
654
    #   Don't flag as ripples - they are patches
392 dpurdie 655
    #
1197 dpurdie 656
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)\w?([-.](.*))?$~ ) {
392 dpurdie 657
        $major = $1;
658
        $minor = $2;
659
        $patch = $3;
660
        if ( length( $patch) >= 4 )
661
        {
662
            $build = substr( $patch, -3 ,3);
663
            $patch = substr( $patch,  0 ,length($patch)-3);
664
        }
665
        $suffix = defined $5 ? ".$5" : '';
666
    }
1197 dpurdie 667
 
392 dpurdie 668
    #
1197 dpurdie 669
    #       nnn.nnn.nnn
670
    #       nnn.nnn-nnn
671
    #       nnn.nnn_nnn
392 dpurdie 672
    #
1197 dpurdie 673
    elsif ( $version =~ m~^(\d+)\.(\d+)[-._](\d+)$~ ) {
392 dpurdie 674
        $major = $1;
675
        $minor = $2;
676
        $patch = $3;
677
        $suffix = '';
678
    }
1197 dpurdie 679
 
392 dpurdie 680
    #
1197 dpurdie 681
    #       nnn.nnn.nnn.nnn
682
    #       nnn.nnn.nnn-nnn
683
    #       nnn.nnn.nnn_nnn
392 dpurdie 684
    #
1197 dpurdie 685
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-._](\d+)$~ ) {
392 dpurdie 686
        $major = $1;
687
        $minor = $2;
688
        $patch = $3;
1197 dpurdie 689
        $build = $4;
392 dpurdie 690
        $suffix = '';
1197 dpurdie 691
        $isaRipple = 0;
392 dpurdie 692
    }
1197 dpurdie 693
 
392 dpurdie 694
 
695
    #
696
    #       nnn.nnn
697
    #
698
    elsif ( $version =~ m~^(\d+)\.(\d+)$~ ) {
699
        $major = $1;
700
        $minor = $2;
701
        $patch = 0;
702
        $suffix = '';
703
    }
704
    #
1197 dpurdie 705
    #       nnn.nnn.xxx
706
    #
707
    elsif ( $version =~ m~^(\d+)\.(\d+)(\.\w+)$~ ) {
708
        $major = $1;
709
        $minor = $2;
710
        $patch = 0;
711
        $suffix = $3;
712
    }
713
 
714
    #
392 dpurdie 715
    #       nnn.nnn.nnnz
716
    #
717
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)([a-z])$~ ) {
718
        $major = $1;
719
        $minor = $2;
720
        $patch = $3;
721
        $build = ord($4) - ord('a');
722
        $suffix = '.cots';
1197 dpurdie 723
        $isaRipple = 0;
392 dpurdie 724
    }
725
    #
726
    #       ???REV=???
727
    #
728
    elsif ( $version =~ m~REV=~ ) {
729
        $suffix = '.cots';
730
        $result = $version . '.0000.cots';
731
    }
732
 
733
    #
734
    #   Wip Packages
1197 dpurdie 735
    #   (nnnnnn).xxx
392 dpurdie 736
    #   Should be essential, but want to sort very low
737
    #
1197 dpurdie 738
    elsif ($version =~ m~\((.*)\)(\..*)?~) {
739
        $suffix = $2 || '';
740
        $result = "000.000.000.000$suffix";
392 dpurdie 741
        $isaWIP = 1;
742
    }
1197 dpurdie 743
 
392 dpurdie 744
    #
1197 dpurdie 745
    #   !current
392 dpurdie 746
    #
1197 dpurdie 747
    elsif ($version eq '!current' || $version eq 'current_$USER' || $version eq 'current' || $version eq 'beta' || $version eq 'latest' || $version eq 'beta.cr' || $version eq 'CREATE') {
748
        $suffix = '';
749
        $result = "000.000.000.000$suffix";
750
        $isaWIP = 1;
751
    }
752
 
753
    #
754
    #   Also WIP: FINRUN.103649.BEI.WIP
755
    elsif ($version =~ m~(\.[a-zA-Z]+)\.WIP$~) {
756
        $suffix = lc($1);
757
        $result = "000.000.000.000$suffix";
758
        $isaWIP = 1;
759
    }
760
 
761
    #
762
    #   Also ERGOFSSLS190100_015
763
    #   Don't flag as a ripple
764
    elsif ($version =~ m~^ERG[A-Z]+(\d\d)(\d\d)(\d\d)[-_](\d+)(\.\w+)?$~) {
765
        $major = $1;
766
        $minor = $2;
767
        $patch = $3;
768
        $build = $4;
769
        $suffix = $5 || '.sls';
770
        $isaRipple = 0;
771
    }
772
 
773
    #
774
    #   Stuff we don't yet handle
775
    #
392 dpurdie 776
    else  {
1197 dpurdie 777
        Warning ("Unknown version number: $name,$version");
392 dpurdie 778
        $version =~ m~(\.\w+)$~;
779
        $suffix = $1 || '';
780
        $result = $version;
781
    }
782
 
1197 dpurdie 783
    $isaRipple = ($build > 0) unless defined $isaRipple;
392 dpurdie 784
    unless ( $result )
785
    {
1197 dpurdie 786
        # Major and minor of 99.99 are normally funny versions
787
        # Don't make important decisions on them
788
        #
789
        if (defined $major && defined $minor && $major == 99 && $minor == 99 )
790
        {
791
            $major = 0;
792
            $minor = 0;
793
            $patch = 0;
794
        }
795
 
392 dpurdie 796
        $result = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $major,$minor,$patch,$build,$suffix || '.0000');
1197 dpurdie 797
        $buildVersion = [ $major, $minor, $patch, $build ];
392 dpurdie 798
    }
799
 
1197 dpurdie 800
    $suffix = lc( $suffix );
801
    if ( exists $suffixFixup{$suffix} )
802
    {
803
        $suffix = $suffixFixup{$suffix} ;
804
    }
392 dpurdie 805
 
1197 dpurdie 806
    return ($suffix, $result, $isaRipple, $isaWIP, $buildVersion );
392 dpurdie 807
}
808
 
809
 
810
#-------------------------------------------------------------------------------
811
# Function        : LocateStrays
812
#
813
# Description     :
814
#
815
# Inputs          :
816
#
817
# Returns         :
818
#
819
sub LocateStrays
820
{
821
    Message ("Locate indirectly referenced packages");
822
    while ( $#StrayPackages >= 0 )
823
    {
824
        my $pv_id = pop @StrayPackages;
825
 
826
        next if ( exists $Packages{$pv_id}{done} );
827
#print "... ",$#StrayPackages,"\n";
828
        GetDepends( $pv_id);
829
        $Packages{$pv_id}{done} = 1;
830
    }
831
}
832
 
833
#-------------------------------------------------------------------------------
1197 dpurdie 834
# Function        : countPackages
392 dpurdie 835
#
1197 dpurdie 836
# Description     : 
392 dpurdie 837
#
838
# Inputs          : 
839
#
1197 dpurdie 840
# Returns         : Number of packages and number oof versions
392 dpurdie 841
#
1197 dpurdie 842
sub countPackages
392 dpurdie 843
{
1197 dpurdie 844
    my $v = 0;
845
    my $p = 0;
846
    my %names;
392 dpurdie 847
 
1197 dpurdie 848
    foreach ( keys %Packages )
849
    {
850
        my $name = $Packages{$_}{name};
851
        next unless ( $name );
852
        $names{$name} = 1;
853
        $v++;
854
    }
392 dpurdie 855
 
1197 dpurdie 856
    $p = keys %names;
857
 
858
    return $p,$v;
859
 
860
}
861
 
862
#-------------------------------------------------------------------------------
863
# Function        : processData
864
#
865
# Description     : Process data before its written out
866
#                       Remove a few packages that we do not want to now about
867
#                       Determine Reason that a version is in the list
868
#                       Finish taging packages in NamedProject
869
#
870
# Inputs          : 
871
#
872
# Returns         : 
873
#
874
sub processData
875
{
392 dpurdie 876
    foreach ( keys %Packages )
877
    {
878
        delete $Packages{$_}{done};
879
        next if ( $Packages{$_}{name} =~ ~m~CSWcfengine~ );
880
 
881
        if ($Packages{$_}{name} eq 'Activestate Perl - Solaris')
882
        {
883
            delete $Packages{$_};
884
            next;
885
        }
886
 
887
        if ( $Packages{$_}{name} =~ m/^CSW/ || $Packages{$_}{name} =~ m/^Solaris$/)
888
        {
889
            delete $Packages{$_};
890
            next;
891
        }
892
 
893
        if ( $Packages{$_}{name} =~ m/^jats_/)
894
        {
895
            delete $Packages{$_};
896
            next;
897
        }
1197 dpurdie 898
 
899
 
900
        #
901
        #   Catch packages that are dependents of NamedProject's
902
        #
903
        if ( $doIncludeOnly )
904
        {
905
            if ( exists  $Packages{$_}{'sbomBase'} || exists  $Packages{$_}{'sbomOsid'} )
906
            {
907
                $Packages{$_}{NamedProject} = 4;
908
            }
909
 
910
            unless ( $Packages{$_}{NamedProject}  )
911
            {
912
                my $named;
913
                my %usedBy;
914
 
915
                if ( exists $Packages{$_}{'usedBy'})
916
                {
917
                    my @examineThese = @{$Packages{$_}{'usedBy'}};
918
                    while ( @examineThese )
919
                    {
920
                        my $pvid = pop @examineThese;
921
                        next if ( $usedBy{$pvid} );
922
 
923
                        if ( $Packages{$pvid}{NamedProject}  )
924
                        {
925
                            $named = 1;
926
                            last;
927
                        }
928
 
929
                        push @examineThese, @{$Packages{$pvid}{'usedBy'}}
930
                            if (exists $Packages{$pvid}{'usedBy'});
931
                    }
932
                    $Packages{$_}{NamedProject} = 5
933
                        if ( $named );
934
                }
935
#                else
936
#                {
937
#                    Warning("Not Named and not usedBy: $Packages{$_}{name} $Packages{$_}{'version'}");
938
#                }
939
            }
940
        }
941
        else
942
        {
943
            $Packages{$_}{NamedProject} = 6;
944
        }
392 dpurdie 945
    }
1197 dpurdie 946
}
392 dpurdie 947
 
1197 dpurdie 948
#-------------------------------------------------------------------------------
949
# Function        : outputData
950
#
951
# Description     : Write out data in a form to allow post processing
952
#
953
# Inputs          : 
954
#
955
# Returns         : 
956
#
957
sub outputData
958
{
959
    my $file = "cc2svn.raw.txt";
960
    Message ("Create: $file");
961
    my $fh = ConfigurationFile::New( $file );
962
 
392 dpurdie 963
    $fh->DumpData(
1197 dpurdie 964
        "\n# Releases.\n#\n",
965
        "ScmReleases", \%Releases );
966
 
967
    $fh->DumpData(
392 dpurdie 968
        "\n# Packages.\n#\n",
969
        "ScmPackages", \%Packages );
970
 
971
    $fh->DumpData(
972
        "\n# Suffixes.\n#\n",
973
        "ScmSuffixes", \%Suffixes );
974
 
975
    $fh->DumpData(
976
        "\n# All Package Names.\n#\n",
977
        "ScmAllPackages", \%AllPackages );
978
 
979
    #
980
    #   Close out the file
981
    #
982
    $fh->Close();
983
 
984
#    #
985
#    #   Split up package data into small files for easy consumption
986
#    #
987
#
988
#    foreach ( keys %Packages )
989
#    {
990
#        my $file = "cc2svn.raw.${_}.txt";
991
#        Message ("Create: $file");
992
#        my $fh = ConfigurationFile::New( $file );
993
#
994
#        $fh->DumpData(
995
#            "\n# Releases.\n#\n",
996
#            "ScmReleases", \$Packages{$_} );
997
#        $fh->Close();
998
#    }
999
 
1000
}
1001
 
1002
 
1003
#-------------------------------------------------------------------------------
1004
#   Documentation
1005
#
1006
 
1007
=pod
1008
 
1009
=for htmltoc    SYSUTIL::cc2svn::
1010
 
1011
=head1 NAME
1012
 
1013
cc2svn_gendata - Extract CC2SVN Essential Package Data from Release Manager
1014
 
1015
=head1 SYNOPSIS
1016
 
1017
  jats cc2svn_gendata [options]
1018
 
1019
 Options:
1020
    -help              - brief help message
1021
    -help -help        - Detailed help message
1022
    -man               - Full documentation
1023
    -test=version      - Test a version string, then exit
1024
    -limit=n           - Limit packages processed. Test only
1197 dpurdie 1025
    -mode=xxx          - Set Mode: all, hops, standard
392 dpurdie 1026
 
1027
=head1 OPTIONS
1028
 
1029
=over 8
1030
 
1031
=item B<-help>
1032
 
1033
Print a brief help message and exits.
1034
 
1035
=item B<-help -help>
1036
 
1037
Print a detailed help message with an explanation for each option.
1038
 
1039
=item B<-man>
1040
 
1041
Prints the manual page and exits.
1042
 
1043
=item B<-test=version>
1044
 
1045
Examine a package version string and report how the tool will parse it.
1046
 
1047
=item B<-limit=n>
1048
 
1049
Limit the number of packages processed by the tool. This is only used to
1050
simplify testing of the program
1051
 
1052
=back
1053
 
1054
=head1 DESCRIPTION
1055
 
1056
This program is a tool used in the conversion of ClearCase VOBS to subversion.
1057
It will:
1058
 
1059
=over 8
1060
 
1061
=item *
1062
 
1063
Determine all Releases in Release manager and mark those that
1064
are to be excluded.
1065
 
1066
=item *
1067
 
1068
Determine all the package-versions used by the releases that are
1069
not excluded. These are called 'direct' dependencies.
1070
 
1071
=item *
1072
 
1073
Recursively find all the dependent packages of all packages. New package
1074
versions are called 'indirect' dependencies. They are buried. This process can
1075
take several minutes.
1076
 
1077
=back
1078
 
1079
The data collected is dumped into a text file for later processing.
1080
 
1081
=cut
1082