Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
261 dpurdie 2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
227 dpurdie 3
#
309 dpurdie 4
# Module name   : jats_svnasave_build.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
261 dpurdie 9
# Description   : Build Daemon Support Utility
10
#                 This utility will:
11
#                   +   Assume the CWD is the root-dir of a package
12
#                       within a versioned control view
13
#                   +   Determine a suitable label for the package
14
#                   +   Save the build file in the view
15
#                   +   Label the resultant view
227 dpurdie 16
#
261 dpurdie 17
# Usage:        : See POD at end of this file
227 dpurdie 18
#
267 dpurdie 19
#               jats etool  jats_save_build
20
#                   -infile     auto.xml/auto.pl
21
#                   -outfile    xxxdepends.xml/build.pl
22
#                   -pname      package_name
23
#                   -pversion   package_version
24
#                   -infofile   path_to_info_file
25
#                   -wiplabel   Existing WIP label (optional)
26
#
227 dpurdie 27
#......................................................................#
28
 
29
use strict;
30
use warnings;
31
use JatsError;
261 dpurdie 32
use JatsBuildFiles;
33
use JatsSystem;
34
use JatsProperties;
227 dpurdie 35
use Getopt::Long;
36
use Pod::Usage;                             # required for help support
261 dpurdie 37
use Cwd;
227 dpurdie 38
 
39
################################################################################
40
#   Option variables
41
#
42
 
261 dpurdie 43
my $VERSION = "2.0.0";                      # Update this
263 dpurdie 44
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
45
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
227 dpurdie 46
my $opt_infile  = "auto.pl";
47
my $opt_ofile = "build.pl";
48
my $opt_help = 0;
49
my $opt_branch_default = "AutoBuilder";
50
my $opt_branch;
51
my $opt_newbranch;
261 dpurdie 52
my $opt_infofile;
53
my $opt_pname;
54
my $opt_pversion;
55
my $opt_wiplabel;
56
my $opt_locate;
227 dpurdie 57
 
58
#
59
#   Globals
60
#
261 dpurdie 61
my $root_dir;
62
my $pkg_label;
63
my $tag_label;
227 dpurdie 64
my @error_list;
65
my $last_result;
241 dpurdie 66
my @last_results;
261 dpurdie 67
my $label_created;
227 dpurdie 68
 
261 dpurdie 69
#
70
#   Configuration options
71
#
227 dpurdie 72
my $result = GetOptions (
261 dpurdie 73
                "help:+"        => \$opt_help,              # flag, multiple use allowed
74
                "manual:3"      => \$opt_help,              # flag
75
                "verbose:+"     => \$opt_verbose,           # flag
76
 
77
                "outfile=s"     => \$opt_ofile,             # string
78
                "infile=s"      => \$opt_infile,            # string
79
                "branch=s"      => \$opt_branch,            # string
80
                "newbranch"     => \$opt_newbranch,         # string
81
 
82
                "infofile=s"    => \$opt_infofile,          # string
83
                "pname=s"       => \$opt_pname,             # string
84
                "pversion=s"    => \$opt_pversion,          # string
85
                "wiplabel=s"    => \$opt_wiplabel,          # string
86
                "locatepkg=s"   => \$opt_locate,            # string
87
 
88
                #
89
                #   Update documentation at the end of the file
90
                #
227 dpurdie 91
                );
92
 
93
#
94
#   Process help and manual options
95
#
96
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
261 dpurdie 97
pod2usage(-verbose => 1)  if ( $opt_help == 2 );
98
pod2usage(-verbose => 2)  if ( $opt_help > 2 );
227 dpurdie 99
 
100
#
101
#   Configure the error reporting process now that we have the user options
102
#
261 dpurdie 103
ErrorConfig( 'name'    =>'ABTSAVE',
227 dpurdie 104
             'verbose' => $opt_verbose,
105
             'on_exit' => \&display_error_list
106
           );
107
Error ("Input and output file are the same: $opt_infile" )
108
    if ( $opt_infile eq $opt_ofile );
109
 
