Subversion Repositories DevTools

Rev

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