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