Subversion Repositories DevTools

Rev

Rev 5710 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
392 dpurdie 3
#
4
# Module name   : jats_ccrelease.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : A script to build a package from a clearcase element
10
#                 The script will:
11
#                   Create a clearcase view
12
#                   Checkout the files
13
#                   Locate the build file
14
#                   Build the packages
15
#                   Install packages
16
#                   Remove the view
17
#
18
#               The script can do a lot of other things too.
19
#
20
#
21
#               Kludged up version pf cc_release to create a dynamic view
22
#
23
#......................................................................#
24
 
25
require 5.008_002;
26
use strict;
27
use warnings;
28
use JatsError;
29
use JatsSystem;
30
use FileUtils;
31
use JatsBuildFiles;
32
use ArrayHashUtils;
33
 
34
use Pod::Usage;                             # required for help support
35
use Getopt::Long;
36
use File::Find;
37
use File::Copy;
38
use File::Path;
39
use Cwd;
40
 
41
my $VERSION = "1.6.0";                      # Update this
42
 
43
#
44
#   Options
45
#
46
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
47
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
48
my $opt_help = 0;                           # User help level
49
my @opt_spec;                               # Labels used as a base for the view
50
my $opt_vob;                                # Hint: which VOB to use
51
my $opt_dpkg = 1;                           # Transfer built package to dpkg_archive
52
my $opt_copy = 0;                           # Copy built package to user
53
my $opt_reuse = 0;                          # Re-user view if it exists
54
my $opt_viewname;                           # View Name
55
my $opt_extract;                            # Just create a static view
56
my $opt_extract_files;                      # Just extract files to user - no view
57
my $opt_delete;                             # Just delete the view
58
my @opt_build;                              # build files to use (kludge)
59
my $opt_test;                               # Test the build process - no copy
60
my $opt_cache;                              # Cache external packages
61
my $opt_keep = 0;                           # Keep view if successful
62
my $opt_lock = 0;                           # Lock label before release
63
my $opt_beta;                               # Create beta release
64
my $opt_merge;                              # Merge release
65
my $opt_path;                               # Path for view spec
66
my $opt_runtests = 1;                       # Run unit tests after build
67
my $opt_latest_root;                        # Modify config spec with rule (kludge)
68
my $opt_branch;                             # Create config spec with branch
69
my $opt_debug_build = 0;                    # Build Debug Only
70
my $opt_prod_build = 0;                     # Build ion Only
71
my $opt_config_spec;                        # User provided config spec
72
my $opt_prefix = 1;                         # Prefix the view tag with user-name
73
my $opt_tag;                                # View tag insert (build or export or user)
74
 
75
#
76
#   Globals - Provided by the JATS environment
77
#
78
my $USER            = $ENV{'USER'};
79
my $UNIX            = $ENV{'GBE_UNIX'};
80
my $GBE_ABT         = $ENV{'GBE_ABT'} || '0';
81
my $MACHINENAME     = $ENV{'GBE_HOSTNAME'};
82
my $GBE_VIEWBASE    = $ENV{'GBE_VIEWBASE'};   # Root of the view
83
 
84
#
85
#   Globals
86
#
87
my $VIEWDIR_ROOT;                           # Root of the static view
88
my $VIEWTAG;                                # The view tag
89
my $VIEWDIR;                                # Absolute path to the view
90
my $VIEWPATH;                               # Path relative to clearcase
91
my $user_cwd;
92
my $error = 0;
93
my $label_count = 0;                        # Number of labels to create the view
94
my @label_not_locked;                       # List of unlocked labels
95
my @label_locked;                           # List of labels I locked
96
my @error_list;                             # ClearCmd detected errors
97
 
98
my $UNIX_VOB_PREFIX = '/vobs';
99
my $VOB_PREFIX = $UNIX ? $UNIX_VOB_PREFIX : '';
100
 
101
my $UNIX_VIEW_PREFIX = '/view/';            # Don't know how to determine this value
102
my $WIN32_VIEW_PREFIX = 'o:/';              # Don't know how to determine this value
103
my $VIEW_PREFIX = $UNIX ? $UNIX_VIEW_PREFIX : $WIN32_VIEW_PREFIX ;
104
 
105
my $VOB_SEP         = $UNIX ? '/' : '\\';
106
my $view_prefix     = "${USER}_";
107
 
108
#
109
#   ROOT_VOBS is a list of VOBS too look in first
110
#   If a label is not found in these vobs, then the program will
111
#   look in all vobs. This list is a hint to speed up searching
112
#
113
my $ROOT_VOB;
114
my $root_vob_spec;
115
my @ROOT_VOBS = qw( /LMOS /DPG_SWBase /DPG_SWCode /ProjectCD /MASS_Dev_Bus
116
                    /MASS_Dev_Infra /MOS /MASS_Dataman /MASS_Dev /MASS_Dev_Dataman
117
                    /COTS /GMPTE2005 /GMPTE2005_obe /MPR /MOS );
118
 
119
 
120
#-------------------------------------------------------------------------------
121
# Function        : Mainline Entry Point
122
#
123
# Description     :
124
#
125
# Inputs          :
126
#
127
 
