Subversion Repositories DevTools

Rev

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

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