Subversion Repositories DevTools

Rev

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