Subversion Repositories DevTools

Rev

Rev 5709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
379 dpurdie 4
# Module name   : gen_cots.pl
227 dpurdie 5
# Module type   : Makefile system
379 dpurdie 6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
297 dpurdie 9
# Description   : Create a buildable package based on a COTS package
10
#                 or other package image.
227 dpurdie 11
#
297 dpurdie 12
#                 Designed to simplify the process of version controlling
13
#                 handcrafted packages that have been dropped into dpkg_archive
227 dpurdie 14
#
379 dpurdie 15
#                 Supports clearcase and subversion
16
#
297 dpurdie 17
# Usage:        See Embedded documentation below
18
#               jats gen_cots ...
227 dpurdie 19
#
20
#......................................................................#
21
 
255 dpurdie 22
require 5.006_001;
227 dpurdie 23
use Cwd;
24
use strict;
25
use warnings;
26
use JatsError;
27
use FileUtils;
28
use File::Basename;
29
use File::Find;
30
use File::Copy;
31
use File::Path;
379 dpurdie 32
use JatsSvn qw(:All);
33
use JatsSystem;
34
use JatsProperties;
35
use File::Temp qw/ tempfile tempdir /;
227 dpurdie 36
 
37
use Pod::Usage;                             # required for help support
38
use Getopt::Long;
39
use Cwd;
40
 
41
#-------------------------------------------------------------------------------
42
#   Global variables
43
#
44
my $VERSION = "1.0.0";                      # Update this
45
my $GBE_DPKG = $ENV{ GBE_DPKG };
46
my %subdirs;
47
my %files;
48
my $DESTDIR = 'src';           # 'src'
49
my $last_result;
50
my @error_list;
51
my $vob_dir  = '';
52
my $vob_name = '';
53
my $src_dir;
54
 
379 dpurdie 55
my $svnSession;
56
my $svnPackageName;
57
my $svnPackageExists;
58
my $svnRmRef = '';
59
 
227 dpurdie 60
#
61
#   Options
62
#
63
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
64
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
65
my $opt_help = 0;
66
my $opt_manual = 0;
67
my $opt_label;
279 dpurdie 68
my $opt_vob;
227 dpurdie 69
my $opt_test;
70
my $opt_keep;
71
my $opt_subdir;
72
my $opt_image;
5104 dpurdie 73
my $opt_package;
379 dpurdie 74
my $opt_repository;
227 dpurdie 75
 
76
#-------------------------------------------------------------------------------
77
# Function        : Mainline Entry Point
78
#
379 dpurdie 79
# Description     : Parse Options
80
#                   Perform Sanity Checks
81
#                   Perform operation
82
#                   Cleanup
227 dpurdie 83
#
379 dpurdie 84
# Inputs          : Command Line arguments
227 dpurdie 85
#
86
my $result = GetOptions (
87
                "help+"         => \$opt_help,              # flag, multiple use allowed
88
                "manual"        => \$opt_manual,            # flag
1403 dpurdie 89
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
227 dpurdie 90
                "label=s"       => \$opt_label,             # String
91
                "vob=s"         => \$opt_vob,               # String
92
                "test"          => \$opt_test,              # Flag
93
                "keep"          => \$opt_keep,              # Flag
94
                "subdir=s"      => \$opt_subdir,            # string
95
                "image=s"       => \$opt_image,             # string
5104 dpurdie 96
                "package"       => \$opt_package,           # flag
2764 dpurdie 97
                "repository=s"  => \$opt_repository,        # string
227 dpurdie 98
                );
99
 
100
                #
101
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
102
                #
103
 
104
#
105
#   Process help and manual options
106
#
107
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
108
pod2usage(-verbose => 1) if ($opt_help == 2 );
109
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
110
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 0 );
111
 
112
#
113
#   Configure the error reporting process now that we have the user options
114
#
115
ErrorConfig( 'name'    =>'gen_cots',
116
             'verbose' => $opt_verbose,
117
            );
118
 
119
#
120
#   Init the file uitilites
121
#
122
InitFileUtils();
379 dpurdie 123
 
