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_label.pl
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s):
9
#
10
# Description   : A script to perform a number of labeling operations
11
#                 The script will:
12
#                   create a label
13
#                   lock a label
14
#                   unlock a label
15
#                   label all files below the current directory and
16
#                         all directories above the current directory
17
#
18
# Version   Who      Date        Description
19
# 1.0.0     DDP      04-Feb-05   Created
20
#......................................................................#
21
 
22
require 5.6.1;
23
use strict;
24
use warnings;
25
use JatsError;
26
use JatsSystem;
27
 
28
use Pod::Usage;                             # required for help support
29
use Getopt::Long;
30
use Cwd;
31
 
32
my $VERSION = "1.2.2";                      # Update this
33
 
34
#
35
#   Options
36
#
37
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
38
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
39
my $opt_help = 0;
40
my $opt_manual = 0;
41
my $opt_label;
42
my $opt_replace;
43
my $opt_create;
44
my $opt_lock;
45
my $opt_unlock;
46
my $opt_show;
47
my $opt_all;
48
my $opt_remove;
49
my $opt_delete;
50
my @opt_exclude;
51
my $opt_test;
52
my $opt_rename;
53
my $opt_auto;
54
my $opt_clone;
55
my $opt_recurse = 1;
56
my $opt_mine;
57
my $opt_info;
58
my $opt_up = 0;
59
my $opt_smartlock;
60
my $opt_checkout = 2;
61
my @opt_files;
62
my @opt_dirs;
63
my $opt_comment;
64
my $opt_vob;
65
my $opt_user;
66
 
67
my $label;
68
my $user_cwd;
69
my @error_list;
70
my $last_result;
71
my $opr_done;
72
my $label_exists = 0;
73
my $build_count = 0;
74
my $vob_desc ='';
75
 
76
#
77
#   Globals
78
#
79
my $USER = $ENV{'USER'};
80
my $UNIX = $ENV{'GBE_UNIX'};
81
my $autobuild = $ENV{'GBE_ABT'};
82
my $UNIX_VOB_PREFIX = '/vobs';
83
my $VOB_SEP = $UNIX ? '/' : '\\';
84
 
85
#-------------------------------------------------------------------------------
86
# Function        : Mainline Entry Point
87
#
88
# Description     :
89
#
90
# Inputs          :
91
#
92
my $result = GetOptions (
93
                "help+"         => \$opt_help,              # flag, multiple use allowed
94
                "manual"        => \$opt_manual,            # flag
95
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
96
                "label"         => \$opt_label,             # Flag
97
                "replace"       => \$opt_replace,           # Flag
98
                "create"        => \$opt_create,            # Flag
99
                "lock"          => \$opt_lock,              # Flag
100
                "unlock"        => \$opt_unlock,            # Flag
101
                "smartlock"     => \$opt_smartlock,         # Flag
102
                "show"          => \$opt_show,              # Flag
103
                "remove"        => \$opt_remove,            # Flag
104
                "delete"        => \$opt_delete,            # Flag
105
                "all"           => \$opt_all,               # Flag
106
                "test"          => \$opt_test,              # Flag
107
                "exclude=s"     => \@opt_exclude,           # Multiple strings
108
                "rename=s"      => \$opt_rename,            # String
109
                "clone=s"       => \$opt_clone,             # String
110
                "auto"          => \$opt_auto,              # Flag
111
                "recurse!",     => \$opt_recurse,           # [No]Flag
112
                "mine!",        => \$opt_mine,              # Flag
113
                "info",         => \$opt_info,              # Flag
114
                "up",           => \$opt_up,                # Flag
115
                "checkout!",    => \$opt_checkout,          # [No]Flag
116
                "files=s"       => \@opt_files,             # Multiple strings
117
                "dirs=s"        => \@opt_dirs,              # Multiple strings
118
                "comment=s"     => \$opt_comment,           # String
119
                "vob=s"         => \$opt_vob,               # String
120
                "user=s"        => \$opt_user,              # String
121
 
122
                );
123
 
124
                #
125
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
126
                #
127
 
128
#
129
#   Process help and manual options
130
#
131
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
132
pod2usage(-verbose => 1) if ($opt_help == 2 );
133
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
134
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 0 );
135
 
136
#
137
#   Configure the error reporting process now that we have the user options
138
#
139
ErrorConfig( 'name'    =>'LABEL',
140
             'verbose' => $opt_verbose,
141
             'on_exit' => \&display_error_list
142
            );