110
Error ("Must provide a branch when usng newbranch option")
111
    if ( $opt_newbranch && ! $opt_branch );
112
 
113
$opt_branch = $opt_branch_default
114
    unless ( $opt_branch );
115
 
309 dpurdie 116
Error ("Package Name not provided")
117
    unless ( $opt_pname );
261 dpurdie 118
 
309 dpurdie 119
Error ("Package Version not provided")
120
    unless ( $opt_pversion );
261 dpurdie 121
 
309 dpurdie 122
Warning("Path to info file not provided")
123
    unless ( $opt_infofile );
261 dpurdie 124
 
309 dpurdie 125
unlink ($opt_infofile) if $opt_infofile;
261 dpurdie 126
 
127
#
128
#   Locate the build directory and chdir to that directory
129
#
130
locate_build_directory();
131
 
132
#
133
#   Have changed to the directory with build files
134
#   Continue with user argument sanity check
135
#
136
Error ("Input file not found: $opt_infile" )
137
    unless ( -f $opt_infile );
138
 
139
Error ("Output file not found: $opt_ofile" )
140
    unless ( -f $opt_ofile );
141
 
142
#
227 dpurdie 143
#   Determine the name of the Branch to be used
144
#   This is based on the branch that the file is already on as ClearCase does
145
#   not allow multiple instances of a branch on different sub-branches
146
#
261 dpurdie 147
ClearCmd ('describe',  '-fmt', '%n', $opt_ofile);
227 dpurdie 148
Error ("Program Terminated") if ( @error_list );
149
Error ("File may not be a VOB object: $opt_ofile" ) unless ( $last_result );
150
my $full_name = $last_result;
151
 
152
$last_result =~ m~(.*)/([^/]+)$~;
153
my $full_path = $1;
154
 
155
$last_result =~ m~(.*)/([^/]+)/([^/]+)~;
156
my $current_branch = $2;
157
 
158
$last_result =~ m~@@(.*)/([^/]+)~;
159
my $full_branch = $1;
160
my $target_branch = $full_branch;
161
my $branch_point = "";
162
 
163
Error ("Cannot determine full pathname of the file: $full_name") unless ( $full_path );
164
 
165
Verbose2 ("FullName     : $full_name" );
166
Verbose2 ("FullPath     : $full_path" );
167
Verbose2 ("Branch       : $current_branch" );
168
Verbose2 ("Userb        : $opt_branch" );
169
Verbose2 ("FullBranch   : $full_branch" );
170
#
171
#
172
#   Determine the branch that the file is on
173
#   If it is not on the desired branch then we will need to create the branch
174
#
175
#   Ensure that the required branch exists in the current VOB
176
#   Need to handle some legacy branches that were created with the name AutoBuilder
177
#   by not creating AutoBuild/AutoBuilder.AutoBuilder branches but retaining the
178
#   existing AutoBuilder branch.
179
#
180
if ( $opt_newbranch )
181
{
182
    #
183
    #   User has asked for a new branch
184
    #   Place the file on /main/xxxxx
185
    #
186
    $branch_point = "-version /main/0";
187
    $target_branch = "/main/$opt_branch";
188
 
189
}
190
elsif ( $current_branch =~ m/^$opt_branch/ )
191
{
192
    #
193
    #   Current branch has the same name ( prefix) as the desired branch
194
    #   Use it
195
    #
196
    $opt_branch  = $current_branch;
197
}
198
else
199
{
200
    #
201
    #   Current branch has a different name
202
    #   Construct new branch name
203
    #
204
    $opt_branch = "$opt_branch.$current_branch";
205
    $target_branch .= "/$opt_branch";
206
}
207
 
208
Verbose2 ("TargetBranch : $target_branch" );
209
Verbose2 ("BranchPoint  : $branch_point" );
210
 
211
#
261 dpurdie 212
#   Determine the desired label for the package
213
#   May need to pick an unassigned label
214
#
215
determine_package_label();
216
 