124
#
125
#   Sanity test user options
126
#
127
Error ("Can only specify either -vob or -repository.") if ( $opt_vob && $opt_repository );
128
Error ("ClearCase mode only supported on WINDOWS, not $::ScmHost") if ( $opt_vob && $::ScmHost ne 'WIN' );
227 dpurdie 129
Error ("No DPK_ARCHIVE") unless ( $GBE_DPKG );
379 dpurdie 130
Error ("Must specify -vob, -repository or -keep") unless ( $opt_vob || $opt_repository || $opt_keep);
5104 dpurdie 131
Error ("Must specify -image=aaa or -package") unless ( $opt_image || $opt_package );
227 dpurdie 132
Error ("Need two arguments: package and version") unless ( $#ARGV eq 1 );
133
 
134
#
135
#   Determine base image
136
#   Either from dpkg_archive or user image
137
#
138
if ( $opt_image )
139
{
140
    $src_dir =  AbsPath($opt_image);
141
    Error("Image directory is not present: $src_dir") unless ( -d $src_dir );
142
}
143
else
144
{
145
    #
146
    #   Ensure that the package source in dpkg_archive can be found
147
    #
148
    $src_dir = "$GBE_DPKG/$ARGV[0]/$ARGV[1]";
241 dpurdie 149
    Message ( "Testing $src_dir" );
5104 dpurdie 150
    Error ("Package not found in dpkg_archive:",$src_dir ) unless ( -d $src_dir );
151
    Message ("Found source package in dpkg_archive");
227 dpurdie 152
}
153
 
154
#
379 dpurdie 155
#   Determine target path with the VOB/Repository
156
#   Will be taken from the package name, unless provided
227 dpurdie 157
#
158
$opt_subdir = $ARGV[0] unless ( $opt_subdir );
379 dpurdie 159
$opt_subdir =~ tr~\\/~/~s;
303 dpurdie 160
 
379 dpurdie 161
#
162
#   Create a TEMP working area
163
#   Needs to work on both Unix and Windows
164
#
165
my $dest_root = tempdir( 'GenCots_XXXX',TMPDIR => 1, CLEANUP => !$opt_keep );
166
my $dest_dir = "$dest_root/$opt_subdir";
279 dpurdie 167
Verbose ("Work Dir: $dest_dir");
379 dpurdie 168
Error( "Temp Directory not found: $dest_root") unless ( -d $dest_root);
169
Error( "Temp Workspace should not exist: $dest_dir") if ( -d $dest_dir);
227 dpurdie 170
 
379 dpurdie 171
#
172
#   Generate a label, if the user has not already specified one
173
#
174
if ( $opt_vob || $opt_repository )
297 dpurdie 175
{
379 dpurdie 176
    $opt_label = "$ARGV[0]_$ARGV[1]"
177
        unless ( $opt_label );
178
    Verbose ("Label: $opt_label");
179
}
180
 
181
#
182
#   Ensure VOBS/REPO and Labels are good
183
#
184
ClearCaseValidate()  if ($opt_vob);
185
SubversionValidate() if ($opt_repository);
186
 
187
#
188
#   Generate the package to be retained
189
#   Create jats build files and copy of required data
190
#
191
generatePackage();
192
 
193
#
194
#   Transfer the image into the target VCS System
195
#
196
ClearCaseImport()  if ($opt_vob);
197
SubversionImport() if ($opt_repository);
198
 
199
#
200
#   Remove the created directory
201
#
202
if ( $opt_keep )
203
{
204
    Warning ("KEEP temp directory: $dest_root");
205
}
206
else
207
{
208
    Message ("Delete temp directory");
209
    rmtree( $dest_root );
210
}
211
 
212
#
213
#   All done
214
#   Report data to the user to use in Release Manager
215
#
216
if ( $opt_vob || $opt_repository )
217
{
218
    Message ("\n");
219
    Message ("Release Manager information");
220
    if ( $opt_vob )
221
    {
222
        Message ("Package path : /$vob_name/$opt_subdir");
223
        Message ("Label        : $opt_label");
224
        Message ("VCS Tag      : CC::/${vob_name}/${opt_subdir}::${opt_label}");
225
    }
226
    else
227
    {
1403 dpurdie 228
        $svnRmRef =~ m~(.*)::(.*)~;
229
        my $rmPath = $1 || 'Unknown';
230
        my $rmTag = $2 || 'Unknown';
231
 
232
        Message ("Source Path  : $rmPath");
233
        Message ("Tag          : $rmTag");
379 dpurdie 234
        Message ("VCS Tag      : SVN::$svnRmRef");
235
    }
236
 
237
    Warning ("Test Mode: Not Version Control System changes made") if ( $opt_test );
238
}
239
exit 0;
240
 
241
#-------------------------------------------------------------------------------
242
# Function        : generatePackage
243
#
244
# Description     : Craete a jats build package
245
#
246
#
247
# Inputs          : All global
248
#
249
# Returns         : 
250
#
251
sub generatePackage
252
{
297 dpurdie 253
    #
379 dpurdie 254
    #   Transfer source to target and remove generated files
297 dpurdie 255
    #
379 dpurdie 256
    mkpath ($dest_dir,$opt_verbose);
257
    Error( "Cannot create target directory") unless ( -d $dest_dir);
227 dpurdie 258
 
379 dpurdie 259
    Message ("Transfer package to local directory");
260
    File::Find::find( \&CopyDir, $src_dir );
261
 
297 dpurdie 262
    #
379 dpurdie 263
    #   Create a build.pl file based on a template
297 dpurdie 264
    #
379 dpurdie 265
    Message ("Create build.pl");
266
    open (BUILD, ">", "$dest_dir/build.pl" );
267
    while ( <DATA> )
268
    {
269
        chomp;
270
        last if ( /^__ENDBUILD/ );
227 dpurdie 271
 
379 dpurdie 272
        #
273
        #   Substitute values
274
        #
275
        s~__PACKAGENAME__~$ARGV[0]~g;
276
        s~__PACKAGEVERSION__~$ARGV[1]~g;
277
        if ( m/__BUILDNAME__/ )
278
        {
279
            if ( $ARGV[1] =~ m~^\d+\.\d+\.\d+[\s.]+(\w+)$~ )
280
            {
281
                print BUILD "BuildName       ( '$ARGV[0]', '$ARGV[1]' );\n";
282
            }
283
            elsif ( $ARGV[1] =~ m~^(.*)\.+(\D+)$~ )
284
            {
285
                my $ver = $1;
286
                my $prj = $2;
287
                print BUILD "BuildName       ( '$ARGV[0]', '$ver', '$prj', '--RelaxedVersion' );\n";
288
            }
289
            else
290
            {
291
                print BUILD "BuildName       ( '$ARGV[0]', '$ARGV[1]', '--RelaxedVersion' );\n";
292
                print "Buildname: '$ARGV[0]', '$ARGV[1]'\n";
293
            }
294
 
295
            next;
296
        }
297
 
298
        print BUILD "$_\n";
299
    }
300
    close (BUILD);
301
 
297 dpurdie 302
    #
379 dpurdie 303
    #   Create a makefile.pl based on a template
297 dpurdie 304
    #
379 dpurdie 305
    Message ("Create src/makefile.pl");
306
    mkdir "$dest_dir/src";
307
    open (MAKE, ">", "$dest_dir/src/makefile.pl" );
308
    while ( <DATA> )
309
    {
310
        chomp;
311
        last if ( /^__ENDMAKE/ );
227 dpurdie 312
 
379 dpurdie 313
        #
314
        #   Substitute values
315
        #
316
        s~__PACKAGENAME__~$ARGV[0]~g;
317
        s~__PACKAGEVERSION__~$ARGV[1]~g;
318
        if ( /__PACKAGEFILE__/ )
297 dpurdie 319
        {
379 dpurdie 320
            unless ( $DESTDIR )
321
            {
322
                foreach my $file ( sort keys %files )
323
                {
324
 
325
                    print MAKE "PackageFile ( '*', '../$file', '--StripDir' );\n";
326
                }
327
            } else {
328
                foreach my $file ( sort keys %files )
329
                {
330
 
331
                    print MAKE "PackageFile ( '*', '$file' );\n";
332
                }
333
            }
334
            foreach my $subdir ( sort keys %subdirs )
335
            {
336
                print MAKE "PackageFile ( '*', '--DirTree=$subdir' );\n";
337
            }
338
            next;
297 dpurdie 339
        }
379 dpurdie 340
        print MAKE "$_\n";
227 dpurdie 341
    }
379 dpurdie 342
    close (MAKE);
227 dpurdie 343
}
344
 
379 dpurdie 345
#-------------------------------------------------------------------------------
346
# Function        : CopyDir
227 dpurdie 347
#
379 dpurdie 348
# Description     : Find callback function used to copy the archive
227 dpurdie 349
#
379 dpurdie 350
# Inputs          :
351
#
352
# Returns         :
353
#
354
sub CopyDir
227 dpurdie 355
{
379 dpurdie 356
    my $item = $File::Find::name;
357
    my $base = File::Basename::basename($item);
227 dpurdie 358
 
379 dpurdie 359
    #
360
    #   Skip generated files
361
    #
362
    return if ( $base =~ m/^descpkg$/ );
363
    return if ( $base =~ m/^RELEASE_NOTES_/ );
364
    return if ( $base =~ m/^built\./ );
227 dpurdie 365
 
379 dpurdie 366
    #
367
    #   Don't process directories
368
    #
369
    return if ( -d $item );
227 dpurdie 370
 
379 dpurdie 371
    #
372
    #   Calculate target directory
373
    #
374
    my $sdl = length ($src_dir);
375
    my $target = $dest_dir . '/' . $DESTDIR . substr ( $item, $sdl );
227 dpurdie 376
 
379 dpurdie 377
    #
378
    #   Determinate top level package directories
379
    #
380
    my $rootdir = substr ( $item, 1 + $sdl );
381
    $rootdir =~ s~/.*~~;
227 dpurdie 382
 
379 dpurdie 383
    if ( $rootdir eq $base )
384
    {
385
        $files{$base} = 1;
386
    } else {
387
        $subdirs{$rootdir} = 1;
388
    }
389
 
390
    my $tdir = $target;
391
    $tdir =~ s~/[^/]+$~~;
392
 
393
#    print "================$item, $base, $tdir, $target, $rootdir\n";
394
 
395
    mkpath ($tdir, 0) unless ( -d $tdir );
396
 
397
    Verbose( "Transfer: $target");
398
    File::Copy::copy( "$item", "$target") || Error("Copy Fault: $item, $target");
399
 
400
}
401
 
402
#-------------------------------------------------------------------------------
403
# Function        : ClearCaseValidate
227 dpurdie 404
#
379 dpurdie 405
# Description     : Validate the ClearCase VOB and label
227 dpurdie 406
#
379 dpurdie 407
# Inputs          : Globals
408
#
409
# Returns         : Nothing
410
#
411
sub ClearCaseValidate
227 dpurdie 412
{
379 dpurdie 413
    #
414
    #   Validate / locate the target VOB
415
    #
416
    locate_vob();
227 dpurdie 417
 
418
    #
379 dpurdie 419
    #   Ensure that the label is not locked
420
    #   The user will not be able to move the label if it is already locked
227 dpurdie 421
    #
379 dpurdie 422
    my $label_exists = 0;
423
    Verbose ("Check label exists");
424
    ClearCmd ("describe -short lbtype:$opt_label@/$vob_name" ) unless $opt_test;
425
    $label_exists = 1 unless( $opt_test || grep ( /Label type not found/, @error_list ));
426
    Verbose ("Check label: $label_exists");
427
 
428
    if ( $label_exists )
227 dpurdie 429
    {
379 dpurdie 430
        Verbose ("Check label not locked");
431
        ClearCmd ("describe -fmt %[locked]p lbtype:$opt_label@/$vob_name" );
432
        unless ( $last_result && $last_result =~ m~unlocked~ )
227 dpurdie 433
        {
379 dpurdie 434
            Error("Label is locked: $opt_label");
227 dpurdie 435
        }
436
    }
437
}
438
 
379 dpurdie 439
#-------------------------------------------------------------------------------
440
# Function        : SubversionValidate
227 dpurdie 441
#
379 dpurdie 442
# Description     : Validate the Subversion Repository and label
227 dpurdie 443
#
379 dpurdie 444
# Inputs          : Globals
445
#
446
# Returns         : Nothing
447
#
448
sub SubversionValidate
227 dpurdie 449
{
379 dpurdie 450
    #
451
    #   Ensure that the created label will be acceptable
452
    #
453
    $opt_label = SvnIsaSimpleLabel ($opt_label);
227 dpurdie 454
 
455
    #
379 dpurdie 456
    #   Prevent the user from creating paths that are too deep
457
    #   Don't want repos that contain hidden packages
227 dpurdie 458
    #
379 dpurdie 459
    Error ("Created repository structure will be too deep")
460
        if ( ($opt_subdir =~ tr~/~~) >= 2  );
461
 
462
    #
463
    #   Create a subversion session
464
    #   Ensure that the repository exists
465
    #
466
    $svnPackageName = $opt_repository . '/' . $opt_subdir;
467
    $svnSession = NewSessionByUrl ( $svnPackageName, 0 );
468
    my $rv = $svnSession->SvnValidateTarget (
469
                        'target' => $svnSession->Full(),
470
                        'test' => 1,
471
                        );
472
    if ( $rv )
227 dpurdie 473
    {
379 dpurdie 474
        #
475
        #   Package exists within the Repo
476
        #   Ensure its a valid package
477
        $svnSession->SvnValidatePackageRoot();
478
        $svnPackageExists = 1;
227 dpurdie 479
 
379 dpurdie 480
        $rv = $svnSession->SvnValidateTarget (
481
                        'target' => $svnSession->BranchName( $opt_label, 'tags' ),
482
                        'test' => 1,
483
                        );
484
        if ( $rv )
227 dpurdie 485
        {
379 dpurdie 486
            Warning ("Target label already exists in the repository",
487
                     "It will be replaced" );
227 dpurdie 488
        }
489
    }
490
}
491
 
379 dpurdie 492
#-------------------------------------------------------------------------------
493
# Function        : ClearCaseImport
227 dpurdie 494
#
379 dpurdie 495
# Description     : Import the generated package into ClearCase
496
#                   Label and all
497
#                   The clearcase command will adjust the target directory
498
#                   to match the source
227 dpurdie 499
#
379 dpurdie 500
# Inputs          : 
227 dpurdie 501
#
379 dpurdie 502
# Returns         : 
227 dpurdie 503
#
379 dpurdie 504
sub ClearCaseImport
297 dpurdie 505
{
379 dpurdie 506
 
507
    #
508
    #   Determine the target directory within the VOB
509
    #   This is the source directory tree, with the last element removed
510
    #
511
    my $target_path = "";
512
    if ( $opt_subdir =~ m~/~ )
513
    {
514
        $target_path = $opt_subdir;
515
        $target_path =~ s~/[^/]*$~~;
516
        $target_path = '/' . $target_path;
517
    }
518
 
297 dpurdie 519
    Message ("Import to clearcase vob: $opt_vob");
520
    my $cmd = "clearfsimport.exe -nsetevent -rec -rmname";
521
       $cmd .= " -preview" if $opt_test;
522
       $cmd .= " -mklabel $opt_label";
523
       $cmd .= " -c \"Package snapshot $ARGV[0]_$ARGV[1]\"";
524
       $cmd .= " $dest_dir $opt_vob$target_path";
227 dpurdie 525
 
297 dpurdie 526
    Verbose($cmd);
527
    @error_list = ();
528
    open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
529
    while (<CMD>)
530
    {
531
        #
532
        #   Filter output from the user
533
        #
534
        chomp;
535
        Verbose($_);
536
        push @error_list, $_ if ( m~Error:~ );
537
    }
538
    close(CMD);
539
    if ( @error_list )
540
    {
379 dpurdie 541
        ReportError ($_) foreach ( @error_list );
297 dpurdie 542
        Error("Problem encountered saving package image");
543
    }
227 dpurdie 544
 
545
    #
297 dpurdie 546
    #   Apply label to all directories upto the root of the VOB
547
    #   The label will have been applied to the TIP
227 dpurdie 548
    #
297 dpurdie 549
    Verbose ("Label package path");
550
    my $lpath = $opt_vob;
551
    foreach ( split ('/', $target_path) )
552
    {
553
        $lpath = $lpath . '/' . $_;
554
        Verbose ("Label package path: $lpath");
555
        ClearCmd ("mklabel -replace $opt_label $lpath" ) unless $opt_test;
556
        Error ("Program Terminated") if ( @error_list );
557
    }
227 dpurdie 558
 
297 dpurdie 559
    #
560
    #   Lock the label
561
    #
562
    Message ("Locking label: $opt_label");
563
    ClearCmd ("lock lbtype:$opt_label\@/$vob_name" ) unless $opt_test;
241 dpurdie 564
    Error ("Program Terminated") if ( @error_list );
565
}
227 dpurdie 566
 
567
#-------------------------------------------------------------------------------
379 dpurdie 568
# Function        : SubversionImport
227 dpurdie 569
#
379 dpurdie 570
# Description     : Import the generated package into Subversion
571
#                   Label and all
227 dpurdie 572
#
379 dpurdie 573
# Inputs          : 
227 dpurdie 574
#
379 dpurdie 575
# Returns         : 
227 dpurdie 576
#
379 dpurdie 577
sub SubversionImport
227 dpurdie 578
{
379 dpurdie 579
    return if ( $opt_test );
227 dpurdie 580
 
379 dpurdie 581
    unless ($svnPackageExists)
582
    {
583
        #
584
        #   Create the package if it does not already exist
585
        #   This is the simple process
586
        #
587
        $svnSession->{PRINTDATA} = 0;
588
        $svnSession->SvnCreatePackage (
1403 dpurdie 589
                      'import'      => $dest_dir,
590
                      'label'       => $opt_label,
591
                      'new'         => 1,
592
                      'printdata'   => $opt_verbose,
379 dpurdie 593
                      );
1403 dpurdie 594
        $svnRmRef = $svnSession->SvnTag();
379 dpurdie 595
    }
596
    else
597
    {
598
        #
599
        #   Package exists
1403 dpurdie 600
        #   Hard bit: Need to merge the existing trunk with this version
379 dpurdie 601
        #             and label the entire lot
602
        #   We already have a program to do that.
603
        #
604
        my $workdir = "$dest_root/SvnImport";
605
        my $datafile = "$dest_root/svnData.txt";
606
        my $rv = JatsTool ('jats_svn', 'import',
607
                    "-package=$svnPackageName",
608
                    "-dir=$dest_dir",
609
                    "-label=$opt_label",
610
                    "-datafile=$datafile",
611
                    "workspace=$workdir",
1403 dpurdie 612
                    "-replace",
613
                    "-printfiles=$opt_verbose"
379 dpurdie 614
                );
615
        if ( $rv )
616
        {
617
            Error ("Error importing package");
618
        }
227 dpurdie 619
 
379 dpurdie 620
        if ( -f $datafile  )
621
        {
622
            my $rmData = JatsProperties::New($datafile);
623
            $svnRmRef = $rmData->getProperty('subversion.tag');
624
        }
625
    }
626
    unless ( $svnRmRef  )
227 dpurdie 627
    {
379 dpurdie 628
        Error ('Failed to determin RM Reference');;
227 dpurdie 629
    }
630
}
631
 
632
#-------------------------------------------------------------------------------
633
# Function        : locate_vob
634
#
635
# Description     : Locate the target VOB
297 dpurdie 636
#                   This is a bit tricky as it makes a few assumptions
227 dpurdie 637
#                       1) That clearcase dynamic views are mounted through the "o" drive
638
#                          This appears to be a standard(ish) configuration.
639
#
640
#                       2) There must be a dynamic view on the machine that does have the
641
#                          required VOB mounted
642
#
643
#                   Note: Assumes that the user is NOT trying to place the package
644
#                         into a subdir of the VOB.
645
#
646
# Inputs          : None
647
#
648
# Returns         : Global: $opt_vob
649
#
650
 
651
sub locate_vob
652
{
653
    #
654
    #   If the user has specified an absolute path then use the users VOB
655
    #
656
    $opt_vob =~ tr~\\/~/~s;
657
    if ( $opt_vob =~ m~[A-Za-z]\:/~ || $opt_vob =~ m~/~ )
658
    {
659
        Error ("User VOB does not exist: $opt_vob") unless ( -d $opt_vob );
660
 
661
        $opt_vob =~ m~(.*/)(.*)~;
662
        $vob_dir = $1;
663
        $vob_name = $2;
664
        return;
665
    }
666
 
667
    #
668
    #   Scan for a dynamic view
669
    #
241 dpurdie 670
    Message ("Scanning for suitable dynamic view");
227 dpurdie 671
    my @search_list = glob ("O:/*");
672
    my $found_vob;
673
    foreach my $dir ( @search_list )
674
    {
675
        my $test_vob = "$dir/$opt_vob";
676
        Verbose ("Testing vob: $test_vob" );
241 dpurdie 677
        next if ( $dir =~ m~solaris~i );                    # Take the hint
678
        next if ( $dir =~ '/administration_view$' );        # Known read-only VOB
679
 
227 dpurdie 680
        if ( -d $test_vob )
681
        {
682
            $found_vob = $dir;
683
            last;
684
        }
685
    }
686
    Error ("Cannot find a suitable view with the $opt_vob VOB mounted") unless ( $found_vob );
687
 
688
    $vob_dir = $found_vob;
689
    $vob_name = $opt_vob;
690
    $opt_vob = "$vob_dir/$vob_name";
241 dpurdie 691
    Message ("Using VOB: $opt_vob");
227 dpurdie 692
}
693
 
694
#-------------------------------------------------------------------------------
695
# Function        : ClearCmd
696
#
697
# Description     : Similar to the system command
698
#                   Does allow standard output and standard error to be captured
699
#                   to a log file
700
#
701
#                   Used since I was having problems with calling other programs
702
#                   and control-C. It could hang the terminal session.
703
#
704
# Inputs          :
705
#
706
# Returns         :
707
#
708
sub ClearCmd
709
{
710
    my( $cmd ) = @_;
711
    Verbose2 "cleartool $cmd";
712
 
713
        @error_list = ();
714
        open(CMD, "cleartool $cmd  2>&1 |")    || Error "can't run command: $!";
715
        while (<CMD>)
716
        {
717
            chomp;
718
            $last_result = $_;
719
            Verbose ( "cleartool resp:" . $_);
720
            push @error_list, $_ if ( m~Error:~ );
721
        }
722
        close(CMD);
723
 
724
    Verbose2 "Exit Status: $?";
725
    return $? / 256;
726
}
727
 
379 dpurdie 728
########################################################################
227 dpurdie 729
#
379 dpurdie 730
#   The following text contains two templates used in the creation
731
#   of a build.pl and a makefile.pl
227 dpurdie 732
#
379 dpurdie 733
#   The text is read and keywords are processed
227 dpurdie 734
#
735
 
736
__DATA__
379 dpurdie 737
########################################################################
6177 dpurdie 738
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 739
#
740
# Module name   : build.pl
297 dpurdie 741
# Module type   : JATS Build File
742
# Environment(s): JATS Build System
227 dpurdie 743
#
744
# Description:    build.pl for package __PACKAGENAME__
745
#.........................................................................#
746
 
747
#..     Build system
748
#
749
$MAKELIB_PL     = "$ENV{ GBE_TOOLS }/makelib.pl";
750
$BUILDLIB_PL    = "$ENV{ GBE_TOOLS }/buildlib.pl";
751
 
752
require         "$BUILDLIB_PL";
753
require         "$MAKELIB_PL";
754
 
755
#..     Product configuration
756
#
757
BuildPlatforms   ( 'GENERIC' );
758
 
759
__BUILDNAME__ BuildName       ( '__PACKAGENAME__', '__PACKAGEVERSION__' );
760
BuildInterface  ( 'interface' );
761
 
762
#
763
#   Specify subdirectories to process
764
#
765
BuildSubDir    ( 'src' );
766
 
767
#
768
#   Generate Files
769
BuildDescpkg   ();
770
BuildMake      ();
771
__ENDBUILD
379 dpurdie 772
########################################################################
6177 dpurdie 773
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 774
#
775
# Module name   : Makefile.pl
379 dpurdie 776
# Module type   : JATS Make File
297 dpurdie 777
# Environment(s): JATS Build System
227 dpurdie 778
#
779
# Description:    makefile.pl for package __PACKAGENAME__
780
#
781
#.........................................................................#
782
 
783
die "Usage: Makefile.pl rootdir Makelib.pl\n"
784
    unless( $#ARGV+1 >= 2 );
785
require "$ARGV[1]";
786
 
787
#
788
# Build platform definitions ..
789
#
790
Platform( '*' );
791
 
792
############################################################################
793
#   Define the source files
794
#
795
 
796
#.............................................................................
797
# Packaging definitions
798
#
799
__PACKAGEFILE__ PackageFile ( '*', '--DirTree=jar' );
800
 
801
#..
802
#
803
Src         ( '*'   , 'descpkg' );
804
PackageFile ( '*'   , 'descpkg' );
805
 
806
#.............................................................................
807
# Finally generate the makefile
808
#
809
MakefileGenerate();
810
 
811
#..  Successful termination
812
1;
813
__ENDMAKE
814
 
815
#-------------------------------------------------------------------------------
816
#   Documentation
817
#
818
 
819
=pod
820
 
821
=head1 NAME
822
 
823
gen_cots - Create a buildable package from dpkg_archive and place it under
824
version control
825
 
826
=head1 SYNOPSIS
827
 
5104 dpurdie 828
jats gen_cots package version [-vob=aa|-repo=aa|-keep] [-image=aaa|-package]
227 dpurdie 829
 
830
 Options:
831
    -help              - brief help message
832
    -help -help        - Detailed help message
833
    -man               - Full documentation
2429 dpurdie 834
    -vob=vvv           - VOB to use, may be a full path.
379 dpurdie 835
    -repository=path   - Subversion Repository
836
    -keep              - Keep the creating dpkg_archive image
227 dpurdie 837
    -label=name        - Specify a label for the versions source
838
    -subdir=nnn        - Named subdir in VOB
379 dpurdie 839
    -test              - Do not perform operations that modify Version Control
227 dpurdie 840
    -image=path        - Path to alternate source image
5104 dpurdie 841
    -package           - Locate image in package archive
227 dpurdie 842
 
843
=head1 OPTIONS
844
 
845
=over 8
846
 
847
=item B<-help>
848
 
849
Print a brief help message and exits.
850
 
851
=item B<-help -help>
852
 
853
Print a detailed help message with an explanation for each option.
854
 
855
=item B<-man>
856
 
857
Prints the manual page and exits.
858
 
859
=item B<-label=name>
860
 
861
This option specifies an alternate label for the checked in source. The
862
default label is based on package and version.
863
 
864
=item B<-vob=vvv>
865
 
379 dpurdie 866
This option invokes the ClearCase mode of operation. The generated code
867
will be checked into ClearCase. This is only available under Windows.
868
 
227 dpurdie 869
This option specifies the VOB into which the saved package will be placed.
870
 
871
There are two ways that this option may be used.
872
 
873
=over 8
874
 
875
=item 1
876
 
877
Simply name the VOB. (ie: COTS) The script will locate a dynamic view on the
363 dpurdie 878
users machine that contains the view. This is done by scanning dynamic views in
227 dpurdie 879
the "O:" drive.
880
 
881
=item 2
882
 
883
The full path to a VOB, including driver is provided. (ie: z:/COTS). This will
884
prevent the script from locating the VOB. It will use the named view.
885
 
886
=back
887
 
379 dpurdie 888
=item B<-repository=path>
227 dpurdie 889
 
379 dpurdie 890
This option invokes the Subversion mode of operation. The generated code
891
will be checked into Subversion.
892
 
893
The argument is the path to the base of the package. The package name
894
will be appended by this program.
895
 
896
=item B<-keep>
897
 
898
If this option is selected then the program will retain the working directory
899
that it has created.
900
 
901
If neither -vob or -repository is used, then this option must be provided.
902
 
227 dpurdie 903
=item B<-subdir=name>
904
 
905
This option specifies the name of a subdirectory in which the package will be created.
906
The default name it taken from the package name.
907
 
908
=item B<-test>
909
 
379 dpurdie 910
This option will suppress the Version Control operations.
227 dpurdie 911
No files will be checked in and the label will not be locked.
912
 
913
=item B<-image=path>
914
 
915
If this option is specified then the package will be created using the
5104 dpurdie 916
specified source path.
227 dpurdie 917
 
918
This option allows a locally created image to be stored as a COTS package
919
before it is placed in dpkg_archive.
920
 
5104 dpurdie 921
Either the -image or the -package option must be specified.
922
 
923
=item B<-image=path>
924
 
925
If this option is specified then the package image will be extracted from dpkg_archive.
926
 
927
Either the -image or the -package option must be specified.
928
 
227 dpurdie 929
=back
930
 
931
=head1 DESCRIPTION
932
 
933
This program will create a version controlled and JATS buildable package from
934
a dpkg_archive package version.
935
 
936
In doing this the program will:
937
 
938
=over 8
939
 
940
=item   *
941
 
942
Create a temporary directory in the users current directory. This will
943
be used to contain a copy of the package.
944
 
945
=item   *
946
 
947
Transfer the named package and version into the temp directory. The files will
948
be transferred in the a 'src' directory within the temp directory.
949
 
950
=item   *
951
 
952
Create JATS build.pl and makefile.pls to support the creation of the
953
package. The build.pl file will contain the package name and the package
954
version.
955
 
956
=item   *
957
 
379 dpurdie 958
Transfer the entire image into the named ClearCase VOB or Subversion Repository.
959
The files will be labeled and the Version Control System target modified to
960
mimic the temp directory view.
227 dpurdie 961
 
962
=item   *
963
 
379 dpurdie 964
Lock the label used to mark the files (ClearCase Only).
227 dpurdie 965
 
966
=item   *
967
 
968
Remove the temp work space.
969
 
970
=item   *
971
 
972
Display information to be entered into Release Manager.
973
 
974
=back
975
 
976
=head1 EXAMPLE
977
 
379 dpurdie 978
=head2 ClearCase
227 dpurdie 979
 
5104 dpurdie 980
    jats etool gen_cots -vob=z:/COTS mos_api 5.6.0.cr -package
379 dpurdie 981
 
982
This will take the version 5.6.0.cr of the mos_api package from dpkg_archive
227 dpurdie 983
place it under version control within the COTS vob and add files to allow the
984
dpkg_archive package to be recreated in an JATS buildable manner.
985
 
379 dpurdie 986
=head2 Subversion
987
 
5104 dpurdie 988
    jats etool gen_cots -repository=AUPERASVN01/COTS mos_api 5.6.0.cr -image=mos_api_5_6_0_cr
379 dpurdie 989
 
5104 dpurdie 990
This will take the image in the specified directory ( which must be in a dpkg_archive complient fomat) and
991
place it under version control within the COTS Repository and add files to allow the image to be
992
recreated in dpkg_archive in a JATS buildable manner as a package called mos_api with a version of 5.6.0.cr.
379 dpurdie 993
 
227 dpurdie 994
=cut
995