143
 
144
#
145
#   Validate user options
146
#   Use either -spec or one command line argument
147
#
148
Error ("No labels provided") if ( $#ARGV < 0);
149
Error ("Too many labels provided") if ( $#ARGV > 0);
150
Error ("Conflicting options") if ( $opt_clone && $opt_label );
151
$label = $ARGV[0];
152
 
153
#
154
#   Allow the exclude list to contain comma seperated names
155
#
156
@opt_exclude = split( /,/,join(',',@opt_exclude));
157
@opt_files   = split( /,/,join(',',@opt_files));
158
@opt_dirs    = split( /,/,join(',',@opt_dirs));
159
 
160
#
161
#   Determine the user
162
#
163
Error ("USER name not determined" )
164
    unless ( $USER );
165
$opt_user = $USER unless ( $opt_user );
166
 
167
#
168
#   Ensure that the 'cleartool' program can be located
169
#
170
Verbose ("Locate clearcase utility in users path");
171
Error ("Cannot locate the 'cleartool' utility in the users PATH")
172
    unless ( LocateProgInPath('cleartool', '--All') );
173
 
174
#-------------------------------------------------------------------------------
175
#   Construct a vob descriptor, if required
176
#
177
if ( $opt_vob )
178
{
179
    Error ("-vob option cannot be used with this command")
180
        if ( $opt_clone || $opt_label || $opt_show || $opt_remove  );
181
 
182
    $vob_desc = $UNIX_VOB_PREFIX if ( $UNIX );
183
    $vob_desc = '@/' . $vob_desc . '/' . $opt_vob;
184
    $vob_desc =~ s~//~/~g;
185
    $vob_desc =~ s~/~$VOB_SEP~g;
186
}
187
 
188
#-------------------------------------------------------------------------------
189
#   Check to see if the clone source label exists
190
#       Create a label
191
#
192
if ( $opt_clone )
193
{
194
    Verbose ("Check clone label");
195
    ClearCmd ("describe", "-short", "lbtype:$opt_clone" );
196
    Error ("Clone source label does not exist") if ( @error_list );
197
}
198
 
199
#-------------------------------------------------------------------------------
200
#   Check to see if the label exists
201
#
202
Verbose ("Check label");
203
ClearCmd ("describe", "-short", "lbtype:$label$vob_desc" ) unless $opt_test;
204
$label_exists = 1 unless( $opt_test || grep ( /Label type not found/, @error_list ));
205
Verbose ("Check label: $label_exists");
206
 
207
 
208
#-------------------------------------------------------------------------------
209
#   Process command
210
#       Create a label
211
#
212
if ( $opt_create || ( $opt_auto && ! $label_exists    ) )
213
{
214
    Verbose ("Create label");
215
    Error ("Label already exists") if ( $label_exists );
216
 
217
    my $opts = '-nc';
218
    $opts = '-c "' . $opt_comment . '"' if ( $opt_comment );
219
 
220
    ClearCmd ("mklbtype", $opts, "$label$vob_desc" ) unless $opt_test;
221
    Error ("Program Terminated") if ( @error_list );
222
    $opr_done = 1;
223
}
224
 
225
#-------------------------------------------------------------------------------
226
#   Ensure that the specified label exists
227
#
228
    Verbose ("Check label");
229
    ClearCmd ("describe", "-short", "lbtype:$label$vob_desc" ) unless $opt_test;
230
    Error ("Program Terminated") if ( @error_list );
231
 
232
#-------------------------------------------------------------------------------
233
#   Process command
234
#       Unlock a label - if it was locked
235
#
236
if ( $opt_unlock || $opt_smartlock )
237
{
238
    Verbose ("Unlock label");
239
 
240
    ClearCmd ("describe", "-fmt", "%[locked]p", "lbtype:$label$vob_desc" );
241
    unless ( $last_result && $last_result =~ m~unlocked~ )
242
    {
243
        ClearCmd ("unlock", "lbtype:$label$vob_desc" ) unless $opt_test;
244
        Error ("Program Terminated") if ( @error_list );
245
        $opt_lock = 1 if ( $opt_smartlock );
246
    }
247
    $opr_done = 1;
248
}
249
 
250
#-------------------------------------------------------------------------------
251
#   Process command
252
#       Rename a label
253
if ( $opt_rename )
254
{
255
    Verbose ("Rename label");
256
    ClearCmd ("rename", "lbtype:$label$vob_desc", "lbtype:$opt_rename$vob_desc" ) unless $opt_test;
257
    Error ("Program Terminated") if ( @error_list );
258
    $label = $opt_rename;
259
 
260
    #
261
    #   Also rename the owner of the label
262
    #   This facility is used by the build process to rename WIP labels
263
    #   The idea is to prevent the original owner from modifying the label
264
    #
265
    $opt_mine = 1
266
        if ( $opt_mine && ($opt_mine != 0) );
267
 
268
    $opr_done = 1;
269
}
270
 
271
#-------------------------------------------------------------------------------
272
#   Change label ownership
273
#
274
if ( $opt_mine )
275
{
276
    Verbose ("Change label owner: $opt_user");
277
    ClearCmd ("protect", "-chown", $opt_user, "lbtype:$label$vob_desc" ) unless $opt_test;
278
    Error ("Program Terminated") if ( @error_list );
279
 
280
    $opr_done = 1;
281
}
282
 
283
#-------------------------------------------------------------------------------
284
#   Process command
285
#       Label files and directories
286
 
287
if ( $opt_label || ( $opt_auto && ! $opt_clone ) )
288
{
289
    Verbose ("Label files and directories");
290
    my $element0_count = 0;
291
    my $label_error = 0;
292
    my @label_these;
293
    my @check_these;
294
    my @parent_list;
295
    my $checked_out_count_dir = 0;
296
    my $checked_out_count = 0;
297
    my $missing_file_count = 0;
298
    my $is_symlink;
299
    my @cmd_opt;
300
    push @cmd_opt, "-replace" if ( $opt_replace );
301
 
302
    #
303
    #   Figure out what to do
304
    #       Label dirs upwards if requested, or we are not doing files or dirs
305
    #       Label the current directory unless asked to do files/dirs or up-only
306
    #
307
    my $do_files = scalar @opt_files;
308
    my $do_dirs = scalar @opt_dirs;
309
    my $do_up = $opt_up || ( ! $do_files && ! $do_dirs );
310
    push @opt_dirs, '.' unless ($opt_up || $do_files || $do_dirs);
311
 
312
 
313
    #
314
    #   Build up a list of parent directories up to the root of the VOB
315
    #   that do not have the desired label
316
    #
317
    if ( $do_up )
318
    {
319
        Verbose ("Examine parent directories");
320
 
321
        my $path = getcwd();
322
        while ( 1 )
323
        {
324
            my $cmd = QuoteCommand ("cleartool", "describe", $path);
325
            my $has_label;
326
            my $is_versioned;
327
            my $start_labels;
328
            my $link;
329
            my $is_checkedout;
330
 
331
            Verbose($cmd);
332
            open(CMD, "$cmd 2>&1 |") || Error( "Can't run command: $!");
333
            while (<CMD>)
334
            {
335
                #
336
                #   Filter output from the user
337
                #
338
                chomp;
339
                Verbose2($_);
340
                push @error_list, $_ if ( m~Error:~ );
341
                $link = $1 if ( m~^symbolic link.* -> (.*)~ );
342
                $is_versioned = 1 if ( m~^directory version ~ );
343
                $start_labels = 1 if ( m~^\s+Labels:$~ );
344
                $is_checkedout = 1 if ( m~[\\/]CHECKEDOUT"~ );
345
                next unless ( $start_labels );
346
                $has_label = 1 if ( m~^\s+$label$~ );
347
            }
348
            close(CMD);
349
 
350
            #
351
            #   Symbolic link located
352
            #   Resolve the link and continue
353
            #   The link cannot be labeled. If we can label the resolved link then
354
            #   all is good, otherwise we have a a problem
355
            #
356
            if ( $link )
357
            {
358
                $is_symlink = 1;
359
                $path =~ s~[/][^/]*$~~;
360
                $path = $path . '/' . $link;
361
                $path =~ s~/[^/]+/\.\./~/~;
362
                Verbose("Symbolic link: $link, Path: $path" );
363
                next;
364
            }
365
 
366
            #
367
            #   Parent directory checked out. Options:
368
            #       0: Don't Label checkedout elements
369
            #       1: Do Label only checkout elements
370
            #       2: Label both
371
            #
372
            if ( $is_checkedout )
373
            {
374
                next find if ( $opt_checkout == 0 );
375
                $checked_out_count_dir++;
376
            }
377
            else
378
            {
379
                next find if ( $opt_checkout == 1 );
380
            }
381
 
382
            last unless ( $is_versioned );
383
            push @parent_list, $path unless ( $has_label );
384
 
385
            #
386
            #   Versioned directory seen
387
            #   If the previous one loop was a symlink, then we have labeled
388
            #   the link correctly
389
            #
390
            $is_symlink = 0;
391
 
392
            #
393
            #   Calculate the path of the parent directory
394
            #   Stop when we get to the top ( ie z: is not good )
395
            #
396
            last unless ($path =~ s~[/][^/]*$~~);
397
            last unless ( $path =~ m~/~ );
398
        }
399
        Verbose ("parent directories to label: @parent_list");
400
 
401
        #
402
        #   Label all the parent directories
403
        #
404
        if ( @parent_list )
405
        {
406
            foreach ( @parent_list )
407
            {
408
                print "Label: $_\n";
409
            }
410
 
411
            ClearCmd ("mklabel", @cmd_opt, $label, @parent_list ) unless $opt_test;
412
            if ( @error_list )
413
            {
414
                display_error_list();
415
                @error_list = ();
416
                $label_error = 1;
417
            }
418
        }
419
    }
420
 
421
    if ( @opt_files )
422
    {
423
        my $file_error;
424
        #
425
        #   Process the user specified list of files
426
        #
427
        Verbose ("Examine specified files");
428
        foreach my $file ( @opt_files )
429
        {
430
            ClearCmd ("describe", "-short", $file );
431
            if ( @error_list )
432
            {
433
                display_error_list();
434
                @error_list = ();
435
                $file_error++;
436
                next;
437
            }
438
            push @check_these, $last_result;
439
        }
440
        Error ("Program Terminated") if ( $file_error );
441
 
442
    }
443
 
444
    foreach my $dir ( @opt_dirs )
445
    {
446
        #
447
        #   Label everything in and below the current directory
448
        #   Be smart and only attempt to label stuff that does not have a label
449
        #
450
 
451
        #
452
        #   Remove possible trailing / from user specified directory as
453
        #   clearcase doesn't handle these too well.
454
        #
455
        $dir =~ tr~\\/~/~s;
456
        $dir =~ s~/+$~~;
457
        $dir = '/' unless ( $dir );
458
 
459
        Verbose ("Examine subdirectory: $dir");
460
        my $find_arg = $opt_recurse ? '' : '-nrecurse ';
461
        my $cmd = QuoteCommand ("cleartool", "find", "$dir", "-cview", $find_arg, "-version", "{!lbtype($label)}", "-print");
462
        Verbose2($cmd);
463
 
464
        open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
465
        while (<CMD>)
466
        {
467
            #
468
            #   Filter output from the user
469
            #
470
            chomp;
471
            Verbose2($_);
472
            if ( m~Error:~ )
473
            {
474
                #
475
                #   In AutoBuild Mode allow the error "Not a vob object"
476
                #   This may be cause by generated directory that has been checked in
477
                #   If the directory gets re-generated then the Find gets confused.
478
                #
479
                if ( $autobuild && m~Not a vob object:~ )
480
                {
481
                    Warning( "AutoBuildTool surpessed: $_" );
482
                    next;
483
                }
484
                push @error_list, $_;
485
                next;
486
            }
487
            push @check_these, $_;
488
        }
489
        close(CMD);
490
        Error ("Program Terminated") if ( @error_list );
491
    }
492
 
493
    #
494
    #   Have a list of files to examine to see if we really want to label them
495
    #
496
    find:
497
    foreach ( @check_these )
498
    {
499
        ( my $file = $_ ) =~ s~@@.*~~;
500
 
501
        #
502
        #   If we are not recursing - then skip directories
503
        #
504
        next find
505
            if ( ! $opt_recurse  && -d $file );
506
 
507
        tr~\\/~/~s;
508
 
509
        #
510
        #   Exclude files and directories that are the /main/0 element
511
        #   These may be in a view due to branching rules
512
        #   The contents will be empty. Labeling them will create uglyness
513
        #   it simplifies life if we don't label them
514
        #
515
        if ( m~/main/0$~ )
516
        {
517
            $element0_count++;
518
            print "Exclude(/main/0): $_\n";
519
            next find;
520
        }
521
 
522
        #
523
        #   Has it been excluded
524
        #
525
        foreach my $name ( @opt_exclude )
526
        {
527
            if ( m~/$name[/@]~ )
528
            {
529
                print "Exclude: $_\n";
530
                next find;
531
            }
532
        }
533
 
534
        #
535
        #   Ensure that the file is really present
536
        #   In a static sandbox CC retains memory of files that have been
537
        #   deleted. This may be intentional it may be an error
538
        #
539
        if ( ! -e $file && ! $opt_all )
540
        {
541
            print ("WARNING: File missing from view. Not labeled: $file \n");
542
            $missing_file_count++;
543
            next find;
544
        }
545
 
546
        #
547
        #   Count build.pl files
548
        #
549
        if ( m~/build.pl@~i )
550
        {
551
            $build_count++;
552
        }
553
 
554
        #
555
        #   Handle Checked out files
556
        #
557
        if ( m/CHECKEDOUT$/ )
558
        {
559
            next find if ( $opt_checkout == 0 );
560
            $checked_out_count++;
561
        }
562
        else
563
        {
564
            next find if ( $opt_checkout == 1 );
565
        }
566
 
567
        push @label_these, $_ ;
568
 
569
    }
570
 
571
    if ( @label_these )
572
    {
573
        foreach ( @label_these)
574
        {
575
            print "Label: $_\n";
576
        }
577
 
578
        #
579
        #   Process the labels in groups
580
        #   The command line does have a finite length
581
        #
582
        my $base = 0;
583
        my $num = $#label_these;
584
 
585
        while ( $base <= $num )
586
        {
587
            my $end = $base + 10;
588
            $end = $num if ( $end > $num );
589
 
590
            print ".";
591
            ClearCmd ("mklabel", @cmd_opt, $label, @label_these[$base .. $end] ) unless ( $opt_test );
592
            if ( @error_list )
593
            {
594
                display_error_list();
595
                $label_error = 1;
596
                @error_list = ();
597
            }
598
 
599
            $base = $end + 1;
600
        }
601
        print "\n";
602
    }
603
 
604
    print "Labels applied: ". (scalar(@label_these) + scalar(@parent_list))  ."\n";
605
    print "WARNING: Labels applied to checked out parent directories: $checked_out_count_dir\n" if ( $checked_out_count_dir );
606
    print "WARNING: Labels applied to checked out files: $checked_out_count\n" if ( $checked_out_count );
607
    print "WARNING: Labels NOT applied to missing files: $missing_file_count\n" if ( $missing_file_count );
608
    print "WARNING: Labels NOT applied to element-0 of files: $element0_count\n" if ( $element0_count );
609
    print "WARNING: Path to the VOB root contains a symbolic link. Labeling incomplete.\n" if ( $is_symlink );
610
    print "WARNING: Multiple build.pl files labeled: $build_count.\n" if ( $build_count > 1 );
611
 
612
    Error ("Program Terminated") if ( $label_error );
613
 
614
    $opr_done = 1;
615
}
616
 
617
#-------------------------------------------------------------------------------
618
#   Process command
619
#       Clone
620
if ( $opt_clone )
621
{
622
    Verbose ("Clone Label");
623
    my @cmd_opt;
624
    push @cmd_opt, "-all" if ($opt_all);
625
 
626
    my @cmd2_opt;
627
    push @cmd2_opt, "-replace" if ( $opt_replace );
628
 
629
    my $count = 0;
630
    my $checked_out_count = 0;
631
 
632
    my $cmd = QuoteCommand ("cleartool", "find", ".", @cmd_opt, "-version", "lbtype($opt_clone)", "-print");
633
    Verbose2($cmd);
634
 
635
    open(CLONECMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
636
    while (<CLONECMD>)
637
    {
638
        chomp;
639
        print($_ . "\n");
640
        $count++;
641
        $checked_out_count++ if ( m/CHECKEDOUT$/ );
642
 
643
        ClearCmd ("mklabel", @cmd2_opt, $label, $_ ) unless ( $opt_test );
644
        last if ( @error_list )
645
    }
646
    close(CLONECMD);
647
 
648
    Error ("Program Terminated") if ( @error_list );
649
    print "Labels applied: $count\n";
650
    print "WARNING: Labels applied to checked out files: $checked_out_count\n" if ( $checked_out_count );
651
    $opr_done = 1;
652
}
653
 
654
 
655
#-------------------------------------------------------------------------------
656
#   Process command
657
#       Show labeled files and directories
658
#       Remove labels
659
 
660
if ( $opt_show || $opt_remove )
661
{
662
    Verbose ("Show Label");
663
    my @cmd_opt;
664
    push @cmd_opt, "-all" if ($opt_all);
665
 
666
    my $cmd = QuoteCommand("cleartool", "find", ".", @cmd_opt, "-version", "lbtype($label)", "-print");
667
    Verbose2($cmd);
668
 
669
    open(SHOWCMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
670
    while (<SHOWCMD>)
671
    {
672
        #
673
        #   Filter output from the user
674
        #
675
        chomp;
676
        print($_ . "\n");
677
 
678
        if ( $opt_remove )
679
        {
680
            ClearCmd ( "rmlabel", $label, $_ ) unless $opt_test;
681
        }
682
 
683
    }
684
    close(SHOWCMD);
685
    $opr_done = 1;
686
}
687
 
688
#-------------------------------------------------------------------------------
689
#   Process command
690
#       Delete a label
691
if ( $opt_delete )
692
{
693
    Verbose ("Delete label");
694
    ClearCmd ("rmtype", "-force", "-rmall", "lbtype:$label$vob_desc" ) unless $opt_test;
695
    Error ("Program Terminated") if ( @error_list );
696
    $opr_done = 1;
697
}
698
 
699
#-------------------------------------------------------------------------------
700
#   Process command
701
#       Lock a label - if not already locked
702
if ( $opt_lock )
703
{
704
    Verbose ("Lock label");
705
    ClearCmd ("describe", "-fmt", "%[locked]p", "lbtype:$label$vob_desc" );
706
    if ( $last_result =~ m~unlocked~ )
707
    {
708
        ClearCmd ("lock", "lbtype:$label$vob_desc" ) unless $opt_test;
709
        Error ("Program Terminated") if ( @error_list );
710
    }
711
    $opr_done = 1;
712
}
713
 
714
#-------------------------------------------------------------------------------
715
#   Process command
716
#       Display Label information
717
if ( $opt_info )
718
{
719
    Verbose ("describe label");
720
    system (QuoteCommand("cleartool", "describe", "-long", "lbtype:$label$vob_desc" )) unless $opt_test;
721
    Error ("Program Terminated") if ( @error_list );
722
    $opr_done = 1;
723
}
724
 
725
 
726
Error ("No valid operations specified. Try -h") unless ( $opr_done );
727
if ( $opt_test )
728
{
729
    print ("End program [Test Mode]\n");
730
}
731
else
732
{
733
    print ("End program\n");
734
}
735
 
736
exit 0;
737
 
738
 
739
#-------------------------------------------------------------------------------
740
# Function        : display_error_list
741
#
742
# Description     : Display the error list
743
#                   This function is registered as an Error callback function
744
#                   it will be called on error exit
745
#
746
# Inputs          :
747
#
748
# Returns         :
749
#
750
sub display_error_list
751
{
752
    foreach ( @error_list )
753
    {
754
        print "$_\n";
755
    }
756
}
757
 
758
#-------------------------------------------------------------------------------
759
# Function        : ClearCmd
760
#
761
# Description     : Similar to the system command
762
#                   Does allow standard output and standard error to be captured
763
#                   to a log file
764
#
765
#                   Used since I was having problems with calling other programs
766
#                   and control-C. It could hang the terminal session.
767
#
768
# Inputs          :
769
#
770
# Returns         :
771
#
772
sub ClearCmd
773
{
774
    my $cmd = QuoteCommand (@_);
775
    Verbose2 "cleartool $cmd";
776
 
777
        @error_list = ();
778
        open(CMD, "cleartool $cmd  2>&1 |")    || Error "can't run command: $!";
779
        while (<CMD>)
780
        {
781
            chomp;
782
            $last_result = $_;
783
            Verbose ( "cleartool resp:" . $_);
784
            push @error_list, $_ if ( m~Error:~ );
785
        }
786
        close(CMD);
787
 
788
    Verbose2 "Exit Status: $?";
789
    return $? / 256;
790
}
791
 
792
#-------------------------------------------------------------------------------
793
#   Documentation
794
#
795
 
796
=pod
797
 
798
=head1 NAME
799
 
800
jats_label - Clearcase label operations
801
 
802
=head1 SYNOPSIS
803
 
804
jats label [options] C<label>
805
 
806
 Options:
807
    -help              - brief help message
808
    -help -help        - Detailed help message
809
    -man               - Full documentation
810
    -auto              - Auto create and label
811
    -clone=xxx         - Apply new label to objects with label xxx
812
    -create            - Create a label
813
    -label             - Labels a directory tree
814
    -lock              - Lock the label
815
    -remove            - Remove label from elements
816
    -delete            - Delete label label from elements and vob
817
    -rename=xxx        - Rename a label
818
    -show              - Show elements with the label
819
    -unlock            - Unlock the label
820
    -[no]mine          - Set label owner to user.
821
    -info              - Provide label information
822
    -smartlock         - Unlock and Relock label, if it was locked
823
 
824
 Modifiers
825
    -all               - Process all the VOB. Use with -show and -remove.
826
    -replace           - Replace existing labels. Use with -label
827
    -exclude=n1,n2     - Exclude files and directories from the -label process.
828
    -files=f1,f2,...   - Label only the named files.
829
    -dirs=d1,d2,...    - Label only the named dirs.
830
    -[no]recurse       - Exclude all subdirectories from the -label process.
831
    -[no]checkout      - Don't/Do label checked out files. Default - label both
832
    -up                - Only label directories upwards. Do not label files/dirs
833
    -test              - Just show the labels that would be added.
834
    -comment=text      - Comment to add to label when created.
835
    -user=name         - Used with -mine to specify user
836
    -vob=name          - Specify VOB name when manipulating label.
837
                         Not allowed with -label, -clone, -remove and -show
838
 
839
=head1 OPTIONS
840
 
841
=over 8
842
 
843
=item B<-help>
844
 
845
Print a brief help message and exits.
846
 
847
=item B<-help -help>
848
 
849
Print a detailed help message with an explanation for each option.
850
 
851
=item B<-man>
852
 
853
Prints the manual page and exits.
854
 
855
=item B<-all>
856
 
857
This option modifies the operation of the -show, -remove and -label operations.
858
 
859
With this option the processing extends to the entire VOB. This is a slower, but
860
more complete operation.
861
 
862
With this option the -label will label files that are not currently present in a
863
static view.
864
 
865
=item B<-auto>
866
 
867
This option will create the label if the label does not exist and then label the
868
current directory.
869
 
870
This option is a combination of a -create and a -label, except that it will
871
not fail if the label already exists.
872
 
873
=item B<-clone=xxx>
874
 
875
This option will apply a new label to all objects that have the label xxx.
876
The effect is that the specified label is clone of label xxx.
877
 
878
This operation may be used to initiate a new build label by first cloning an
879
existing build before tailoring the file set.
880
 
881
=item B<-create>
882
 
883
This option will create the specified label. The operations will fail if the
884
label is already present in the current VOB.
885
 
886
The label will be created in the current VOB with a comment if one is provided.
887
 
888
=item B<-delete>
889
 
890
This option will delete the specified label from all objects with the label
891
and remove the label from the VOB. You need to be the owner of this label in
892
order for the operation to occur without error.
893
 
894
=item B<-exclude name>
895
 
896
Exclude specific files and directories from the labeling process.
897
 
898
The names may be comma separated, or the option may be specified multiple times.
899
 
900
Wildcards are supported in the form of regular expressions. All .h
901
files may be excluded with the command "-exclude=.*\.h".
902
 
903
examples:
904
    -exclude=test will exclude all directory trees called test
905
 
906
    -exclude=test,play will exclude all directory trees called 'test' and 'play'
907
 
908
    -exclude=test/seattle will exclude all directory trees called test/seattle
909
 
910
=item B<-files=name>
911
 
912
Label only the specified files. The names may be comma separated, or the option
913
may be specified multiple times.
914
 
915
The use of this option overrides the default operation of the label utility
916
and the entire file tree will not be scanned. Only the specified files will be
917
labeled.
918
 
919
Wildcards are not supported.
920
 
921
Directories will not be recursed, but may be labeled.
922
 
923
=item B<-dirs=name>
924
 
925
Label only the specified directories. The names may be comma separated, or the
926
option may be specified multiple times.
927
 
928
The use of this option overrides the default operation of the label utility
929
and the entire file tree will not be scanned. Only the specified directories
930
will be labeled.
931
 
932
Wildcards are not supported.
933
 
934
=item B<-label>
935
 
936
This option will label all the files in, and below, the current directory and
937
all the parent directories.
938
 
939
The -replace option may be used to force labels to be moved.
940
 
941
The -norecurse option may be used to prevent recursion into all subdirectories,
942
and the labeling of any directories.
943
 
944
=item B<-lock>
945
 
946
This option will lock the specified label. This operation will be done after any
947
other operations have been performed.  If the label is already locked then
948
this operation will not attempt to lock the label.
949
 
950
=item B<-remove>
951
 
952
This option will remove the specified label from all objects with the label.
953
 
954
If the -all option is present then all elements in the entire VOB will be
955
examined, otherwise just this in and below the current directory will be
956
examined.
957
 
958
The -all operation may take some time.
959
 
960
=item B<-rename=xxx>
961
 
962
This option will rename a label. The new name of the label is provided as the
963
argument after the option. If any further operation are to be performed the
964
new label name will be used.
965
 
966
By default, the owner of the label will be set to the current user. This
967
mechanism is used in the build process. This -nomine option changes this
968
behaviour.
969
 
970
=item B<-replace>
971
 
972
This option may be used with the -label command to force labels to be moved to
973
the file or directory in the current view.
974
 
975
=item B<-[no]recurse>
976
 
977
This option modifies the behaviour of the B<-label> operation. The default
978
behaviour is to label all files and directories in and below the current
979
directory.
980
 
981
The B<-norecurse> option prevents recursion into subdirectories and the labeling
982
of subdirectories. Only files in the current directory will be labeled. -
983
together with parent directories as required.
984
 
985
=item B<-show>
986
 
987
This operation will show all clearcase elements with the specified label.
988
 
989
If the -all option is present then all elements in the entire VOB will be shown,
990
otherwise just this in and below the current directory will be displayed.
991
 
992
The -all operation may take some time.
993
 
994
=item B<-test>
995
 
996
This operation will prevent the program from performing any destructive
997
operation. It may be used to show what operation would be done.
998
 
999
=item B<-unlock>
1000
 
1001
This option will unlock the specified label. This operation will be done before
1002
any other operations have been performed.  If the label is not locked then
1003
this operation will not attempt to unlock the label.
1004
 
1005
=item B<-[no]mine>
1006
 
1007
This option will set the owner of the label to the current user. This
1008
operation is performed automatically when a -rename operation occurs. The
1009
"no" option allows this behaviour to be modified.
1010
 
1011
=item B<-up>
1012
 
1013
This option will prevent the utility for labeling files and directories below
1014
the current directory. Only directories above the current directory will be
1015
labeled.
1016
 
1017
This option may be specifically used with -dirs and -files to label the named
1018
directories and files as well as the directoires up, from the current directory.
1019
 
1020
=item B<-info>
1021
 
1022
This option will provide label information. It uses the clearcase describe
1023
command.
1024
 
1025
=item B<-smartlock>
1026
 
1027
This option will unlock the label for the duration of the operations and then
1028
lock the label again - if it was locked to start with. Smart locking allows
1029
label operations while retaining the lock state of the label.
1030
 
1031
=item B<-[no]checkout>
1032
 
1033
This option affects the processing of checked out files. There are three modes of
1034
operation.:
1035
 
1036
    1) -nocheckout      Checked out files are not labeled
1037
    2) -checkout        Only checked out files are labeled
1038
    3) Neither          All files are labeled.
1039
 
1040
=item B<-comment=text>
1041
 
1042
This option allows a comment to be added to a label when it is created. The
1043
option has no effect if the label is not created.
1044
 
1045
=item B<-vob=name>
1046
 
1047
This option is used by commands that do not acutally place labels on files to
1048
manipulate when the user's current directry is not within a view. This allows lables to be created,
1049
locked and unlocked without having a view present.
1050
 
1051
=back
1052
 
1053
=head1 DESCRIPTION
1054
 
1055
This program provides a number of useful ClearCase labeling operations. These
1056
are:
1057
 
1058
=over 8
1059
 
1060
=item   create - create a label
1061
 
1062
=item   unlock - unlock the specified label
1063
 
1064
=item   rename - rename a label
1065
 
1066
=item   mine - change ownership of a label
1067
 
1068
=item   label - label a directory tree
1069
 
1070
=item   remove - remove the label from all labeled objects
1071
 
1072
=item   show - show all objects tagged with the label
1073
 
1074
=item   lock - lock a label
1075
 
1076
=item   delete - delete all instances of a label and the label
1077
 
1078
=item   info - describe the labels properties
1079
 
1080
=back
1081
 
1082
The various operations may be mixed in the one command. The order of the
1083
operations is: create, unlock, rename, mine, label, show, remove, delete, lock
1084
and info.
1085
 
1086
Thus it is possible to create a label, label a directory tree and then lock the
1087
label.
1088
 
1089
=head1 EXAMPLE
1090
 
1091
jats label -create -label -lock daf_br_23.0.0.syd
1092
 
1093
=cut
1094