Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
263 dpurdie 1
########################################################################
2
# Copyright (C) 2008 ERG Limited, All rights reserved
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
 
22
require 5.008_002;
23
use strict;
24
use warnings;
25
use JatsError;
26
use JatsSystem;
27
use FileUtils;
28
use JatsBuildFiles;
29
use ArrayHashUtils;
30
 
31
use Pod::Usage;                             # required for help support
32
use Getopt::Long;
33
use File::Find;
34
use File::Copy;
35
use File::Path;
36
use Cwd;
37
 
38
my $VERSION = "1.6.0";                      # Update this
39
 
40
#
41
#   Options
42
#
43
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
44
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
45
my $opt_help = 0;                           # User help level
46
my @opt_spec;                               # Labels used as a base for the view
47
my $opt_vob;                                # Hint: which VOB to use
48
my $opt_dpkg = 1;                           # Transfer built package to dpkg_archive
49
my $opt_copy = 0;                           # Copy built package to user
50
my $opt_reuse = 0;                          # Re-user view if it exists
51
my $opt_viewname;                           # View Name
52
my $opt_extract;                            # Just create a static view
53
my $opt_extract_files;                      # Just extract files to user - no view
54
my $opt_delete;                             # Just delete the view
55
my @opt_build;                              # build files to use (kludge)
56
my $opt_test;                               # Test the build process - no copy
57
my $opt_cache;                              # Cache external packages
58
my $opt_keep = 0;                           # Keep view if successful
59
my $opt_lock = 0;                           # Lock label before release
60
my $opt_beta;                               # Create beta release
61
my $opt_merge;                              # Merge release
62
my $opt_path;                               # Path for view spec
63
my $opt_runtests = 1;                       # Run unit tests after build
64
my $opt_latest_root;                        # Modify config spec with rule (kludge)
65
my $opt_branch;                             # Create config spec with branch
66
my $opt_debug_build = 0;                    # Build Debug Only
67
my $opt_prod_build = 0;                     # Build ion Only
68
my $opt_view_root = $ENV{'GBE_VIEWBASE'};   # Root of the view
69
my $opt_config_spec;                        # User provided config spec
70
my $opt_prefix = 1;                         # Prefix the view tag with user-name
71
my $opt_tag;                                # View tag insert (build or export or user)
72
 
73
#
74
#   Globals - Provided by the JATS environment
75
#
76
my $USER            = $ENV{'USER'};
77
my $UNIX            = $ENV{'GBE_UNIX'};
78
my $HOME            = $ENV{'HOME'};
79
my $GBE_SANDBOX     = $ENV{'GBE_SANDBOX'};
80
my $GBE_ABT         = $ENV{'GBE_ABT'} || '0';
279 dpurdie 81
my $MACHINENAME     = $ENV{'GBE_HOSTNAME'};
263 dpurdie 82
 
83
#
84
#   Globals
85
#
86
my $VIEWDIR_ROOT = "c:/clearcase";          # Root of all static views (WIN32)
87
my $VIEWTAG;                                # The view tag
88
my $VIEWDIR;                                # Absolute path to the view
89
my $VIEWPATH;                               # Path relative to clearcase
90
my $user_cwd;
91
my $error = 0;
92
my $label_count = 0;                        # Number of labels to create the view
93
my @label_not_locked;                       # List of unlocked labels
94
my @label_locked;                           # List of labels I locked
95
my @error_list;                             # ClearCmd detected errors
96
 
97
my $UNIX_VOB_PREFIX = '/vobs';
98
my $VOB_PREFIX = $UNIX ? $UNIX_VOB_PREFIX : '';
99
 
100
my $UNIX_VIEW_PREFIX = '/view/';            # Don't know how to determine this value
101
my $WIN32_VIEW_PREFIX = 'o:/';              # Don't know how to determine this value
102
my $VIEW_PREFIX = $UNIX ? $UNIX_VIEW_PREFIX : $WIN32_VIEW_PREFIX ;
103
 
104
my $UNIX_VP_ROOT    = 'jats_cbuilder';
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
#   Alter some option defaults if we are creating a view within a sandbox
130
#
131
if ( $GBE_SANDBOX )
132
{
133
   $opt_view_root = $GBE_SANDBOX;
134
   $opt_prefix = 0;
135
}
136
 
137
#
138
#   Parse the user options
139
#
140
my $result = GetOptions (
141
                "help+"         => \$opt_help,              # flag, multiple use allowed
142
                "manual:3"      => \$opt_help,              # flag
143
                "v|verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
144
                "label=s"       => \@opt_spec,              # Array of build specs
145
                "spec=s"        => \@opt_spec,              # Array of build specs
146
                "config=s"      => \$opt_config_spec,       # String
147
                "view=s"        => \$opt_viewname,          # String
148
                "vob=s"         => \$opt_vob,               # String
149
                "dpkg!"         => \$opt_dpkg,              # [no]flag
150
                "copy!"         => \$opt_copy,              # [no]flag
151
                "reuse!"        => \$opt_reuse,             # [no]flag
152
                "extract"       => \$opt_extract,           # flag
153
                "extractfiles"  => \$opt_extract_files,     # flag
154
                "delete"        => \$opt_delete,            # flag
155
                "build=s"       => \@opt_build,             # An array of build
156
                "test!"         => \$opt_test,              # [no]flag
157
                "cache"         => \$opt_cache,             # flag
158
                "keep!"         => \$opt_keep,              # [no]flag
159
                "lock!"         => \$opt_lock,              # [no]flag
160
                "beta!"         => \$opt_beta,              # [no]flag
161
                "merge"         => \$opt_merge,             # [no]flag
162
                "path=s"        => \$opt_path,              # string
163
                "runtests!"     => \$opt_runtests,          # [no]flag
164
                "latestroot=s"  => \$opt_latest_root,       # String
165
                "branch=s"      => \$opt_branch,            # String
166
                "mkbranch=s"    => \$opt_branch,            # String
167
                "prodOnly"      => \$opt_prod_build,        # flag
168
                "debugOnly"     => \$opt_debug_build,       # flag
169
                "root=s"        => \$opt_view_root,         # string
170
                "prefix!"       => \$opt_prefix,            # flag
171
                "tag=s"         => \$opt_tag,               # string
172
                );
173
 
174
                #
175
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
176
                #
177
 
178
#
179
#   Process help and manual options
180
#
181
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
182
pod2usage(-verbose => 1)  if ($opt_help == 2 );
183
pod2usage(-verbose => 2)  if ($opt_help > 2 );
184
 
185
InitFileUtils();
186
 
187
#
188
#   Configure the error reporting process now that we have the user options
189
#
190
ErrorConfig( 'name'    => 'RELEASE',
191
             'verbose' => $opt_verbose );
192
 