217
#
218
#   Ensure that the specified package label exists
227 dpurdie 219
#   Determine if it is locked too
261 dpurdie 220
#   
221
Verbose ("Checking package label: $pkg_label");
222
ClearCmd ('describe', '-fmt', '%[locked]p', "lbtype:$pkg_label" );
227 dpurdie 223
Error ("Program Terminated") if ( @error_list );
224
my $was_locked = 1 unless ( $last_result =~ m~unlocked~ );
225
 
226
#
227
#   Create the desired branch if it does not already exist
261 dpurdie 228
#   Detected locked element and unlock it
227 dpurdie 229
#
261 dpurdie 230
Verbose ("Checking branch existence: $opt_branch");
231
ClearCmd ('lstype', '-short', "brtype:$opt_branch" );
227 dpurdie 232
if ( $last_result =~ m~\(locked\)~ )
233
{
261 dpurdie 234
    Verbose ("Unlocking branch: $opt_branch");
235
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', "brtype:$opt_branch" );
227 dpurdie 236
}
237
elsif ( $last_result ne $opt_branch )
238
{
261 dpurdie 239
    Verbose ("Create new branch: $opt_branch");
240
    ClearCmd ('mkbrtype', '-c', "Contains saved versions of $opt_ofile files created by the AutoBuild system", $opt_branch );
227 dpurdie 241
    Error ("Program Terminated") if ( @error_list );
242
}
243
 
244
#
245
#   Ensure that the file is not locked
246
#   Unlock the file - can't do anything to a 'locked' file
247
#
261 dpurdie 248
Verbose ("Checking for locked file: $opt_ofile");
249
ClearCmd ('lslock', '-short', $opt_ofile );
227 dpurdie 250
if ( $last_result )
251
{
261 dpurdie 252
    Verbose ("Unlocking file: $opt_ofile");
253
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', $opt_ofile );
227 dpurdie 254
}
255
 
256
if ( $current_branch ne $opt_branch )
257
{
258
    #
259
    #   Need to create the initial branch point, but only if one does not already
260
    #   exists
261
    #
261 dpurdie 262
    Verbose ("Check for existing branch: $opt_branch" );
263
    if ( ClearCmd( 'find', $opt_ofile, '-version', "brtype($opt_branch)", '-print' ) )
227 dpurdie 264
    {
265
        Error ("Internal error. Cleartool find should not fail");
266
    }
267
    if ( $last_result )
268
    {
269
        #
270
        #   A branch already exists - and there can only be one
271
        #
272
        $last_result =~ m~@@(.*)/([^/]+)~;
273
        $target_branch = $1;
274
        Error ("Cannot determine full branch path: $last_result") unless ( $target_branch );
275
        Verbose2 ("Target Branch: $target_branch" );
276
    }
277
    else
278
    {
279
        Verbose ("Create the initial branch point" );
261 dpurdie 280
        ClearCmd( 'mkbranch', '-nco', '-nc', '-nwarn', $branch_point, $opt_branch, $opt_ofile );
227 dpurdie 281
    }
282
}
283
 
284
#
285
#   Ensure that the branch with the target auto builder file on is not locked
286
#
261 dpurdie 287
ClearCmd ( 'lslock', '-short', "$opt_ofile\@\@$target_branch" );
227 dpurdie 288
if ( $last_result )
289
{
261 dpurdie 290
    Verbose ("Unlocking branch: $target_branch");
291
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', "$opt_ofile\@\@$target_branch" );
227 dpurdie 292
}
293
 
294
 
295
#
296
#   Look for a checked out file on the target branch
297
#   It may be reserved - this will kill the process, so unreserve it
298
#
261 dpurdie 299
if ( ClearCmd( 'lsco', '-long', '-brtype', $opt_branch, $opt_ofile ) )
227 dpurdie 300
{
301
    Error ("Internal error. Cleartool lsco should not fail");
302
}
303
 