128
#
129
#   Parse the user options
130
#
131
my $result = GetOptions (
132
                "help+"         => \$opt_help,              # flag, multiple use allowed
133
                "manual:3"      => \$opt_help,              # flag
134
                "v|verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
135
                "label=s"       => \@opt_spec,              # Array of build specs
136
                "spec=s"        => \@opt_spec,              # Array of build specs
137
                "config=s"      => \$opt_config_spec,       # String
138
                "view=s"        => \$opt_viewname,          # String
139
                "vob=s"         => \$opt_vob,               # String
140
                "dpkg!"         => \$opt_dpkg,              # [no]flag
141
                "copy!"         => \$opt_copy,              # [no]flag
142
                "reuse!"        => \$opt_reuse,             # [no]flag
143
                "extract"       => \$opt_extract,           # flag
144
                "extractfiles"  => \$opt_extract_files,     # flag
145
                "delete:+"      => \$opt_delete,            # flag
146
                "build=s"       => \@opt_build,             # An array of build
147
                "test!"         => \$opt_test,              # [no]flag
148
                "cache"         => \$opt_cache,             # flag
149
                "keep!"         => \$opt_keep,              # [no]flag
150
                "lock!"         => \$opt_lock,              # [no]flag
151
                "beta!"         => \$opt_beta,              # [no]flag
152
                "merge"         => \$opt_merge,             # [no]flag
153
                "path=s"        => \$opt_path,              # string
154
                "runtests!"     => \$opt_runtests,          # [no]flag
155
                "latestroot=s"  => \$opt_latest_root,       # String
156
                "branch=s"      => \$opt_branch,            # String
157
                "mkbranch=s"    => \$opt_branch,            # String
158
                "prodOnly"      => \$opt_prod_build,        # flag
159
                "debugOnly"     => \$opt_debug_build,       # flag
160
                "root=s"        => \$GBE_VIEWBASE,          # string
161
                "prefix!"       => \$opt_prefix,            # flag
162
                "tag=s"         => \$opt_tag,               # string
163
                );
164
 
165
                #
166
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
167
                #
168
 
169
#
170
#   Process help and manual options
171
#
172
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
173
pod2usage(-verbose => 1)  if ($opt_help == 2 );
174
pod2usage(-verbose => 2)  if ($opt_help > 2 );
175
 
176
InitFileUtils();
177
 
178
#
179
#   Configure the error reporting process now that we have the user options
180
#
181
ErrorConfig( 'name'    => 'RELEASE',
182
             'verbose' => $opt_verbose );
183
 
