Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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