193
#
194
#   Validate user options
195
#   Use either -label or one command line argument
196
#
197
Error ("Unexpected command line arguments present.","Cannot mix -label and command line label" )
198
    if ( $#opt_spec >= 0 && $#ARGV >= 0);
199
 
200
push @opt_spec, @ARGV;
201
 
202
if ( $opt_config_spec )
203
{
204
    Error("Cannot use -path with -config")      if($opt_path);
205
    Error("Cannot use -branch with -config")    if($opt_branch);
206
    Error("Cannot use -vob with -config")       if($opt_vob);
207
    Error("Cannot use a label with -config")    if( @opt_spec);
208
    Error("Config spec file not found: $opt_config_spec") unless ( -f $opt_config_spec );
209
 
210
    unless ( $opt_viewname )
211
    {
212
        $opt_viewname = StripDirExt($opt_config_spec);
213
        $opt_viewname =~ s~[\.:/\\]~_~g;
214
    }
215
 
216
    $opt_vob = "";
217
 
218
    #
219
    #   Convert file in an absolute file name
220
    #   Will be needed as we change directory
221
    #
222
    $opt_config_spec = FullPath($opt_config_spec);
223
}
224
 
225
unless(  @opt_spec || $opt_config_spec  )
226
{
227
    Error ("Need a view or a label. -help for options") if ( $opt_delete  && ! $opt_viewname );
228
    Error ("Need a label or config_spec. -help for options") unless $opt_delete;
229
}
230
 
231
#
232
#   Convert label with embedded VCS information into a 'normal' form.
233
#   Form:
234
#       CC::label
235
#       CC::path::label
236
#       CC::::label
237
#
238
foreach ( @opt_spec )
239
{
240
    if ( $_ =~ m~^(.+?)::(.*?)(::(.+))?$~ )
241
    {
242
        Error ("Label contains invalid Version Control Identifier($1): $_")
243
            if ( $1 ne 'CC' );
244
 
245
        my $ll = $2;
246
        my $path;
247
        if ( $3 )
248
        {
249
            $path = $2;
250
            $ll = $4;
251
            if ( $path  )
252
            {
253
                Error ("Multiple conflicting Embedded source paths",
254
                       "Path: $opt_path",
255
                     "VCS Spec: $_" ) if ( $opt_path && $path ne $opt_path );
256
                $opt_path = $path;
257
            }
258
        }
259
        $_ = $ll;
260
    }
261
    Verbose ("Clean URL: $_");
262
}
263
 
264
#
265
#   User has specified both debug and production
266
#   Then set both to 0 : ie default
267
#
268
if ( $opt_debug_build + $opt_prod_build > 1 )
269
{
270
    $opt_debug_build = 0;
271
    $opt_prod_build = 0;
272
}
273
 
274
#
275
#   User has requested test mode
276
#       - Don't copy
277
#       - Don't packgae
278
#
279
if ( $opt_test )
280
{
281
    $opt_dpkg = 0;
282
    $opt_copy = 0;
283
}
284
 
285
#
286
#   Determine the machine type
287
#
288
Verbose ("Machine Type: UNIX=$UNIX");
289
 
290
Error ("Machine Name not determined")
291
    unless ( $MACHINENAME );
292
$user_cwd = getcwd;
293
 
294
Error ("USER name not determined" )
295
    unless ( $USER );
296
 
297
#
298
#   Ensure that the 'cleartool' program can be located
299
#
300
Verbose ("Locate clearcase utility in users path");
301
Error ("Cannot locate the 'cleartool' utility in the users PATH")
302
    unless ( LocateProgInPath('cleartool', '--All') );
303
 
304
 
305
#
306
#   Under UNIX, create views in the user home directory
307
#
308
unless ( $opt_view_root  )
309
{
310
    if ( $UNIX )
311
    {
312
        Error ("Unix HOME EnvVar not defined" ) unless ( $HOME );
313
        Error ("Unix HOME directory not found: $HOME" ) unless (-d $HOME );
314
        $VIEWDIR_ROOT = "$HOME/$UNIX_VP_ROOT";
315
        Verbose ("Unix viewpath: $VIEWDIR_ROOT");
316
        mkdir ( $VIEWDIR_ROOT ) unless (-d $VIEWDIR_ROOT);
317
    }
318
}
319
else
320
{
321
    $opt_view_root = Realpath($opt_view_root) || $opt_view_root;
322
    $VIEWDIR_ROOT = $opt_view_root;
323
}
324
 
325
Verbose ("Viewpath: $VIEWDIR_ROOT");
326
Error ("Cannot locate view root directory: $VIEWDIR_ROOT" ) unless (-d $VIEWDIR_ROOT);
327
 
328
#
329
#   Remove any user name from the front of the view name
330
#   Simplifies the deletion process as the user can provide
331
#   the directory name
332
#
333
$view_prefix = "" unless ( $opt_prefix );
334
 
335
#
336
#   Setup user specified viewname
337
#   Include the user name to ensure that the view name is unique-ish
338
#   Keep the name as short as possible as some compilers display a fixed
339
#   length filename in error messages and this name is part of the path
340
#
341
#   Base the viewname on the view label. This will simplify the creation
342
#   of multiple views and reduce the risk of unexpected deletion
343
#
344
$opt_viewname = $opt_spec[0] unless ( defined $opt_viewname );
345
$opt_viewname =~ s~^$view_prefix~~ if (defined($opt_viewname) && $view_prefix && $opt_delete );
346
 
347
#
348
#   Create the view tag
349
#   Attempt to make this globally unique
350
#   Include USER name, MACHINE name, the view name
351
#   Optionally include a user 'tag'. Provided to allow the ABT to maintain
352
#   multiple instances of a view.
353
#
354
unless ( $opt_tag )
355
{
356
    $opt_tag = $opt_extract_files ? 'extract' : 'build';
357
}
358
$VIEWTAG = "${USER}_${MACHINENAME}_${opt_tag}_${opt_viewname}";
359
 
360
#
361
#   Create a clearcase view to be used for the view
362
#
363
$VIEWPATH = "$view_prefix$opt_viewname";
364
$VIEWDIR = "$VIEWDIR_ROOT/$VIEWPATH";
299 dpurdie 365
$VIEWDIR =~ tr~\\/~/~s;
263 dpurdie 366
Verbose( "Hostname: $MACHINENAME" );
367
Verbose( "Viewtag: $VIEWTAG" );
368
Verbose( "Viewpath: $VIEWPATH" );
369
Verbose( "Viewdir : $VIEWDIR" );
370
 
371
#
372
#   If the user has specified a "source path", then we can extract the VOB
373
#   from that path. It will be the first directory
374
#
375
Verbose("Locate Source VOB");
376
if ( $opt_path )
377
{
378
    $opt_path =~ tr~\\/~/~s;
379
    $opt_path =~ s~/+$~~;
380
 
381
    Error( "Source Path needs leading '/'") unless ( $opt_path =~ m~^/~ );
382
    Error( "Source Path is a UNC" ) if ( $opt_path =~ m~^//~ );
383
    Error( "Source Path has drive specifier" ) if ( $opt_path =~ m~^[A-Za-z]\:~ );
384
 
385
    #
386
    #   Extract the VOB from the path
387
    #
388
    unless ( $opt_vob )
389
    {
390
        my $vob = $opt_path;
391
        $vob =~ s~^/~~g;
392
        $vob =~ s~/.*~~g;
393
 
394
        $opt_vob = $vob;
395
        Verbose ("Extract VOB from path: $vob" );
396
    }
397
}
398
 
399
 
400
#
401
#   If the view currently exists then it will be deleted if allowed
402
#
403
delete_view()
299 dpurdie 404
    unless ( $opt_reuse );
263 dpurdie 405
 
299 dpurdie 406
 
263 dpurdie 407
#
408
#   If the user is simply deleting the view then all has been done
409
#
410
exit 0
411
    if ( $opt_delete );
412
 
413
#
414
#   Setup user specified VOB
415
#
416
if ( defined($opt_vob) )
417
{
418
    $ROOT_VOB = "/$opt_vob";
419
    $ROOT_VOB =~ s~//~/~g;
420
    @ROOT_VOBS = $ROOT_VOB;
421
}
422
else
423
{
424
    #
425
    #   Extend the list of ROOT_VOBS with all the known vobs
426
    #   The initial ROOT_VOBS are treated as a "hint" to assist searching
427
    #
428
        my $cmd = ClearToolCmd ('lsvob', '-short');
429
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
430
        while (<CMD>)
431
        {
432
            #
433
            #   Filter output from the user
434
            #
435
            chomp;
436
            s~^$UNIX_VOB_PREFIX~~ if ($UNIX);
437
            Verbose2("lsvob: $_");
438
            tr~\\/~/~s;
439
            push @ROOT_VOBS, $_;
440
        }
441
        close(CMD);
442
}
443
 
444
#
445
#   Ensure that the label is present within the specified VOB
446
#   Hunt for the user specified label in a number of well known VOBs
447
#
448
if ( @opt_spec )
449
{
450
    Verbose("Ensure Label is found in a VOB");
451
    my $found = 0;
452
    my $spec = $opt_spec[0];
453
    foreach my $vob ( @ROOT_VOBS )
454
    {
455
        $vob = $UNIX_VOB_PREFIX . $vob if ( $UNIX );
456
        (my $vob_name = $vob) =~ s~/~$VOB_SEP~g;
457
 
458
        Verbose2 ("Examine label $spec in vob: $vob" );
459
 
460
        my $cmd = ClearToolCmd ('lstype', "lbtype:$spec\@$vob_name");
461
        my $cmd_done = 0;
462
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
463
        while (<CMD>)
464
        {
465
            #
466
            #   Filter output from the user
467
            #   Stay in loop to avoid Broken Pipe message
468
            #
469
            chomp;
470
            Verbose2("lstype: $_");
471
            next if ( $cmd_done );
472
            next if ( m~Error~ );
473
            next unless ( m~label type~ );
474
            push @label_not_locked, $spec unless( m~\(locked\)~ );
475
            $label_count++;
476
            $found = $vob;
477
            $cmd_done = 1;
478
        }
479
        close(CMD);
480
        last if ( $found );
481
    }
482
 
483
    Error ("Label $spec not found in @ROOT_VOBS")
484
        unless ( $found );
485
    Verbose ("Label $spec found in vob: $found" );
486
 
487
    $ROOT_VOB = $found;
488
 
489
    #
490
    #   Create a VOB spec extension
491
    #
492
    $root_vob_spec = '@' . $ROOT_VOB;
493
    $root_vob_spec =~ s~/~$VOB_SEP~g;
494
 
495
    #
496
    #   Ensure that all labels are found in the VOB
497
    #
498
    foreach my $spec ( @opt_spec[1..$#opt_spec] )
499
    {
500
        $label_count++;
501
        Verbose ("Testing label $spec in vob: $ROOT_VOB" );
502
        my $data = qx( cleartool lstype lbtype:$spec$root_vob_spec );
503
        Verbose ( "lstype: $data" );
504
        Error ("Label $spec not found in $ROOT_VOB. All labels must be in the same VOB")
505
            if ( ! $data );
506
        push @label_not_locked, $spec unless( $data =~ m~\(locked\)~ );
507
    }
508
 
509
    #
510
    #   Ensure that the branch is found in the VOB
511
    #
512
    if ( $opt_branch )
513
    {
514
            Verbose ("Testing branch $opt_branch in vob: $ROOT_VOB" );
515
            my $data = qx( cleartool lstype brtype:$opt_branch$root_vob_spec );
516
            Verbose ( "lstype: $data" );
517
            Error ("Branch $opt_branch not found in $ROOT_VOB.")
518
                if ( ! $data );
519
    }
520
 
521
    #
522
    #   Lock the label(s)
523
    #
524
    if ( $opt_lock )
525
    {
526
        my @still_not_locked;
527
        Message( "Locking labels" );
528
        foreach my $spec ( @label_not_locked )
529
        {
530
            Verbose ("Locking $spec");
531
            push @label_locked, $spec;
532
            ClearCmd ('lock', "lbtype:$spec$root_vob_spec" );
533
            push @still_not_locked, $spec if ( @error_list );
534
        }
535
        @label_not_locked = @still_not_locked;
536
 
537
        #
538
        #   Register function to unlock all the locked lables on failure
539
        #
540
        ErrorConfig ('on_exit' => \&unlock_on_error );
541
        Error ("Not all labels locked: @label_not_locked") if ( @label_not_locked  );
542
    }
543
}
544
 
545
#
546
#   If we are only extracting files then ...
547
#
548
if ( $opt_extract_files )
549
{
550
    extract_files_from_view();
551
    exit (0);
552
}
553
 
554
#
555
#   Create a new (static) view
556
#   Create a config spec and populate the view
557
#
558
if (! -d $VIEWDIR || ! $opt_reuse )
559
{
560
    Message( "Create the view" . ($GBE_SANDBOX ? " in a SANDBOX" : ""));
561
 
562
    #
563
    #   Tried creating a co-located view under Windows, but had problems
564
    #       1) Did not work on WindowsServer based build machine ??
565
    #       2) Deleting the view could be a problem if the user had
566
    #          files open in the view.
567
    #       3) Documentation doesn't really like the use of -colocated
568
    #
569
    #
570
    foreach my $view_count ( 1 .. 5 )
571
    {
572
        my $cc_race_condition;
573
        my $cmd = ClearToolCmd ('mkview', '-snapshot', '-tag', $VIEWTAG, $VIEWDIR);
574
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
575
        while (<CMD>)
576
        {
577
            #
578
            #   Filter output from the user
579
            #
580
            chomp;
581
            tr~\\/~/~s;
582
            Verbose2("mkview: $_");
583
 
584
            #
585
            #   Detect Race condition
586
            #   Multiple build daemons creating views too fast for ClearCase
587
            #   ClearCase can hit a race condition and fail to create a view
588
            #
589
            if ( $_ =~ m~Error: Unable to create directory "[^"]+": File exists\.~ )
590
            {
591
                $cc_race_condition = 1;
592
            }
593
        }
594
        close(CMD);
595
 
596
        #
597
        #   Race condition detected
598
        #   Back-off and try again. Will only try a limited number of times
599
        #
600
        if ( $cc_race_condition  )
601
        {
602
            Message ("ClearCase Race condition detected");
603
            sleep ( $view_count );
604
            next;
605
        }
606
        last;
607
    }
608
    Error ("Cannot locate the created static view")
609
        unless ( -d $VIEWDIR );
610
 
611
    #   In order to operate in this view (ie set the config spec, we need to
612
    #   be in the directory of the view
613
    #
614
    chdir ($VIEWDIR) or Error( "Cannot chdir to $VIEWDIR");
615
 
616
    #
617
    #   Create a local package archive
618
    #   May be needed for multipackage builds and it will prevent JATS from
619
    #   finding any outside the view
620
    #
621
    mkdir ( 'local_dpkg_archive')
622
        unless ($GBE_SANDBOX);
623
 
624
    my $config_file = $opt_config_spec;
625
    unless ( $config_file )
626
    {
627
        $config_file = create_config_spec ('config_spec.txt');
628
    }
629
 
630
    Message( "Populating the view");
631
    ClearTool( 'setcs', '-tag', $VIEWTAG, $config_file );
632
}
633
 
269 dpurdie 634
#   Place a tag-file in the user-specified source path
635
#   This will be used by the build-tool to locate the 'source-path' of the
636
#   view, primarily for determining metrics.
263 dpurdie 637
#
269 dpurdie 638
#   Calculate where the dynmaic view will be
639
#   This differ between UNIX/WINDOWS
640
#
285 dpurdie 641
if ( $opt_path && $GBE_ABT)
269 dpurdie 642
{
643
    Message( "Create Build tagfile");
644
    my $cpath = $VIEWDIR . $VOB_PREFIX . $opt_path;
645
    if ( -d $cpath )
646
    {
647
        TouchFile ( "$cpath/.jats.packageroot" );
648
    }
649
}
650
 
651
#
263 dpurdie 652
#   Locate the JATS build files within the populated view
653
#
654
chdir ($VIEWDIR) or Error( "Cannot chdir to $VIEWDIR");
655
Message( "Locating build files");
656
 
657
my $bscanner = BuildFileScanner( "$VIEWDIR$ROOT_VOB", 'build.pl', '--LocateAll' );
658
$bscanner->scan();
659
my @build_list = $bscanner->getInfo();
660
foreach my $be ( @build_list )
661
{
662
    Message( DisplayPath ("Build file: $be->{dir} Name: $be->{file}"));
663
}
664
 
665
#
666
#   If we are extracting the view then we are done
667
#   Display useful information for the user
668
#
669
if ( $opt_extract )
670
{
671
    Message  DisplayPath "View in: $VIEWDIR";
672
    Warning ("No build files found" )   if ( $#build_list < 0 );
673
    Warning( "Multiple build files found" )if ( $#build_list > 0 );
674
    Message ("Not all labels are locked") if ( @label_not_locked  );
675
    Message ("All labels are locked") unless ( @label_not_locked  );
676
    Message ("Development Sandbox") if ( $GBE_SANDBOX );
677
 
678
    exit 0;
679
}
680
 
681
Error ("No build files found")  if ( $#build_list < 0 );
682
 
683
#
684
#   Determine the list of builds to perform
685
#   Ensure that the user-requested build files are present
686
#
687
#   The user specifies the build file, via the mangled package name
688
#   This is package_name . project extension (daf_utils.cr)
689
#
690
if ( $#opt_build  >= 0)
691
{
692
    Verbose( "Check and locate the build files");
693
    @build_list = ();
694
    foreach my $bentry ( @opt_build )
695
    {
696
        if ($bscanner->match( $bentry) )
697
        {
698
            UniquePush (\@build_list, $bscanner->getMatchList() );
699
            Verbose ("Found: $bentry");
700
        }
701
        else
702
        {
703
            Error ("Cannot locate requested build files for: $bentry")
704
        }
705
    }
706
}
707
 
708
#
709
#   Sanity test if we will transfer the generated package to dpkg_archive
710
#   There are some limits
711
#       1) Must have built from one label
712
#       2) That label must be locked
713
#       3) Only one build file
714
#       4) The view must not have been reused
715
#       5) The view has a branch rule
716
#       6) Building from a config spec
717
#       7) Cannot release from a sandbox
718
#
719
my @elist;
720
push @elist, "Package built from multiple labels" unless ( $label_count == 1 || $opt_config_spec );
721
push @elist, "Package built from an unlocked label" if ( @label_not_locked  );
722
push @elist, "Package built with multiple build files" if ( scalar @build_list > 1 );
723
push @elist, "Package from a reused view" if ( $opt_reuse && ! $opt_beta );
724
push @elist, "Package from a development sandbox" if ( $GBE_SANDBOX );
725
push @elist, "View contains a branch" if ( $opt_branch );
726
push @elist, "Package based on a config spec" if ( $opt_config_spec );
727
push @elist, "User has specified build files" if ( $#opt_build > 0 );
728
 
729
if ( @elist )
730
{
731
    Warning ("Cannot officially release the package.", @elist);
732
    Error ("Build terminated as it cannot be released") if ($opt_dpkg && ! $opt_beta);
733
}
734
Warning ("Beta Release") if $opt_beta;
735
 
736
#
737
#   Process each of the build files in the specified order
738
#
739
foreach my $be (@build_list)
740
{
741
 
742
    #
743
    #   We need to change to the build directory
744
    #   Moreover we need the local name of the build directory.
745
    #   Windows does not handle a UNC pathname to well (at all)
746
    #
747
    my $build_dir = $be->{dir};
748
    chdir ("$build_dir") or Error( "Cannot chdir to build directory: $build_dir");
749
 
750
    if ( $be->{file} =~ m/^build.pl$/ )
751
    {
752
        Message ("Using JATS: $build_dir");
753
        #
754
        #   Invoke JATS to build the package and make the package
755
        #
756
        my @build_args = qw(--expert --cache);
757
        push @build_args, '--cache' if $opt_cache;
758
 
759
        my $make_type = 'all';
760
        $make_type = 'all_prod'  if ( $opt_prod_build );
761
        $make_type = 'all_debug' if ( $opt_debug_build );
762
 
763
 
764
        JatsCmd('build', @build_args)               and Error("Package did not build");
765
        JatsCmd('make', $make_type, 'NODEPEND=1')   and Error("Package did not make");
766
        JatsCmd('install');
767
 
768
        if ( $opt_runtests )
769
        {
770
            JatsCmd('make', 'run_unit_tests')      and Error("Tests did not run corectly");
771
        }
772
    }
773
    else
774
    {
775
        #
776
        #   Ant build files
777
        #
778
        my $pname =  $be->{file};
779
        Message ("Using ANT: $build_dir, $pname");
780
        $pname =~ s~depends.xml$~.xml~;
781
        copy($be->{file}, "auto.xml");
782
        JatsCmd('-buildfile', $pname, 'ant', 'build')        and Error("Package did not build");
783
        JatsCmd('-buildfile', $pname, 'ant', 'make_package') and Error("Package did not make_package");
784
    }
785
}
786
 
787
#
788
#   Copy the generated packages
789
#       1) dpkg_archive
790
#       2) Users local directory
791
#
792
foreach my $be (@build_list)
793
{
794
    my $build_dir = $be->{dir};
795
    chdir ("$build_dir") or Error( "Cannot chdir to build directory: $build_dir");
796
    if ( $opt_dpkg )
797
    {
798
        Message ("Using: $build_dir");
279 dpurdie 799
        my @create_opts = "-o";
800
        push @create_opts ,"-m" if ( $opt_merge );
801
        JatsCmd('-here', 'create_dpkg', @create_opts, '-pname', $be->{name}, '-pversion', $be->{version}) and $error++;
263 dpurdie 802
    }
803
 
804
    if ( $opt_copy )
805
    {
806
        Message ("Copy package to $user_cwd");
807
        copy_directory( 'pkg', $user_cwd, '' );
808
    }
809
 
810
    #
811
    #   Test structure of the package
812
    #   Ensure that it has a descpkg file
813
    #   Validate the package name and version
814
    #   More important for ANT projects than JATS as JATS has a sanity test
815
    #
816
    if ( $opt_test )
817
    {
818
        JatsCmd('-here', 'create_dpkg', '-test', '-pname', $be->{name}, '-pversion', $be->{version}) and $error++;
819
    }
820
 
821
}
822
Error ("Package not transferred")
823
    if ( $error );
824
 
825
 
826
#
827
#   Delete the view
828
#
829
if ( ! $opt_reuse && ! $error && ! $opt_keep )
830
{
831
    delete_view();
832
}
833
else
834
{
835
    Message( "View left in: $VIEWDIR" );
836
}
837
 
838
Message ("End program");
839
exit 0;
840
 
841
#-------------------------------------------------------------------------------
842
# Function        : delete_view
843
#
844
# Description     : Delete a view
845
#
846
# Inputs          : None
847
#                   $VIEWTAG - name of the view
848
#                   $VIEWDIR - path of the view
849
#
850
# Returns         :
851
#
852
sub delete_view
853
{
854
    my $cofound = 0;
855
    my $uuid;
856
 
857
    #
299 dpurdie 858
    #   Simple delete
263 dpurdie 859
    #
299 dpurdie 860
    if ( $opt_extract_files )
263 dpurdie 861
    {
299 dpurdie 862
        if ( -d $VIEWDIR )
863
        {
864
            Message("Remove extracted files: $VIEWTAG");
865
            rmtree( $VIEWDIR );
866
        }
867
    }
868
    else
869
    {
263 dpurdie 870
        #
299 dpurdie 871
        #   If the view physically exists then attempt to phyically remove it
263 dpurdie 872
        #
299 dpurdie 873
        if ( -d $VIEWDIR )
874
        {
875
            #
876
            #   Determine if there are any checked out files in the view
877
            #
878
            Message("Remove the view: $VIEWTAG");
879
            Verbose("Look for checked out files");
263 dpurdie 880
 
299 dpurdie 881
            chdir ( $VIEWDIR );
882
            foreach my $file ( glob ('*') )
263 dpurdie 883
            {
299 dpurdie 884
                next if ( $file =~ m~local_dpkg_archive~ );
885
                next if ( $file =~ m~^view\.~ );
886
                if ( -d $file )
887
                {
888
                    Verbose ("Examine $file for checked out files");
889
                    chdir "$VIEWDIR/$file";
263 dpurdie 890
 
299 dpurdie 891
                    my $cmd = ClearToolCmd('lsco', '-cview', '-rec' );
892
                    open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
893
                    while (<CMD>)
263 dpurdie 894
                    {
299 dpurdie 895
                        #
896
                        #   Filter output from the user
897
                        #
898
                        chomp;
899
                        Verbose("lsco: $_");
900
                        if ( m~checkout version~ )
901
                        {
902
                            $cofound++ ;
903
                            Warning ("Checked out file: $_");
904
                        }
263 dpurdie 905
                    }
299 dpurdie 906
                    close(CMD);
263 dpurdie 907
                }
908
            }
909
 
299 dpurdie 910
            Error ("Will not delete view. Checked out files exist")
911
                if ( $cofound );
263 dpurdie 912
 
299 dpurdie 913
            #
914
            #   Get out of the view
915
            #   Cannot delete the view if we are in it.
916
            #
917
            chdir ( $user_cwd );
263 dpurdie 918
 
299 dpurdie 919
            #
920
            #   Static views should be removed by dirname, not by tag
921
            #
922
            ClearTool( 'rmview', $VIEWDIR );
263 dpurdie 923
 
299 dpurdie 924
            #
925
            #   Now try to delete the directory
926
            #
927
            rmtree( $VIEWDIR );
928
        }
263 dpurdie 929
 
930
        #
299 dpurdie 931
        #   If the view tag still exists then delete the view the hard way
932
        #   Use 'lsview' to locate the views uuid
263 dpurdie 933
        #
299 dpurdie 934
        Verbose("Look for View Tag");
935
        my $cmd = ClearToolCmd ('lsview', '-long', $VIEWTAG );
936
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
937
        while (<CMD>)
938
        {
939
            #
940
            #   Filter output from the user
941
            #
942
            chomp;
943
            Verbose("lsview: $_");
944
            $uuid = $1 if ( m~^View uuid:\s+(.*)~ );
945
        }
946
        close(CMD);
263 dpurdie 947
 
299 dpurdie 948
        if ( $uuid )
949
        {
950
            Warning ("Deleting view - the hard way");
951
            ClearTool( '--Quiet', 'rmview', '-force', '-all', '-uuid', $uuid );
952
            ClearTool( '--Quiet', 'unregister', '-view', '-uuid', $uuid );
953
            ClearTool( '--Quiet', 'rmtag','-view', '-all', $VIEWTAG );
954
        }
263 dpurdie 955
    }
956
 
957
    Error ("View was not deleted")
958
        if ( -d $VIEWDIR );
959
}
960
 
961
#-------------------------------------------------------------------------------
962
# Function        : copy_directory
963
#
964
# Description     : Copy a directory tree
965
#
966
# Inputs          : Source directory
967
#                   Target directory
968
#                   Strip
969
#
970
#                   Should be full pathnames
971
#
972
# Returns         :
973
#
974
my $copy_error;
975
my $copy_count;
976
sub copy_directory
977
{
978
    our ($src_dir, $dest_dir, $strip) = @_;
979
    our $slength = length ($strip);
980
 
981
    #
982
    #   Prevent File::Find from generating warnings
983
    #
984
    no warnings 'File::Find';
985
 
986
 
987
    #
988
    #   Helper routine to copy files
989
    #
990
    sub copy_file_wanted
991
    {
992
        #
993
        #   Do not copy directories
994
        #   Just make the directory entry. May result in empty directories
995
        #
996
        if ( -d $_ )
997
        {
998
            my $tdir = "$dest_dir/" . substr( $File::Find::dir, $slength);
999
            $tdir .= "/$_";
1000
            File::Path::mkpath( $tdir )
1001
                unless ( -d $tdir);
1002
            return;
1003
        }
1004
 
1005
        #
1006
        #   When used to copy file from within a clearcase dynamic view the
1007
        #   files may not actually exist. This will generate an error later
1008
        #   so check for existance of file file now.
1009
        #
1010
        return unless ( -e $_ );
1011
 
1012
        #
1013
        #   Have been chdir'ed to the source directory
1014
        #   when invoked
1015
        #
1016
        my $tdir = "$dest_dir/" . substr( $File::Find::dir, $slength);
1017
        my $tfile = "$tdir/$_";
1018
        my $sfile = "$File::Find::dir/$_";
1019
        Verbose ("Copy: $sfile -> $tfile");
1020
 
1021
        File::Path::mkpath( $tdir )
1022
            unless ( -d $tdir);
1023
 
1024
        unlink ( $tfile )
1025
            if ( -f $tfile );
1026
 
1027
        if( ! File::Copy::copy ( $_ , $tfile ) )
1028
        {
1029
            $copy_error++;
1030
            Message "Error copying $sfile";
1031
        }
1032
        else
1033
        {
1034
            my $perm = (stat $_)[2] & 07777;
1035
            chmod($perm, $tfile);
1036
 
1037
            $copy_count++;
1038
        }
1039
    }
1040
 
1041
    #
1042
    #   Locate all files to copy
1043
    #
1044
    $copy_error = 0;
1045
    $copy_count = 0;
1046
    File::Find::find ( \&copy_file_wanted, $src_dir );
1047
    return $copy_error;
1048
}
1049
 
1050
#-------------------------------------------------------------------------------
1051
# Function        : ClearTool
1052
#
1053
# Description     : Issue a cleartool command
1054
#                   Filter out many of the stupid messages
1055
#
1056
# Inputs          : Options and Command line
1057
#                   Options:
1058
#                       --Quiet     - Supress all command output
1059
#
1060
# Returns         : Error code
1061
#
1062
sub ClearTool
1063
{
1064
    my $quiet;
1065
 
1066
    #
1067
    #   Scan for initial options
1068
    #       --Quiet
1069
    #
1070
    if ( $_[0] eq '--Quiet' )
1071
    {
1072
        $quiet = 1;
1073
        shift;
1074
    }
1075
 
1076
    my $cmd = ClearToolCmd(@_);
1077
    open(CMD, "$cmd 2>&1 |") || Error "can't run command: $!";
1078
    while (<CMD>)
1079
    {
1080
        #
1081
        #   Filter output from the user
1082
        #
1083
        next if ( $quiet );
1084
        unless ( $opt_verbose )
1085
        {
1086
            next if ( m~Making dir~ );
1087
            next if ( m~End dir~ );
1088
            next if ( m~Processing dir~ );
1089
            next if ( m~Error~ );
1090
        }
1091
        print $_;
1092
    }
1093
    close(CMD);
1094
 
1095
    Verbose2 "ClearTool Exit Status: $?";
1096
    return $? / 256;
1097
}
1098
 
1099
#-------------------------------------------------------------------------------
1100
# Function        : ClearCmd
1101
#
1102
# Description     : Execute a cleartool command
1103
#                   Capture error messages only
1104
#
1105
# Inputs          : Command to execute
1106
#                   Takes an array of command argumeents and will quote them
1107
#
1108
# Returns         : Exit code
1109
#                   Also the global @error_list
1110
#
1111
sub ClearCmd
1112
{
1113
    @error_list = ();
1114
 
1115
    my $cmd = ClearToolCmd(@_);
1116
    open(CMD, "$cmd  2>&1 |")    || Error "can't run command: $!";
1117
    while (<CMD>)
1118
    {
1119
        chomp;
1120
        Verbose ($_);
1121
        push @error_list, $_ if ( m~Error:~ );
1122
    }
1123
    close(CMD);
1124
 
1125
    Verbose2 "Exit Status: $?";
1126
    return $? / 256;
1127
}
1128
 
1129
#-------------------------------------------------------------------------------
1130
# Function        : ClearToolCmd
1131
#
1132
# Description     : Create a nice escaped cleartool command
1133
#
1134
# Inputs          : An array of cleartool command line arguments
1135
#
1136
# Returns         : A string that has been quoted
1137
#
1138
sub ClearToolCmd
1139
{
1140
    my $cmd = 'cleartool ' . QuoteCommand( @_);
1141
    Verbose2 $cmd;
1142
    return $cmd;
1143
}
1144
 
1145
#-------------------------------------------------------------------------------
1146
# Function        : unlock_on_error
1147
#
1148
# Description     : Error cleanup function.
1149
#                   Called by the error processing
1150
#                   Called to unlock all labels that have been locked by this
1151
#                   utility
1152
#
1153
# Inputs          : @label_locked           - Labels locked by this utility (Global)
1154
#
1155
# Returns         : 
1156
#
1157
sub unlock_on_error
1158
{
1159
    my @still_locked;
1160
    Message( "Releasing Locked labels" );
1161
    foreach my $spec ( @label_locked )
1162
    {
1163
        Verbose ("Unlocking:$spec");
1164
        ClearCmd ('unlock', "lbtype:$spec$root_vob_spec" );
1165
        push @still_locked, $spec if ( @error_list );
1166
    }
1167
    Error ("Not all labels unlocked: @still_locked") if ( @still_locked  );
1168
}
1169
 
1170
#-------------------------------------------------------------------------------
1171
# Function        : extract_files_from_view
1172
#
1173
# Description     : This function will
1174
#                       Create a dynamic view
1175
#                       Copy all the files out of the view
1176
#                       Delete the view
1177
#
1178
#                   Its used in the creation of escrow directories
1179
#
1180
# Inputs          : None
1181
#                   All done via globals
1182
#
1183
# Returns         : 
1184
#
1185
sub extract_files_from_view
1186
{
1187
    my $vob_mounted = 1;
1188
    my $vob_name;
1189
 
1190
    #
1191
    #   Determine the target directory for the extracted files
1192
    #       Delete the output subdir
1193
    #       Create the config spec in that directory
1194
    #
1195
    Verbose("Extracting files into $VIEWDIR");
1196
    if ( -d $VIEWDIR )
1197
    {
1198
        Verbose "Delete Directory: $VIEWDIR\n";
1199
        rmtree( $VIEWDIR );
1200
    }
1201
 
1202
    #
1203
    #   Which config spec
1204
    #   If we need to create it, do it within the final view
1205
    #
1206
    my $config;
1207
    $config = $opt_config_spec;
1208
    unless ( $opt_config_spec )
1209
    {
1210
        File::Path::mkpath( $VIEWDIR );
1211
        $config = create_config_spec( "$VIEWDIR/config_spec.txt" );
1212
    }
1213
 
1214
    #
1215
    #   Create the view and insert the config spec
1216
    #
1217
    ClearCmd ( 'rmview', '-tag', $VIEWTAG );
1218
    ClearCmd ( 'mkview', '-tag', $VIEWTAG, '-stgloc', '-auto' );
1219
    ClearCmd ( 'setcs',  '-tag', $VIEWTAG, $config );
1220
 
1221
    #
1222
    #   Ensure that the base VOB has been 'mounted'
1223
    #   Dynamic views require vobs to be mounted
1224
    #
1225
    ($vob_name = $ROOT_VOB) =~ s~/~$VOB_SEP~g;
1226
    $vob_mounted = ClearCmd ('mount', $vob_name);
1227
 
1228
    #
1229
    #   Calculate where the dynmaic view will be
1230
    #   This differ between UNIX/WINDOWS
1231
    #
1232
    my $vpath = $VIEW_PREFIX . $VIEWTAG . $VOB_PREFIX;
1233
    my $cpath = $vpath;
1234
       $cpath .= $opt_path if ( $opt_path );
1235
    #
1236
    #   Is the view where we expect it to be
1237
    #
1238
    Error ("Cannot locate dynamic view",
1239
            "Looking in: $vpath" ) unless -d $vpath;
1240
 
1241
    #
1242
    #   Copy all the files out of the view
1243
    #
1244
    Verbose ("Copy View contents");
1245
    my $rv = copy_directory ($cpath, $VIEWDIR, $vpath );
1246
    Message ("View files in: $VIEWDIR, Files: $copy_count" );
1247
 
1248
    #
1249
    #   Remove the view
1250
    #
1251
    ClearCmd ( 'rmview', '-tag', $VIEWTAG );
1252
 
1253
    #
1254
    #   Unmount the vob - if mounted
1255
    #
1256
    ClearCmd ('umount', $vob_name) unless $vob_mounted;
1257
 
1258
    Error ("Copy did not complete without error")
1259
        if ( $rv );
1260
 
1261
}
1262
 
1263
#-------------------------------------------------------------------------------
1264
# Function        : create_config_spec
1265
#
1266
# Description     : Creates a config spec
1267
#
1268
# Inputs          : $config     - Path to the config file
1269
#
1270
# Returns         : Path to the config spec
1271
#
1272
sub create_config_spec
1273
{
1274
    my ($config_file) = @_;
1275
    #
1276
    #   Create a config spec to be used to populate the view
1277
    #       Do not branch directories
1278
    #       Do not extract files from lost+found
1279
    #
1280
    Verbose( "Create config spec");
1281
    my @config;
1282
    push @config, "element * CHECKEDOUT";
1283
    push @config, "element .../lost+found -none";
1284
    push @config, "element * .../$opt_branch/LATEST" if $opt_branch;
1285
    foreach (@opt_spec)
1286
    {
1287
        my $data = "element * $_";
1288
        $data .= " -mkbranch $opt_branch" if $opt_branch;
1289
        push @config, $data;
1290
    }
1291
 
1292
    #
1293
    #   Packages SHOULD be labled to the root.
1294
    #   Do not extend this list fix the package - fix the labels in the VOB.
1295
    #
1296
    if ( $opt_latest_root )
1297
    {
1298
        push @config, "element -directory $ROOT_VOB .../$opt_latest_root/LATEST";
1299
        push @config, "element -directory $ROOT_VOB .../mass_dev/LATEST";
1300
        push @config, "element -directory $ROOT_VOB /main/LATEST";
1301
    }
1302
 
1303
    #
1304
    #   Do not branch directories above the load path
1305
    #   Load only the version on /main
1306
    #       UNIX: Don't play with the /vobs (won't work)
1307
    #
1308
    if ( $opt_branch )
1309
    {
1310
        if ( $opt_path )
1311
        {
1312
            my $fulldir = $VOB_PREFIX;
1313
            my @parts = split ('/', $opt_path);
1314
            shift @parts;
1315
            foreach my $dir ( @parts )
1316
            {
1317
                $fulldir .= "/$dir";
1318
                push @config, "element -dir $fulldir /main/LATEST"
1319
            }
1320
        }
1321
        else
1322
        {
1323
            push @config, "element -dir $ROOT_VOB /main/LATEST";
1324
        }
1325
    }
1326
 
1327
    #
1328
    #   Branch rule:
1329
    #   Need /main/0 to allow files to be added to the view
1330
    #   Will get a lot of stuff, so take care not to label it all
1331
    #
1332
    push @config, "element * /main/0 -mkbranch $opt_branch" if $opt_branch;
1333
 
1334
    #
1335
    #   Load rule
1336
    #   Use ROOT_VOB, unless the user has specified a path
1337
    #   Quote the path so that spaces will be correcly handled
1338
    #
1339
    push @config, "load $ROOT_VOB" unless $opt_path;
1340
    push @config, "load \"$VOB_PREFIX$opt_path\"" if $opt_path;
1341
 
1342
    FileCreate ($config_file, \@config);
1343
    return $config_file;
1344
}
1345
 
1346
#-------------------------------------------------------------------------------
1347
#   Documentation
1348
#
1349
 
1350
=pod
1351
 
1352
=head1 NAME
1353
 
1354
jats_ccrelease - Build a package given a clearcase label
1355
 
1356
=head1 SYNOPSIS
1357
 
1358
  jats ccrelease [options] [-label=]label | -config=config_spec
1359
 
1360
 Options:
1361
    -help              - brief help message
1362
    -help -help        - Detailed help message
1363
    -man               - Full documentation
1364
    -label=xxx         - Clearcase label
1365
    -spec=xxx          - Same as -label=xxx
1366
    -path=xxx          - Source Path
1367
    -view=xxx          - Modify the name of the created view
1368
    -vob=vobname       - VOB name
1369
    -build=xxx         - Package Name to build
1370
    -root=xxx          - Root directory for generated view
1371
    -latestroot=xxx    - Use the LATEST rootlevel directory 'xxx'
1372
    -[mk]branch=xxx    - Will create a view with a branch rule
1373
    -config=xxx        - Create a view with the provided config spec
1374
    -tag=xxx           - Alternate tag used with in the ViewTag
1375
    -extract           - Extract the view and exit
1376
    -extractfiles      - Extract files, without a view
1377
    -cache             - Refresh local dpkg_archive cache
1378
    -delete            - Remove any existing view and exit
1379
    -debugOnly         - Make only the debug version
1380
    -prodOnly          - Make only the production version
1381
    -[no]dpkg          - Transfer package into dpkg_archive
1382
    -[no]copy          - Transfer pkg directory to the current user directory
1383
    -[no]reuse         - Reuse the view
1384
    -[no]test          - Test package build. Implies nocopy and nodpkg
1385
    -[no]keep          - Keep the view after the build
1386
    -[no]lock          - Lock labels
1387
    -[no]beta          - Release a beta package
1388
    -[no]merge         - Merge packages into dpkg_archive
1389
    -[no]runtests      - Run units tests. Default is runtests
1390
    -[no]prefix        - Supress user prefix in view name. Default prefix is USER
1391
 
1392
=head1 OPTIONS
1393
 
1394
=over 8
1395
 
1396
=item B<-help>
1397
 
1398
Print a brief help message and exits.
1399
 
1400
=item B<-help -help>
1401
 
1402
Print a detailed help message with an explanation for each option.
1403
 
1404
=item B<-man>
1405
 
1406
Prints the manual page and exits.
1407
 
1408
=item B<-label> or B<-spec>
1409
 
1410
The ClearCase label to use as the base for the view.
1411
 
1412
Eg: daf_utils_math_3.2.1
1413
 
1414
=item B<-view name>
1415
 
1416
Specified an alternate view name and tag to be used. This option does not provide the
1417
full name of the view.
1418
 
1419
    The view tag will be : "${USER}_${MACHINENAME}_${TAG}_${NAME}"
1420
    The view path will be: "${USER}_${NAME}"
1421
 
1422
The default "NAME" is the first label specified.
1423
The default "TAG" is build. See B<-tag=tagname>.
1424
 
1425
If the user provides a view "name" that is prefixed with their user name
1426
('${USER}_'), then the username will be stripped of for internal processing.
1427
This allows a user to provide a view path when deleting a view.
1428
 
1429
=item B<-path=xxx>
1430
 
1431
Specifies the source path to the root of the extracted file tree. This option has several uses:
1432
 
1433
=over 8
1434
 
1435
=item   *
1436
 
1437
Provide a sanity test of the "Source Path" item within Release Manager
1438
 
1439
=item   *
1440
 
1441
Specify the VOB that contains the source. The VOB name will be extracted and
1442
used as the B<-vob> parameter.
1443
 
1444
=item   *
1445
 
1446
Limit the work to do in extracting the file tree.
1447
 
1448
=back
1449
 
1450
=item B<-vob=xxx>
1451
 
1452
Specifies the Clearcase VOB in which the clearcase label will be located.
1453
This is used as the basis for locating and loading the files within the view.
1454
 
1455
By default this utility will examine all the VOBs for the label.
1456
 
1457
=item B<-build=xxx>
1458
 
1459
This option allows the user to specify the packages to be built and the
1460
order in which the packages are to be built.
1461
This is useful if the extracted view contains multiple build files
1462
 
1463
This option may be used multiple times.
1464
 
1465
There are two forms in which the build target can be specified. It can be
1466
specified as a full package name and vesrion, or as a package name and the
1467
project suffix.
1468
 
1469
By default the program will assume that there is only one build file in the
1470
view and will not build if multiple files are present, unless the package to be
1471
built can be resolved.
1472
 
1473
The location mechanism operates for both JATS and ANT build files.
1474
 
1475
Example: -build=jats-api.1.0.0000.cr
1476
 
1477
This will locate the build file that builds version 1.0.0000.cr of the jats-api
1478
package. The version numbers must match exactly.
1479
 
1480
Example: -build=jats-api.cr -build=jats-lib.cr
1481
 
1482
This will located the build files that build the jats_api (cr) package and the
1483
jats-lib (cr) package. The version of the packages will not be considered.
1484
 
1485
=item B<-root=xxx>
1486
 
1487
This option allows the location of the generated view to be specified on the
1488
command line. The environment variable GBE_VIEWBASE provides the same feature,
1489
but it will affect all the view created.
1490
 
1491
The default location is:
1492
 
1493
=over 8
1494
 
1495
=item WINDOWS
1496
 
1497
c:\clearcase
1498
 
1499
=item Unix
1500
 
1501
$(HOME)/jats_cbuilder
1502
 
1503
If the comamnd is invoked within a development sandbox, then the default
1504
location will be the root directory of the development sandbox.
1505
 
1506
=back
1507
 
1508
=item B<-latestroot=xxx>
1509
 
1510
This option enables a work around for a bad-labelling practice that has existed
1511
in the past. This LATEST version of the named (xxx) branch will be added to
1512
the config spec used to create the view.
1513
 
1514
This is a work around for a problem where the top-level directory in the VOB has
1515
not been labelled. This can result in unreproducible builds.
1516
 
1517
This option allows the utility to construct a view, but the user SHOULD label
1518
the root level directory to correct the problem.
1519
 
1520
The use of this switch will add the following lines to the config spec:
1521
 
1522
    element -directory /DPG_SWBase /main/xxxx/LATEST
1523
 
1524
=item B<-branch=xxx or -mkbranch=xxx>
1525
 
1526
This option will create a view such that files that are checked out will be
1527
checked out on the named branch. This is intended to facilitate the maintenance
1528
of existing packages - the creation of a patch.
1529
 
1530
The named branch must exist within the VOB containing the label. The script will
1531
check for its existence.
1532
 
1533
The use of this switch will add the following lines to the config spec:
1534
 
1535
    element * .../xxx/LATEST
1536
    element * {label} -mkbranch xxx
1537
    element * /main/0 -mkbranch xxx
1538
 
1539
=item B<-config=config_spec>
1540
 
1541
This option is an alternate mechanism to create a static view. The view will be
1542
based on the provided configuration spec. This view cannot be used to release a package.
1543
The option is intended to simplify development.
1544
 
1545
This option is incompatibale with:
1546
 
1547
    -release
1548
    -label
1549
    -branch
1550
    -path
1551
    -vob
1552
 
1553
 
1554
=item B<-tag=text>
1555
 
1556
This option alters the ClearCase view tag created for the view. It allows
1557
the creation of multiple views based on the same label. Intended to be used in
1558
the automated build system to create unique views tags.
1559
 
1560
The default tag is 'build'.
1561
 
1562
=item B<-extract>
1563
 
1564
With this option the view is created and the left in place. The user may then
1565
access the files within the view. The view should not be used for a
1566
production release.
1567
 
1568
=item B<-extractfiles>
1569
 
1570
With this option the utility will create a dynamic view and transfer files from
1571
the view to the user's tararget. The dynamic view is then removed.
1572
 
1573
This command is intended to simplify the process of creating an escrow.
1574
 
1575
=item B<-cache>
1576
 
1577
Forces external packages to be placed in the local dpkg_archive cache.
1578
 
1579
The normal operation is to copy the packages, only if they do not already exist
1580
in the local cache. This option may be used to ensure that the local copy is
1581
correct and up to date.
1582
 
1583
=item B<-delete>
1584
 
1585
Delete the view used by the program, if it exists. This option may be used to
1586
cleanup after an error.
1587
 
1588
Note: Ensure that no files are open in the view and that the users current
1589
working directory is not in the view as these will prevent the view from being
1590
deleted.
1591
 
1592
 
1593
=item B<-debugOnly>
1594
 
1595
Make only the debug version of the package. The default it to create both the
1596
debug and production version of the package. The type of build may be  further
1597
limited by options within the package.
1598
 
1599
=item B<-prodOnly>
1600
 
1601
Make only the production version of the package. The default it to create both the
1602
debug and production version of the package. The type of build may be  further
1603
limited by options within the package.
1604
 
1605
=item B<-[no]dpkg>
1606
 
1607
Copy the generated package into dpkg_archive. This is the default mode of
1608
operation.
1609
 
1610
=item B<-[no]copy>
1611
 
1612
Copy the built "pkg" directory to the users current directory. The entire
1613
"pkg" subdirectory includes the full package named directory for the package
1614
that has been built.
1615
 
1616
=item B<-[no]reuse>
1617
 
1618
This flag allows the view created by the program to be re-used.
1619
 
1620
=over 8
1621
 
1622
=item 1. The view is not deleted before being populated.
1623
 
1624
=item 2. The view will not be populated if it does exist.
1625
 
1626
=item 3. The view will not be deleted at the end the process.
1627
 
1628
=back
1629
 
1630
This option is useful for debugging a build process.
1631
 
1632
=item B<-[no]test>
1633
 
1634
Test the building of the package. This option implies "nocopy" and "nodpkg".
1635
 
1636
=item B<-[no]keep>
1637
 
1638
Keep the clearcase view after the build. The default option is "nokeep"
1639
 
1640
This option is different to the "reuse" in that the view will be deleted, if
1641
it exists, before the build, but will be retained at the completion of the
1642
process. The user may then manually extract the created package.
1643
 
1644
The view may be deleted with the the "delete" option; taking care to ensure that
1645
no files are open in the view and that the users current working directory is
1646
not in the view.
1647
 
1648
=item B<-[no]lock>
1649
 
1650
Lock any unlocked labels before attempting the build. This operation may be used
1651
to ensure that a release build does not fail due to the labels not being locked.
1652
The label is locked before the view is constructed and populated.
1653
 
1654
This operation may fail if the user does not "own" the label.
1655
 
1656
=item B<-[no]beta>
1657
 
1658
This option overrides many of the package release tests to allow a beta package
1659
to be released.
1660
 
1661
=item B<-[no]merge>
1662
 
1663
This option will merge packages being built on multiple machines into
1664
dpkg_archive. By default, if a package already exists in the archive it will be
1665
deleted and replaced. With this option the package will be merged. The merge
1666
process does not over write files found in the archive.
1667
 
1668
=item B<-[no]runtests>
1669
 
1670
This option will allow the suppression of the running of the unit tests included
1671
with the component. By default the tests are run. This can be suppressed
1672
without affecting the release process.
1673
 
1674
=back
1675
 
1676
=head1 DESCRIPTION
1677
 
1678
This program is the primary tool for the creation, recreation and release of
1679
packages within the B<ERG> build environment, although the program can perform a
1680
number of very useful operations required during normal development and
1681
maintenance.
1682
 
1683
This program will build a system containing one or more inter-related build
1684
files using the JATS build tools.
1685
 
1686
In normal operation the program will:
1687
 
1688
=over 8
1689
 
1690
=item Remove View
1691
 
1692
Remove any existing view of the same name. The view will not be removed if it
1693
contains checked-out files.
1694
 
1695
The view removal may fail if there are any files B<open> within the view or if
1696
any shell has a subdirectory of the view set as a B<current working directory>.
1697
 
1698
=item Locate VOB
1699
 
1700
Locate the VOB that contains the specified label or labels. If multiple labels
1701
are specified they must all exist in the same VOB.
1702
 
1703
=item Lock Labels
1704
 
1705
Lock any unlocked labels, if required.
1706
 
1707
=item Create the view
1708
 
1709
Create a static view to containing the files describes by the Clearcase
1710
label being processed.
1711
 
1712
The program uses a fixed view name. If this view exists then item
1713
will be deleted before item is created again. Each build starts in a clean view.
1714
 
1715
=item Populate the View
1716
 
1717
Loads files into the static view. The user label and the VOB name are used to
1718
created a clearcase configuration specification. This configuration
1719
specification is then activated and all files within the specified VOB will be
1720
loaded into the view if they match the user supplied label.
1721
 
1722
This processed normally results in a lot of error messages that can be ignored.
1723
 
1724
I<Note:> The label placed on the component to be built must extend to the
1725
root of the VOB, otherwise the directory path will not be extracted nor will
1726
the files within the component.
1727
 
1728
I<Note:> If the view is simply being extracted, then this is the end of the
1729
program. The extracted view is left in place.
1730
 
1731
=item Sanity Test
1732
 
1733
If the build is being used as a release into dpkg_archive then
1734
various tests are performed to ensure the repeatability of the view and the
1735
build. These tests include:
1736
 
1737
=over 8
1738
 
1739
=item   * The view must be constructed from one label
1740
 
1741
=item   * That label must be locked
1742
 
1743
=item   * The labelled view must contain exactly one build file
1744
 
1745
=item   * The view cannot have been re-used.
1746
 
1747
=back
1748
 
1749
=item Locate build files
1750
 
1751
Locate the build file within the view.
1752
 
1753
It is an error to have multiple build files within the view, unless the
1754
B<-build> option is used. By default, only one package will be built.
1755
 
1756
=item Package the results
1757
 
1758
Use JATS to build and make the package.
1759
 
1760
The resultant package may be copied to a numbers of locations. These include
1761
 
1762
=over 8
1763
 
1764
=item 1
1765
 
1766
The master dpkg_archive as an official release. This is the default operation.
1767
 
1768
=item 2
1769
 
1770
The users current directory. The package directory from the built package is
1771
copied locally. The "pkg" directory is copied. This is only performed with the
1772
B<-copy> option.
1773
 
1774
=back
1775
 
1776
=item Delete the view
1777
 
1778
Delete the view and all related files.
1779
 
1780
The view will not be deleted if an error was detected in the build process, or
1781
the "reuse" or "keep" options are present.
1782
 
1783
=back
1784
 
1785
=cut
1786