241 dpurdie 304
#
305
#   Can only have one 'reserved' checkout on the branch, but it may not
306
#   be the first one listed.
307
#       Lines are in sets of 3
308
#           1) Not used
309
#           2) Has keyword reserved
310
#           3) Has full path to view server
311
#   Need veiew server path, iff its a reserved checkout
312
#
313
my $reserved = undef;
314
foreach ( @last_results )
227 dpurdie 315
{
316
    #
241 dpurdie 317
    #   Once reserved has been seen, the next line will contain the view path
321 dpurdie 318
    #   Note: ClearCmd has changed \ to /, so change them back
319
    #         May be problematical. It looks like this has been
320
    #         changed several times.
227 dpurdie 321
    #
241 dpurdie 322
    if ( $reserved )
323
    {
324
        m~\(\"(.+)\"\)~;
325
        my $view = $1;
321 dpurdie 326
        $view =~ s~/~\\~g unless ( $ENV{GBE_UNIX} );
327
        Verbose ("Reserved checkout: Target View: $view" );
261 dpurdie 328
        ClearCmd( 'unreserve', '-comment', 'Unreserved by JATS ABTSAVE', '-view', $view, $opt_ofile );
241 dpurdie 329
        #
330
        #   Only one reserved file can exist, so there is no more to do
331
        #
332
        last;
333
    }
334
 
335
    #
336
    #   Check to see if this line flags a reserved version
337
    #
338
    $reserved = m~\(reserved\)~;
227 dpurdie 339
}
340
 
341
#
342
#   Use clearcase to checkout the output file
343
#
261 dpurdie 344
Verbose ("Checkout file: $opt_ofile" );
345
ClearCmd ('co', '-nc', '-nq', '-ndata', '-nwarn', '-branch', $target_branch, $opt_ofile);
227 dpurdie 346
Error ("Program Terminated") if ( @error_list );
347
 
348
#
349
#   Place the label on this file
350
#       If the label is locked then unlock it first
351
#       This is OK, because we are the builder ( or have permission )
352
#
261 dpurdie 353
if ( $was_locked )
354
{
355
    Verbose ("Relocking label: $pkg_label");
356
    ClearCmd ('unlock', "lbtype:$pkg_label" );
357
}
227 dpurdie 358
 
261 dpurdie 359
ClearCmd ('mklabel', '-replace', $pkg_label, $opt_ofile );
227 dpurdie 360
my @delayed_error = @error_list;
361
 
261 dpurdie 362
ClearCmd ('lock', "lbtype:$pkg_label" ) if $was_locked;
227 dpurdie 363
 
364
#
365
#   Place a Hyperlink Merge arrow between the two files if it looks as though we
366
#   have stolen the file or its label. If the original build file is on a different branch
367
#   the we have stolen it.
368
#
261 dpurdie 369
Verbose ("Check need to create a Hyperlink" );
227 dpurdie 370
 
371
my $target_name = $opt_ofile;
372
Verbose2 ("FullName: $full_name :Branch: $full_branch" );
373
Verbose2 ("TargetName: $target_name :Branch: $target_branch" );
374
 
375
if ( ( $full_branch ne $target_branch ) && ( !$opt_newbranch ) )
376
{
261 dpurdie 377
    Verbose ("Creating Hyperlink" );
378
    ClearCmd ('mkhlink', 'Merge', $full_name, $target_name);
227 dpurdie 379
}
380
 
381
#
382
#   Check in the file auto.pl file as the new build.pl file
383
#   This may get ugly if the current config-spec does not have a rule to
384
#   select the "new" build.pl file. This is often the case
385
#
386
#   Examine the error output and discard these errors
387
#
261 dpurdie 388
Verbose ("Check in build file: $opt_ofile" );
389
ClearCmd ('ci', '-c', "AutoBuilder checkin: $pkg_label", '-identical', '-from', $opt_infile, $opt_ofile);
227 dpurdie 390
Error ("Program Terminated") unless ( $last_result =~ m/Checked in "$opt_ofile" version/ );
391
 
392
@error_list = @delayed_error;
393
Error ("Program Terminated") if ( @error_list );
394
 
261 dpurdie 395
#
396
#   Label the view
397
#
398
label_build_view();
399
 
227 dpurdie 400
exit 0;
401
 
402
#-------------------------------------------------------------------------------
261 dpurdie 403
# Function        : locate_build_directory
404
#
405
# Description     : Locate the build directory that contains the build files
406
#                   In an ANT build, this will e the root of the package
407
#                   Otherwise the build files may not be in the root directory
408
#
409
#
410
# Inputs          : Globals
411
#
412
# Returns         : Globals
413
#
414
sub locate_build_directory
415
{
416
    return unless ( $opt_locate );
417
 
418
    my $bscanner = BuildFileScanner ( '.', $opt_infile );
419
    my $count = $bscanner->locate();
420
 
421
    Error ("Autolocate. Build file not found: $opt_infile" )
422
        if ( $count <= 0 );
423
 
424
    #
425
    #   If multiple build files have been found
426
    #   Scan the buildfiles and determine the names of the packages that will
427
    #   be built. This can be used to generate nice error messages
428
    if ( $count > 1 )
429
    {
430
        $bscanner->scan();
431
        $count = $bscanner->match( $opt_locate );
432
 
433
        my $errmess;
434
        if ( $count <= 0 ) {
435
            $errmess = "None found that build package: $opt_locate";
436
 
437
        } elsif ( $count > 1 ) {
438
            $errmess = "Multiple build files build the required package: $opt_locate";
439
        }
440
 
441
        #
442
        #   Pretty error display
443
        #   Display build directory and the package name (mangled)
444
        #
445
        if ( $errmess )
446
        {
447
            Error ("Autolocate. Multiple build files found.",
448
                   $errmess,
449
                   "Build files found in:", $bscanner->formatData() );
450
        }
451
    }
452
 
453
    #
454
    #   Extract the required build file directory
455
    #
456
    my $dir = $bscanner->getMatchDir() || '';
457
    Verbose ("Autolocate. Found $count build files: $dir");
458
 
459
    #
460
    #   Select the one true build directory
461
    #
462
    if ( $dir ne '.' )
463
    {
464
        #
465
        #   Save the current directory for later
466
        #
467
        $root_dir = getcwd();
468
        chdir $dir || Error ("Cannot change directory: $dir");
469
    }
470
}
471
 
472
#-------------------------------------------------------------------------------
473
# Function        : determine_package_label
474
#
475
# Description     : Determine the label that is to be applied to the package
476
#                   There are several cases to consider
477
#                       1) Compatability mode: User provides label
309 dpurdie 478
#                       2) WIP Mode. Determine name of label to use in rename
261 dpurdie 479
#                       3) Create a new label
480
#
481
# Inputs          : Globals
482
#
483
# Returns         : Globals
484
#                       $pkg_label
485
#
486
sub determine_package_label
487
{
488
    #
489
    #   Determine the desired label for the package
490
    #   This is a function of the package name and the package version
491
    #   The two are joined with a '.'
492
    #
263 dpurdie 493
    $tag_label = $opt_pname . '_' . $opt_pversion;
261 dpurdie 494
 
495
    #
496
    #   Ensure that desired label is "free", if not then hunt for a new one
497
    #   Determine the name of a 'new' label
498
    #
499
    my $base_label = $tag_label;
500
    my $index = 0;
501
 
502
    while ( ++$index )
503
    {
504
        if ( $index > 20 )
505
        {
506
            Error ("Cannot determine new label. Retry limit exceeded");
507
        }
508
        Verbose2 ("Trying $tag_label");
509
 
510
        unless (ClearCmd ('describe', '-short', "lbtype:$tag_label" ) )
511
        {
512
            #
513
            #   Label found - so try another
514
            #
515
            Verbose2("Label found. Try another");
516
            $tag_label = $base_label . '.' . $index;
517
            next;
518
        }
519
 
520
        #
521
        #   Warn about non standard label
522
        #
523
        Verbose ("Package will be labeled: $tag_label");
524
        Warning ("Labeling with a non-standard label: $tag_label" )
525
            if ( $index > 1 );
526
        last;
527
    }
528
 
529
    #
530
    #   Free label has been found
531
    #   Create it now, unless we are processing a WIP
532
    #
533
    unless ( $opt_wiplabel )
534
    {
535
        Verbose ("Creating new label: $tag_label");
536
        ClearCmd ('mklbtype', '-c', 'Autobuild Created', $tag_label );
537
        Error ("Cannot create new label: $tag_label" ) if ( @error_list );
538
 
539
        #
540
        #   Mark as created by this utility
541
        #   Label should be deleted on error
542
        #
543
        $label_created = $tag_label;
544
        $pkg_label = $tag_label;
545
    }
546
    else
547
    {
548
        $pkg_label = $opt_wiplabel;
549
    }
550
}
551
 
552
#-------------------------------------------------------------------------------
553
# Function        : label_build_view
554
#
555
# Description     : Label the view
556
#
557
#                   Either:
558
#                       Rename the WIP label to required name
559
#                       Label all files in the view
560
#                   
561
#                   Use JATS to do the hard work
562
#
563
#
564
# Inputs          : Globals
565
#
566
# Returns         : 
567
#
568
sub label_build_view
569
{
570
    if ( $opt_wiplabel )
571
    {
572
        Verbose ("Rename label: From $opt_wiplabel to $tag_label");
309 dpurdie 573
        SystemConfig ( ExitOnError => 2);
261 dpurdie 574
        JatsCmd( 'label', '-unlock', $opt_wiplabel, '-rename', $tag_label, '-lock' );
575
    }
576
    else
577
    {
578
        Verbose ("Apply new label to package: $tag_label");
265 dpurdie 579
 
261 dpurdie 580
        #
265 dpurdie 581
        #   Need to determine the root of the VOB
582
        #   Currently within the VOB.
583
        #   Get the "versioned object base" from clearcase
584
        #   Change to that directory and label the entire subtree
261 dpurdie 585
        #
265 dpurdie 586
        ClearCmd('describe', '-fmt', '%Ln', 'vob:.');
587
        Error ("Program Terminated") if ( @error_list );
588
        Error ("Cannot determine current VOB base" ) unless ( $last_result );
589
        my $vob_base = quotemeta($last_result);
321 dpurdie 590
        Verbose ("VOB Base: $last_result");
261 dpurdie 591
 
265 dpurdie 592
        my $here =  getcwd();
593
        Verbose ("Current dir: $here");
594
 
595
        $here =~ m~^(.*$vob_base)~;
596
        my $base_dir = $1;
597
        Verbose ("Path of base: $base_dir");
598
 
599
        chdir ( $base_dir ) || Error ("Cannot chdir to vob base", $base_dir);
600
 
601
        #
602
        #   Label the entire (static) view
321 dpurdie 603
        #       This will work because this should only be done within a
604
        #       static view based on a single label. Thus the view should
605
        #       contain ony the files that form the current package.
309 dpurdie 606
        #   Handle errors as error exit will clean up
265 dpurdie 607
        #
321 dpurdie 608
        my $rv = JatsCmd( 'label', '-label', $tag_label, '-replace', '-lock' );
309 dpurdie 609
        Error ("Failed to label all files in view")
610
            if ( $rv );
261 dpurdie 611
    }
612
 
613
    #
614
    #   Write the label out to the specified file so that the user
615
    #   can do something with it
616
    #
617
    if ( $opt_infofile )
618
    {
619
 
620
        my $data = JatsProperties::New();
621
 
622
        $data->setProperty('Label', $tag_label);
623
        $data->setProperty('WipLabel', $opt_wiplabel ) if $opt_wiplabel;
624
        $data->setProperty('PackageName', $opt_pname);
625
        $data->setProperty('PackageVersion', $opt_pversion);
626
        $data->setProperty('clearcase.branch', $opt_branch);
627
 
628
        $data->Dump('InfoFile') if ($opt_verbose);
629
        $data->store( $opt_infofile );
630
    }
631
}
632
 
633
#-------------------------------------------------------------------------------
227 dpurdie 634
# Function        : ClearCmd
635
#
265 dpurdie 636
# Description     : Execute a ClearCase command and capture the results
241 dpurdie 637
#                   Errors are held in one array
638
#                   Result are held in another
227 dpurdie 639
#
640
# Inputs          :
641
#
642
# Returns         :
643
#
644
sub ClearCmd
645
{
261 dpurdie 646
    my $cmd = QuoteCommand (@_);
227 dpurdie 647
    Verbose2( "cleartool $cmd" );
648
 
649
        @error_list = ();
241 dpurdie 650
        @last_results = ();
227 dpurdie 651
        $last_result = undef;
652
 
653
        open(CMD, "cleartool $cmd  2>&1 |")    || Error( "can't run command: $!" );
654
        while (<CMD>)
655
        {
656
            chomp;
657
            $last_result = $_;
658
            $last_result =~ tr~\\/~/~s;
241 dpurdie 659
            push @last_results, $last_result;
227 dpurdie 660
 
261 dpurdie 661
            Verbose2 ( "cleartool resp:" . $_);
227 dpurdie 662
            push @error_list, $_ if ( m~Error:~ );
663
        }
664
        close(CMD);
665
 
666
    Verbose2( "Exit Status: $?" );
667
    return $? / 256;
668
}
669
 
670
#-------------------------------------------------------------------------------
671
# Function        : display_error_list
672
#
309 dpurdie 673
# Description     : Display the error list and clean up
227 dpurdie 674
#                   This function is registered as an Error callback function
675
#                   it will be called on error exit
676
#
677
# Inputs          :
678
#
679
# Returns         :
680
#
681
sub display_error_list
682
{
683
    foreach ( @error_list )
684
    {
685
        print "$_\n";
686
    }
309 dpurdie 687
 
688
    #
689
    #   Perform cleanup
690
    #       Delete the label if created it anyway (which we did)
691
    #       This leaves checked in build file on branch (live with it)
692
    #
693
    JatsCmd( 'label', '-delete', $tag_label )
694
        if ($label_created);
695
 
227 dpurdie 696
}
697
 
698
#-------------------------------------------------------------------------------
699
#   Documentation
700
#
701
 
702
=pod
703
 
704
=head1 NAME
705
 
261 dpurdie 706
jats_save_build - Save a build view to version control system
227 dpurdie 707
 
708
=head1 SYNOPSIS
709
 
710
  jats etool jats_save_build [options]
711
 
712
 Options:
261 dpurdie 713
    -help[=n]           - brief help message
227 dpurdie 714
    -help -help         - Detailed help message
261 dpurdie 715
    -man[=n]            - Full documentation
716
    -verbose[=n]        - Verbose operation
717
    -infile=xxx         - Input file (auto.pl)
718
    -outfile=xxx        - Output file (build.pl)
719
    -branch=xxx         - Branch to create (AutoBuilder)
227 dpurdie 720
    -newbranch          - Force file to be on a new (project) branch
261 dpurdie 721
    -infofile=path      - Save label information in 'path'
722
    -pname=name         - Name of the package
723
    -pversion=text      - Package version
724
    -locatepkg=text     - Package locator string
725
    -wiplabel=text      - Current package WIP label
227 dpurdie 726
 
727
=head1 OPTIONS
728
 
729
=over 8
730
 
261 dpurdie 731
=item B<-help[=n]>
227 dpurdie 732
 
733
Print a brief help message and exits.
734
 
261 dpurdie 735
The verbosity of the help text can be controlled by setting the help level to a
736
number in the range of 1 to 3, or by invoking the option multiple times.
227 dpurdie 737
 
261 dpurdie 738
=item B<-man[=n]>
227 dpurdie 739
 
261 dpurdie 740
Without a numeric argument this is the same as -help=3. Full help will be
741
displayed.
227 dpurdie 742
 
261 dpurdie 743
With a numeric argument, this option is the same as -help=n.
227 dpurdie 744
 
261 dpurdie 745
=item B<-verbose[=n]>
746
 
747
This option will increase the level of verbosity of the utility.
748
 
749
If an argument is provided, then it will be used to set the level, otherwise the
750
existing level will be incremented. This option may be specified multiple times.
751
 
752
=item B<-infile=xxxx>
753
 
754
This option specifies the name of the generated build configuration file that
755
will be used as a data-source for the check-in build file.
756
 
757
The default file name is 'auto.pl'.
758
 
759
=item B<-outfile=xxxx>
760
 
761
This option specifies the name of the target build configuration file that
762
will be checked in to version-control. Data from from file specifies with '-
763
infile' will be used to update the file.
764
 
765
The default file name is 'build.pl'.
766
 
767
=item B<-branch=xxxx>
768
 
769
This options specifies the root name of the target branch that will be sued to
770
contain the checked-in build file. If the branch does not exist it will be
771
created.
772
 
773
The default branch will be based on "AutoBuilder".
774
 
227 dpurdie 775
=item B<-newbranch>
776
 
777
This option will force the file to be checked into a new branch
778
The branch will be created on /main/0 unless it is already found elsewhere
779
 
780
This option allows a build.pl file to be placed on a new project branch.
781
 
261 dpurdie 782
=item B<-infofile=path>
783
 
784
This option specifies a file that this utility will use to communicate with a
785
user script. It will write the new label text into the file.
786
 
787
The file path is relative to the current working directory.
788
 
789
The file will be deleted, and only created if the utility is successful.
790
 
791
=item B<-pname=name>
792
 
793
This option specifies the package name. It will be used to construct a new
794
label for the package.
795
 
796
=item B<-pversion=xxx>
797
 
798
This option specifies the package version. It will be used to construct a new
799
label for the package.
800
 
801
=item B<-locatepkg=text>
802
 
803
This option specifies a name, by which the package's build files may be located.
804
This is only needed for JATS builds and will only be used to resolve the
805
location of build files when a package contains multiple build files.
806
 
807
=item B<-wiplabel=text>
808
 
809
This option controls the manner in which this utility will label the build view.
810
 
811
If present, the label specifies a 'Work In Progress' label. The label will be
812
renamed.
813
 
814
If not present, then the view will be labeled with a new label.
815
 
227 dpurdie 816
=back
817
 
818
=head1 DESCRIPTION
819
 
261 dpurdie 820
This utility is used by the automated build system to place build view under
821
version control. The utility will:
227 dpurdie 822
 
261 dpurdie 823
=over 8
227 dpurdie 824
 
261 dpurdie 825
=item * Determine a suitable label for the package
227 dpurdie 826
 
261 dpurdie 827
The label is constructed from the package name and the package version. The
828
utility will ensure that the label does not already exist. If it does it will
829
use an alternate form of the label.
830
 
831
=item * Determine a suitable branch name for the build files
832
 
833
The modified build file is placed on a file-branch.
834
 
835
=item * Locate the build files within the package
836
 
837
JATS build files do not need to be at the root of the package. The utility
838
will locate the JATS build files.
839
 
840
=item * Update the build files and save them into the version control system
841
 
842
The build file will be updated with new version information as provided by a
843
secondary configuration file.
844
 
845
The updated file will be checked into version control. It will be placed on a
846
branch so as not to affect dynamic views.
847
 
227 dpurdie 848
The operation will fail if that file is checked out "reserved". The program
849
can work around this - but its not done yet.
850
 
261 dpurdie 851
If the build file is sourced from a different branch then a Merge arrow
852
will be created to indicate where the file and its label was taken from.   
853
 
854
=item * Ensure that the package is labeled
855
 
856
The build view will be labeled.
857
 
858
If a WIP label is provided then the label will be applied to the modified
859
build file and then the label will be renamed.
860
 
861
If a WIP label is not provided, then the entire package will be labeled with a
862
suitable label.
863
 
864
=item * Return the label to the user
865
 
866
The label used to label the package will be returned to the user in an 'info'
867
file. This is a 'properties' file. The following properties are defined:
868
 
869
=over 8
870
 
871
=item   1) Label - The label used to tag the file
872
 
873
=item   3) WipLabel - The WIP label provided (optional)
874
 
875
=item   4) PackageName - The package name
876
 
877
=item   5) PackageVersion - The package version
878
 
879
=back
880
 
881
=back
882
 
227 dpurdie 883
=cut
884