184
#
185
#   Validate user options
186
#   Use either -label or one command line argument
187
#
188
Error ("Unexpected command line arguments present.","Cannot mix -label and command line label" )
189
    if ( $#opt_spec >= 0 && $#ARGV >= 0);
190
 
191
push @opt_spec, @ARGV;
192
 
193
if ( $opt_config_spec )
194
{
195
    Error("Cannot use -path with -config")      if($opt_path);
196
    Error("Cannot use -branch with -config")    if($opt_branch);
197
    Error("Cannot use -vob with -config")       if($opt_vob);
198
    Error("Cannot use a label with -config")    if( @opt_spec);
199
    Error("Config spec file not found: $opt_config_spec") unless ( -f $opt_config_spec );
200
 
201
    unless ( $opt_viewname )
202
    {
203
        $opt_viewname = StripDirExt($opt_config_spec);
204
        $opt_viewname =~ s~[\.:/\\]~_~g;
205
    }
206
 
207
    $opt_vob = "";
208
 
209
    #
210
    #   Convert file in an absolute file name
211
    #   Will be needed as we change directory
212
    #
213
    $opt_config_spec = FullPath($opt_config_spec);
214
}
215
 
216
unless(  @opt_spec || $opt_config_spec  )
217
{
218
    Error ("Need a view or a label. -help for options") if ( $opt_delete  && ! $opt_viewname );
219
    Error ("Need a label or config_spec. -help for options") unless $opt_delete;
220
}
221
 
222
#
223
#   Convert label with embedded VCS information into a 'normal' form.
224
#   Form:
225
#       CC::label
226
#       CC::path::label
227
#       CC::::label
228
#
229
foreach ( @opt_spec )
230
{
231
    if ( $_ =~ m~^(.+?)::(.*?)(::(.+))?$~ )
232
    {
233
        Error ("Label contains invalid Version Control Identifier($1): $_")
234
            if ( $1 ne 'CC' );
235
 
236
        my $ll = $2;
237
        my $path;
238
        if ( $3 )
239
        {
240
            $path = $2;
241
            $ll = $4;
242
            if ( $path  )
243
            {
244
                Error ("Multiple conflicting Embedded source paths",
245
                       "Path: $opt_path",
246
                     "VCS Spec: $_" ) if ( $opt_path && $path ne $opt_path );
247
                $opt_path = $path;
248
            }
249
        }
250
        $_ = $ll;
251
    }
252
    Verbose ("Clean URL: $_");
253
}
254
 
255
#
256
#   User has specified both debug and production
257
#   Then set both to 0 : ie default
258
#
259
if ( $opt_debug_build + $opt_prod_build > 1 )
260
{
261
    $opt_debug_build = 0;
262
    $opt_prod_build = 0;
263
}
264
 
265
#
266
#   User has requested test mode
267
#       - Don't copy
268
#       - Don't packgae
269
#
270
if ( $opt_test )
271
{
272
    $opt_dpkg = 0;
273
    $opt_copy = 0;
274
}
275
 
276
#
277
#   Determine the machine type
278
#
279
Verbose ("Machine Type: UNIX=$UNIX");
280
 
281
Error ("Machine Name not determined")
282
    unless ( $MACHINENAME );
283
$user_cwd = getcwd;
284
 
285
Error ("USER name not determined" )
286
    unless ( $USER );
287
 
288
#
289
#   Ensure that the 'cleartool' program can be located
290
#
291
Verbose ("Locate clearcase utility in users path");
292
Error ("Cannot locate the 'cleartool' utility in the users PATH")
293
    unless ( LocateProgInPath('cleartool', '--All') );
294
 
295
 
296
#
297
#   Clean up the view root directory
298
#
299
$VIEWDIR_ROOT = Realpath($GBE_VIEWBASE) || $GBE_VIEWBASE;
300
 
301
Verbose ("Viewpath: $VIEWDIR_ROOT");
302
Error ("Cannot locate view root directory: $VIEWDIR_ROOT" ) unless (-d $VIEWDIR_ROOT);
303
 
304
#
305
#   Remove any user name from the front of the view name
306
#   Simplifies the deletion process as the user can provide
307
#   the directory name
308
#
309
$view_prefix = "" unless ( $opt_prefix );
310
 
311
#
312
#   Setup user specified viewname
313
#   Include the user name to ensure that the view name is unique-ish
314
#   Keep the name as short as possible as some compilers display a fixed
315
#   length filename in error messages and this name is part of the path
316
#
317
#   Base the viewname on the view label. This will simplify the creation
318
#   of multiple views and reduce the risk of unexpected deletion
319
#
320
$opt_viewname = $opt_spec[0] unless ( defined $opt_viewname );
321
$opt_viewname =~ s~^$view_prefix~~ if (defined($opt_viewname) && $view_prefix && $opt_delete );
322
 
323
#
324
#   Create the view tag
325
#   Attempt to make this globally unique
326
#   Include USER name, MACHINE name, the view name
327
#   Optionally include a user 'tag'. Provided to allow the ABT to maintain
328
#   multiple instances of a view.
329
#
330
unless ( $opt_tag )
331
{
332
    $opt_tag = 'dynamic';
333
}
334
$VIEWTAG = "${USER}_${MACHINENAME}_${opt_tag}_${opt_viewname}";
335
 
336
#
337
#   Create a clearcase view to be used for the view
338
#
339
$VIEWPATH = "$view_prefix$opt_viewname";
340
$VIEWDIR = "$VIEWDIR_ROOT/$VIEWPATH";
341
$VIEWDIR =~ tr~\\/~/~s;
342
Verbose( "Hostname: $MACHINENAME" );
343
Verbose( "Viewtag: $VIEWTAG" );
344
Verbose( "Viewpath: $VIEWPATH" );
345
Verbose( "Viewdir : $VIEWDIR" );
346
 
347
#
348
#   If the user has specified a "source path", then we can extract the VOB
349
#   from that path. It will be the first directory
350
#
351
Verbose("Locate Source VOB");
352
if ( $opt_path )
353
{
354
    $opt_path =~ tr~\\/~/~s;
355
    $opt_path =~ s~/+$~~;
356
 
357
    Error( "Source Path needs leading '/'") unless ( $opt_path =~ m~^/~ );
358
    Error( "Source Path is a UNC" ) if ( $opt_path =~ m~^//~ );
359
    Error( "Source Path has drive specifier" ) if ( $opt_path =~ m~^[A-Za-z]\:~ );
360
 
361
    #
362
    #   Extract the VOB from the path
363
    #
364
    unless ( $opt_vob )
365
    {
366
        my $vob = $opt_path;
367
        $vob =~ s~^/~~g;
368
        $vob =~ s~/.*~~g;
369
 
370
        $opt_vob = $vob;
371
        Verbose ("Extract VOB from path: $vob" );
372
    }
373
}
374
 
375
 
376
#
377
#   If the view currently exists then it will be deleted if allowed
378
#
379
delete_view();
380
 
381
 
382
#
383
#   If the user is simply deleting the view then all has been done
384
#
385
exit 0
386
    if ( $opt_delete );
387
 
388
#
389
#   Setup user specified VOB
390
#
391
if ( defined($opt_vob) )
392
{
393
    $ROOT_VOB = "/$opt_vob";
394
    $ROOT_VOB =~ s~//~/~g;
395
    @ROOT_VOBS = $ROOT_VOB;
396
}
397
else
398
{
399
    #
400
    #   Extend the list of ROOT_VOBS with all the known vobs
401
    #   The initial ROOT_VOBS are treated as a "hint" to assist searching
402
    #
403
        my $cmd = ClearToolCmd ('lsvob', '-short');
404
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
405
        while (<CMD>)
406
        {
407
            #
408
            #   Filter output from the user
409
            #
410
            chomp;
411
            s~^$UNIX_VOB_PREFIX~~ if ($UNIX);
412
            Verbose2("lsvob: $_");
413
            tr~\\/~/~s;
414
            push @ROOT_VOBS, $_;
415
        }
416
        close(CMD);
417
}
418
 
419
#
420
#   Ensure that the label is present within the specified VOB
421
#   Hunt for the user specified label in a number of well known VOBs
422
#
423
if ( @opt_spec )
424
{
425
    Verbose("Ensure Label is found in a VOB");
426
    my $found = 0;
427
    my $spec = $opt_spec[0];
428
    foreach my $vob ( @ROOT_VOBS )
429
    {
430
        $vob = $UNIX_VOB_PREFIX . $vob if ( $UNIX );
431
        (my $vob_name = $vob) =~ s~/~$VOB_SEP~g;
432
 
433
        Verbose2 ("Examine label $spec in vob: $vob" );
434
 
435
        my $cmd = ClearToolCmd ('lstype', "lbtype:$spec\@$vob_name");
436
        my $cmd_done = 0;
437
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
438
        while (<CMD>)
439
        {
440
            #
441
            #   Filter output from the user
442
            #   Stay in loop to avoid Broken Pipe message
443
            #
444
            chomp;
445
            Verbose2("lstype: $_");
446
            next if ( $cmd_done );
447
            next if ( m~Error~ );
448
            next unless ( m~label type~ );
449
            push @label_not_locked, $spec unless( m~\(locked\)~ );
450
            $label_count++;
451
            $found = $vob;
452
            $cmd_done = 1;
453
        }
454
        close(CMD);
455
        last if ( $found );
456
    }
457
 
458
    Error ("Label $spec not found in @ROOT_VOBS")
459
        unless ( $found );
460
    Verbose ("Label $spec found in vob: $found" );
461
 
462
    $ROOT_VOB = $found;
463
 
464
    #
465
    #   Create a VOB spec extension
466
    #
467
    $root_vob_spec = '@' . $ROOT_VOB;
468
    $root_vob_spec =~ s~/~$VOB_SEP~g;
469
 
470
    #
471
    #   Ensure that all labels are found in the VOB
472
    #
473
    foreach my $spec ( @opt_spec[1..$#opt_spec] )
474
    {
475
        $label_count++;
476
        Verbose ("Testing label $spec in vob: $ROOT_VOB" );
477
        my $data = qx( cleartool lstype lbtype:$spec$root_vob_spec );
478
        Verbose ( "lstype: $data" );
479
        Error ("Label $spec not found in $ROOT_VOB. All labels must be in the same VOB")
480
            if ( ! $data );
481
        push @label_not_locked, $spec unless( $data =~ m~\(locked\)~ );
482
    }
483
 
484
    #
485
    #   Ensure that the branch is found in the VOB
486
    #
487
}
488
 
489
#
490
#   Extracting files then ...
491
#
492
extract_files_from_view();
493
Message ("End program");
494
exit 0;
495
 
496
#-------------------------------------------------------------------------------
497
# Function        : delete_view
498
#
499
# Description     : Delete a dynamic view
500
#
501
# Inputs          : None
502
#                   $VIEWTAG - name of the view
503
#                   $VIEWDIR - path of the view
504
#
505
# Returns         :
506
#
507
sub delete_view
508
{
509
        if ( -l $VIEWDIR )
510
        {
511
            Message("Remove extracted files: $VIEWTAG");
512
            RmDirTree( $VIEWDIR );
513
        }
514
 
515
    #
516
    #   Remove the view
517
    #   Simply remove the dynamic view tag
518
    #
519
    ClearCmd ( 'rmview', '-tag', $VIEWTAG );
520
    Message ("View deleted");
521
}
522
 
523
#-------------------------------------------------------------------------------
524
# Function        : ClearTool
525
#
526
# Description     : Issue a cleartool command
527
#                   Filter out many of the stupid messages
528
#
529
# Inputs          : Options and Command line
530
#                   Options:
531
#                       --Quiet     - Supress all command output
532
#
533
# Returns         : Error code
534
#
535
sub ClearTool
536
{
537
    my $quiet;
538
 
539
    #
540
    #   Scan for initial options
541
    #       --Quiet
542
    #
543
    if ( $_[0] eq '--Quiet' )
544
    {
545
        $quiet = 1;
546
        shift;
547
    }
548
 
549
    my $cmd = ClearToolCmd(@_);
550
    open(CMD, "$cmd 2>&1 |") || Error "can't run command: $!";
551
    while (<CMD>)
552
    {
553
        #
554
        #   Filter output from the user
555
        #
556
        next if ( $quiet );
557
        unless ( $opt_verbose )
558
        {
559
            next if ( m~Making dir~ );
560
            next if ( m~End dir~ );
561
            next if ( m~Processing dir~ );
562
            next if ( m~Error~ );
563
        }
564
        print $_;
565
    }
566
    close(CMD);
567
 
568
    Verbose2 "ClearTool Exit Status: $?";
569
    return $? / 256;
570
}
571
 
572
#-------------------------------------------------------------------------------
573
# Function        : ClearCmd
574
#
575
# Description     : Execute a cleartool command
576
#                   Capture error messages only
577
#
578
# Inputs          : Command to execute
579
#                   Takes an array of command argumeents and will quote them
580
#
581
# Returns         : Exit code
582
#                   Also the global @error_list
583
#
584
sub ClearCmd
585
{
586
    @error_list = ();
587
 
588
    my $cmd = ClearToolCmd(@_);
589
    open(CMD, "$cmd  2>&1 |")    || Error "can't run command: $!";
590
    while (<CMD>)
591
    {
592
        chomp;
593
        Verbose ($_);
594
        push @error_list, $_ if ( m~Error:~ );
595
    }
596
    close(CMD);
597
 
598
    Verbose2 "Exit Status: $?";
599
    return $? / 256;
600
}
601
 
602
#-------------------------------------------------------------------------------
603
# Function        : ClearToolCmd
604
#
605
# Description     : Create a nice escaped cleartool command
606
#
607
# Inputs          : An array of cleartool command line arguments
608
#
609
# Returns         : A string that has been quoted
610
#
611
sub ClearToolCmd
612
{
613
    my $cmd = 'cleartool ' . QuoteCommand( @_);
614
    Verbose2 $cmd;
615
    return $cmd;
616
}
617
 
618
#-------------------------------------------------------------------------------
619
# Function        : extract_files_from_view
620
#
621
# Description     : This function will
622
#                       Create a dynamic view
623
#                       Copy all the files out of the view
624
#                       Delete the view
625
#
626
#                   Its used in the creation of escrow directories
627
#
628
# Inputs          : None
629
#                   All done via globals
630
#
631
# Returns         : 
632
#
633
sub extract_files_from_view
634
{
635
    my $vob_mounted = 1;
636
    my $vob_name;
637
 
638
    #
639
    #   Which config spec
640
    #   Create config spec in local dir
641
    #
642
    my $config;
643
    $config = $opt_config_spec;
644
    unless ( $opt_config_spec )
645
    {
646
        $config = create_config_spec( "config_spec.txt" );
647
    }
648
 
649
    #
650
    #   Create the view and insert the config spec
651
    #
652
    ClearCmd ( 'rmview', '-tag', $VIEWTAG );
653
    ClearCmd ( 'mkview', '-tag', $VIEWTAG, '-stgloc', '-auto' );
654
    ClearCmd ( 'setcs',  '-tag', $VIEWTAG, $config );
655
 
656
    #
657
    #   Ensure that the base VOB has been 'mounted'
658
    #   Dynamic views require vobs to be mounted
659
    #
660
    ($vob_name = $ROOT_VOB) =~ s~/~$VOB_SEP~g;
661
    $vob_mounted = ClearCmd ('mount', $vob_name);
662
 
663
    #
664
    #   Calculate where the dynmaic view will be
665
    #   This differ between UNIX/WINDOWS
666
    #
667
    my $vpath = $VIEW_PREFIX . $VIEWTAG . $VOB_PREFIX;
668
    my $cpath = $vpath;
669
       $cpath .= $opt_path if ( $opt_path );
670
    #
671
    #   Is the view where we expect it to be
672
    #
673
    Error ("Cannot locate dynamic view",
674
            "Looking in: $vpath" ) unless -d $vpath;
675
    Message ("Dynamic view path: $vpath" );
676
    Message ("Dynamic view path: $cpath" );
677
    Message ("Dynamic view tag : $VIEWTAG" );
678
 
679
    #
680
    #   Create a soft link
681
    #
682
    symlink ($vpath, $VIEWDIR) || Error ("Cannot create VIEWDIR link: $vpath, $VIEWDIR, $!");
683
    Message ("ViewDir : $VIEWDIR" );
684
}
685
 
686
#-------------------------------------------------------------------------------
687
# Function        : create_config_spec
688
#
689
# Description     : Creates a config spec
690
#
691
# Inputs          : $config     - Path to the config file
692
#
693
# Returns         : Path to the config spec
694
#
695
sub create_config_spec
696
{
697
    my ($config_file) = @_;
698
 
699
    #
700
    #   Calc the path to a directory in the view which we really want to
701
    #   consider as the base. Only want to see folders above this base.
702
    #   Don't want to add elements above the base
703
    #
704
    my $basepath = ($opt_path) ? "\"${VOB_PREFIX}${opt_path}\""     : $ROOT_VOB;
705
    my $elroot   = ($opt_path) ? "\"${VOB_PREFIX}${opt_path}/...\"" : '*';
706
    my $elpath   = ($opt_path) ? $opt_path : '';
707
 
708
    #
709
    #   Create a config spec to be used to populate the view
710
    #       Do not branch directories
711
    #       Do not extract files from lost+found
712
    #
713
    Verbose( "Create config spec");
714
    my @config;
715
    push @config, "element * CHECKEDOUT";
716
    push @config, "element .../lost+found -none";
717
 
718
    #
719
    #   Insert rules to prevent branching above the load path
720
    #   This will be the root of the package
721
    #
722
    if ( $opt_path )
723
    {
724
        my $fulldir = $VOB_PREFIX;
725
        my @parts = split ('/', $opt_path);
726
        shift @parts;                                   # Skip first as its empty
727
        pop @parts;                                     # Skip last as its the package
728
        foreach my $dir ( @parts )
729
        {
730
            $fulldir .= "/$dir";
731
            foreach (@opt_spec)
732
            {
733
                push @config, "element -dir \"$fulldir\" $_ -nocheckout";
734
            }
735
        }
736
    }
737
    else
738
    {
739
        foreach (@opt_spec)
740
        {
741
            push @config, "element -dir \"$ROOT_VOB\" $_ -nocheckout";
742
        }
743
    }
744
 
745
    #
746
    #   General branching rules
747
    #   Rule will apply to all following directives
748
    #
749
    if ( $opt_branch )
750
    {
751
        push @config, "element $elroot .../$opt_branch/LATEST";
752
        push @config, "mkbranch $opt_branch";
753
    }
754
 
755
    #
756
    #   Rules to extract elements within the load path
757
    #
758
    foreach (@opt_spec)
759
    {
760
        push @config, "element $elroot $_";
761
    }
762
 
763
    #
764
    #   KLUDGE ALERT
765
    #   Packages SHOULD be labled to the root.
766
    #   Do not extend this list fix the package - fix the labels in the VOB.
767
    #
768
    if ( $opt_latest_root )
769
    {
770
        push @config, "element -dir $ROOT_VOB .../$opt_latest_root/LATEST";
771
        push @config, "element -dir $ROOT_VOB .../mass_dev2/LATEST";
772
        push @config, "element -dir $ROOT_VOB .../mass_dev/LATEST";
773
        push @config, "element -dir $ROOT_VOB /main/LATEST";
774
    }
775
 
776
    #
777
    #   Handle file(directory) addition
778
    #   Need a rule to allow /main/0 to be visible
779
    #   Need to ensure that we don't "see" the entire VOB, just below the load path
780
    #
781
    unless ($GBE_ABT)
782
    {
783
        #
784
        #   Ensure that we have more than just the VOB root
785
        #   If we only have the VOB root then we will get all top level entries
786
        #   in the vob - and this is not good.
787
        #
788
        #   Comment out the rule so that the user can use if they must
789
        #
790
        my $count = ($elpath =~ tr~/~~);
791
        my $prefix = ( $count <= 1 ) ? '# ' : '';
792
        Verbose2 ("Config Spec: Suppress /main/0. Path too short)") if $prefix;
793
        #
794
        #   Ensure that element-0 is visible (unless autobuilder)
795
        #   Note: mkbranch rule will modify this rule
796
        #
797
        push @config, $prefix . "element $elroot /main/0";
798
    }
799
 
800
    #
801
    #   Load rule
802
    #   Quote the path so that spaces will be correcly handled
803
    #
804
    push @config, "load $basepath";
805
 
806
    Message ("Config Spec", @config )
807
        if ( IsVerbose(1) );
808
 
809
    FileCreate ($config_file, \@config);
810
    return $config_file;
811
}
812
 
813
#-------------------------------------------------------------------------------
814
#   Documentation
815
#
816
 
817
=pod
818
 
819
=for htmltoc    GENERAL::ClearCase::
820
 
821
=head1 NAME
822
 
823
jats_ccrelease - Build a package given a clearcase label
824
 
825
=head1 SYNOPSIS
826
 
827
  jats ccrelease [options] [-label=]label | -config=config_spec
828
 
829
 Options:
830
    -help              - brief help message
831
    -help -help        - Detailed help message
832
    -man               - Full documentation
833
    -label=xxx         - Clearcase label
834
    -spec=xxx          - Same as -label=xxx
835
    -path=xxx          - Source Path
836
    -view=xxx          - Modify the name of the created view
837
    -vob=vobname       - VOB name
838
    -build=xxx         - Package Name to build
839
    -root=xxx          - Root directory for generated view
840
    -latestroot=xxx    - Use the LATEST rootlevel directory 'xxx'
841
    -[mk]branch=xxx    - Will create a view with a branch rule
842
    -config=xxx        - Create a view with the provided config spec
843
    -tag=xxx           - Alternate tag used with in the ViewTag
844
    -extract           - Extract the view and exit
845
    -extractfiles      - Extract files, without a view
846
    -cache             - Refresh local dpkg_archive cache
847
    -delete            - Remove any existing view and exit
848
    -debugOnly         - Make only the debug version
849
    -prodOnly          - Make only the production version
850
    -[no]dpkg          - Transfer package into dpkg_archive
851
    -[no]copy          - Transfer pkg directory to the current user directory
852
    -[no]reuse         - Reuse the view
853
    -[no]test          - Test package build. Implies nocopy and nodpkg
854
    -[no]keep          - Keep the view after the build
855
    -[no]lock          - Lock labels
856
    -[no]beta          - Release a beta package
857
    -[no]merge         - Merge packages into dpkg_archive
858
    -[no]runtests      - Run units tests. Default is runtests
859
    -[no]prefix        - Supress user prefix in view name. Default prefix is USER
860
 
861
=head1 OPTIONS
862
 
863
=over 8
864
 
865
=item B<-help>
866
 
867
Print a brief help message and exits.
868
 
869
=item B<-help -help>
870
 
871
Print a detailed help message with an explanation for each option.
872
 
873
=item B<-man>
874
 
875
Prints the manual page and exits.
876
 
877
=item B<-label> or B<-spec>
878
 
879
The ClearCase label to use as the base for the view.
880
 
881
Eg: daf_utils_math_3.2.1
882
 
883
=item B<-view name>
884
 
885
Specified an alternate view name and tag to be used. This option does not provide the
886
full name of the view.
887
 
888
The view tag will be : "${USER}_${MACHINENAME}_${TAG}_${NAME}"
889
 
890
The view path will be: "${USER}_${NAME}"
891
 
892
The default "NAME" is the first label specified.
893
The default "TAG" is build. See B<-tag=tagname>.
894
 
895
If the user provides a view "name" that is prefixed with their user name
896
('${USER}_'), then the username will be stripped of for internal processing.
897
This allows a user to provide a view path when deleting a view.
898
 
899
=item B<-path=xxx>
900
 
901
Specifies the source path to the root of the extracted file tree. This option has several uses:
902
 
903
=over 8
904
 
905
=item   *
906
 
907
Provide a sanity test of the "Source Path" item within Release Manager
908
 
909
=item   *
910
 
911
Specify the VOB that contains the source. The VOB name will be extracted and
912
used as the B<-vob> parameter.
913
 
914
=item   *
915
 
916
Limit the work to do in extracting the file tree.
917
 
918
=back
919
 
920
=item B<-vob=xxx>
921
 
922
Specifies the Clearcase VOB in which the clearcase label will be located.
923
This is used as the basis for locating and loading the files within the view.
924
 
925
By default this utility will examine all the VOBs for the label.
926
 
927
=item B<-build=xxx>
928
 
929
This option allows the user to specify the packages to be built and the
930
order in which the packages are to be built.
931
This is useful if the extracted view contains multiple build files
932
 
933
This option may be used multiple times.
934
 
935
There are two forms in which the build target can be specified. It can be
936
specified as a full package name and vesrion, or as a package name and the
937
project suffix.
938
 
939
By default the program will assume that there is only one build file in the
940
view and will not build if multiple files are present, unless the package to be
941
built can be resolved.
942
 
943
The location mechanism operates for both JATS and ANT build files.
944
 
945
Example: -build=jats-api.1.0.0000.cr
946
 
947
This will locate the build file that builds version 1.0.0000.cr of the jats-api
948
package. The version numbers must match exactly.
949
 
950
Example: -build=jats-api.cr -build=jats-lib.cr
951
 
952
This will located the build files that build the jats_api (cr) package and the
953
jats-lib (cr) package. The version of the packages will not be considered.
954
 
955
=item B<-root=xxx>
956
 
957
This option allows the location of the generated view to be specified on the
958
command line. It overides the value of GBE_VIEWBASE.
959
 
960
If the comamnd is invoked within a development sandbox, then the default
961
location will be the root directory of the development sandbox.
962
 
963
=item B<-latestroot=xxx>
964
 
965
This option enables a work around for a bad-labelling practice that has existed
966
in the past. This LATEST version of the named (xxx) branch will be added to
967
the config spec used to create the view.
968
 
969
This is a work around for a problem where the top-level directory in the VOB has
970
not been labelled. This can result in unreproducible builds.
971
 
972
This option allows the utility to construct a view, but the user SHOULD label
973
the root level directory to correct the problem.
974
 
975
The use of this switch will add the following lines to the config spec:
976
 
977
    element -directory /DPG_SWBase /main/xxxx/LATEST
978
 
979
=item B<-branch=xxx or -mkbranch=xxx>
980
 
981
This option will create a view such that files that are checked out will be
982
checked out on the named branch. This is intended to facilitate the maintenance
983
of existing packages - the creation of a patch.
984
 
985
The named branch must exist within the VOB containing the label. The script will
986
check for its existence.
987
 
988
The use of this switch will add the following lines to the config spec:
989
 
990
    element * .../xxx/LATEST
991
    element * label -mkbranch xxx
992
    element * /main/0 -mkbranch xxx
993
 
994
=item B<-config=config_spec>
995
 
996
This option is an alternate mechanism to create a static view. The view will be
997
based on the provided configuration spec. This view cannot be used to release a package.
998
The option is intended to simplify development.
999
 
1000
This option is incompatibale with:
1001
 
1002
    -release
1003
    -label
1004
    -branch
1005
    -path
1006
    -vob
1007
 
1008
=item B<-tag=text>
1009
 
1010
This option alters the ClearCase view tag created for the view. It allows
1011
the creation of multiple views based on the same label. Intended to be used in
1012
the automated build system to create unique views tags.
1013
 
1014
The default tag is 'build'.
1015
 
1016
=item B<-extract>
1017
 
1018
With this option the view is created and the left in place. The user may then
1019
access the files within the view. The view should not be used for a
1020
production release.
1021
 
1022
=item B<-extractfiles>
1023
 
1024
With this option the utility will create a dynamic view and transfer files from
1025
the view to the user's tararget. The dynamic view is then removed.
1026
 
1027
This command is intended to simplify the process of creating an escrow.
1028
 
1029
=item B<-cache>
1030
 
1031
Forces external packages to be placed in the local dpkg_archive cache.
1032
 
1033
The normal operation is to copy the packages, only if they do not already exist
1034
in the local cache. This option may be used to ensure that the local copy is
1035
correct and up to date.
1036
 
1037
=item B<-delete>
1038
 
1039
Delete the view used by the program, if it exists. This option may be used to
1040
cleanup after an error.
1041
 
1042
Note: Ensure that no files are open in the view and that the users current
1043
working directory is not in the view as these will prevent the view from being
1044
deleted.
1045
 
1046
=item B<-debugOnly>
1047
 
1048
Make only the debug version of the package. The default it to create both the
1049
debug and production version of the package. The type of build may be  further
1050
limited by options within the package.
1051
 
1052
=item B<-prodOnly>
1053
 
1054
Make only the production version of the package. The default it to create both the
1055
debug and production version of the package. The type of build may be  further
1056
limited by options within the package.
1057
 
1058
=item B<-[no]dpkg>
1059
 
1060
Copy the generated package into dpkg_archive. This is the default mode of
1061
operation.
1062
 
1063
=item B<-[no]copy>
1064
 
1065
Copy the built "pkg" directory to the users current directory. The entire
1066
"pkg" subdirectory includes the full package named directory for the package
1067
that has been built.
1068
 
1069
=item B<-[no]reuse>
1070
 
1071
This flag allows the view created by the program to be re-used.
1072
 
1073
=over 8
1074
 
1075
=item *
1076
 
1077
The view is not deleted before being populated.
1078
 
1079
=item *
1080
 
1081
The view will not be populated if it does exist.
1082
 
1083
=item *
1084
 
1085
The view will not be deleted at the end the process.
1086
 
1087
=back
1088
 
1089
This option is useful for debugging a build process.
1090
 
1091
=item B<-[no]test>
1092
 
1093
Test the building of the package. This option implies "nocopy" and "nodpkg".
1094
 
1095
=item B<-[no]keep>
1096
 
1097
Keep the clearcase view after the build. The default option is "nokeep"
1098
 
1099
This option is different to the "reuse" in that the view will be deleted, if
1100
it exists, before the build, but will be retained at the completion of the
1101
process. The user may then manually extract the created package.
1102
 
1103
The view may be deleted with the the "delete" option; taking care to ensure that
1104
no files are open in the view and that the users current working directory is
1105
not in the view.
1106
 
1107
=item B<-[no]lock>
1108
 
1109
Lock any unlocked labels before attempting the build. This operation may be used
1110
to ensure that a release build does not fail due to the labels not being locked.
1111
The label is locked before the view is constructed and populated.
1112
 
1113
This operation may fail if the user does not "own" the label.
1114
 
1115
=item B<-[no]beta>
1116
 
1117
This option overrides many of the package release tests to allow a beta package
1118
to be released.
1119
 
1120
=item B<-[no]merge>
1121
 
1122
This option will merge packages being built on multiple machines into
1123
dpkg_archive. By default, if a package already exists in the archive it will be
1124
deleted and replaced. With this option the package will be merged. The merge
1125
process does not over write files found in the archive.
1126
 
1127
=item B<-[no]runtests>
1128
 
1129
This option will allow the suppression of the running of the unit tests included
1130
with the component. By default the tests are run. This can be suppressed
1131
without affecting the release process.
1132
 
1133
=back
1134
 
1135
=head1 DESCRIPTION
1136
 
1137
This program is the primary tool for the creation, recreation and release of
5710 dpurdie 1138
packages within the B<VIX> build environment, although the program can perform a
392 dpurdie 1139
number of very useful operations required during normal development and
1140
maintenance.
1141
 
1142
This program will build a system containing one or more inter-related build
1143
files using the JATS build tools.
1144
 
1145
In normal operation the program will:
1146
 
1147
=over 8
1148
 
1149
=item Remove View
1150
 
1151
Remove any existing view of the same name. The view will not be removed if it
1152
contains checked-out files.
1153
 
1154
The view removal may fail if there are any files B<open> within the view or if
1155
any shell has a subdirectory of the view set as a B<current working directory>.
1156
 
1157
=item Locate VOB
1158
 
1159
Locate the VOB that contains the specified label or labels. If multiple labels
1160
are specified they must all exist in the same VOB.
1161
 
1162
=item Lock Labels
1163
 
1164
Lock any unlocked labels, if required.
1165
 
1166
=item Create the view
1167
 
1168
Create a static view to containing the files describes by the Clearcase
1169
label being processed.
1170
 
1171
The program uses a fixed view name. If this view exists then item
1172
will be deleted before item is created again. Each build starts in a clean view.
1173
 
1174
=item Populate the View
1175
 
1176
Loads files into the static view. The user label and the VOB name are used to
1177
created a clearcase configuration specification. This configuration
1178
specification is then activated and all files within the specified VOB will be
1179
loaded into the view if they match the user supplied label.
1180
 
1181
This processed normally results in a lot of error messages that can be ignored.
1182
 
1183
I<Note:> The label placed on the component to be built must extend to the
1184
root of the VOB, otherwise the directory path will not be extracted nor will
1185
the files within the component.
1186
 
1187
I<Note:> If the view is simply being extracted, then this is the end of the
1188
program. The extracted view is left in place.
1189
 
1190
=item Sanity Test
1191
 
1192
If the build is being used as a release into dpkg_archive then
1193
various tests are performed to ensure the repeatability of the view and the
1194
build. These tests include:
1195
 
1196
=over 8
1197
 
1198
=item   *
1199
 
1200
The view must be constructed from one label
1201
 
1202
=item   *
1203
 
1204
That label must be locked
1205
 
1206
=item   *
1207
 
1208
The labelled view must contain exactly one build file
1209
 
1210
=item   *
1211
 
1212
The view cannot have been re-used.
1213
 
1214
=back
1215
 
1216
=item Locate build files
1217
 
1218
Locate the build file within the view.
1219
 
1220
It is an error to have multiple build files within the view, unless the
1221
B<-build> option is used. By default, only one package will be built.
1222
 
1223
=item Package the results
1224
 
1225
Use JATS to build and make the package.
1226
 
1227
The resultant package may be copied to a numbers of locations. These include
1228
 
1229
=over 8
1230
 
1231
=item 1
1232
 
1233
The master dpkg_archive as an official release. This is the default operation.
1234
 
1235
=item 2
1236
 
1237
The users current directory. The package directory from the built package is
1238
copied locally. The "pkg" directory is copied. This is only performed with the
1239
B<-copy> option.
1240
 
1241
=back
1242
 
1243
=item Delete the view
1244
 
1245
Delete the view and all related files.
1246
 
1247
The view will not be deleted if an error was detected in the build process, or
1248
the "reuse" or "keep" options are present.
1249
 
1250
=back
1251
 
1252
=cut
1253