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