Subversion Repositories DevTools

Rev

Rev 329 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 329 Rev 331
Line 61... Line 61...
61
my @opt_dirs;
61
my @opt_dirs;
62
my $opt_comment;
62
my $opt_comment;
63
my $opt_vob;
63
my $opt_vob;
64
my $opt_user;
64
my $opt_user;
65
my $opt_admin_vob;
65
my $opt_admin_vob;
-
 
66
my $opt_entire_view;
66
 
67
 
67
my $label;
68
my $label;
68
my $user_cwd;
69
my $user_cwd;
69
my @error_list;
70
my @error_list;
-
 
71
my @last_results;
70
my $last_result;
72
my $last_result;
71
my $opr_done;
73
my $opr_done;
72
my $label_exists = 0;
74
my $label_exists = 0;
73
my $label_is_locked = 0;
75
my $label_is_locked = 0;
74
my $build_count = 0;
76
my $build_count = 0;
75
my $vob_desc ='';
77
my $vob_desc ='';
-
 
78
my $vob_base;
76
 
79
 
77
#
80
#
78
#   Globals
81
#   Globals
79
#
82
#
80
my $USER = $ENV{'USER'};
83
my $USER = $ENV{'USER'};
Line 118... Line 121...
118
                "dirs=s"        => \@opt_dirs,              # Multiple strings
121
                "dirs=s"        => \@opt_dirs,              # Multiple strings
119
                "comment=s"     => \$opt_comment,           # String
122
                "comment=s"     => \$opt_comment,           # String
120
                "vob=s"         => \$opt_vob,               # String
123
                "vob=s"         => \$opt_vob,               # String
121
                "user=s"        => \$opt_user,              # String
124
                "user=s"        => \$opt_user,              # String
122
                "admin"         => \$opt_admin_vob,         # String
125
                "admin"         => \$opt_admin_vob,         # String
-
 
126
                "entireview"    => \$opt_entire_view,       # Flag
123
 
127
 
124
                );
128
                );
125
 
129
 
126
                #
130
                #
127
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
131
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
Line 147... Line 151...
147
#   Validate user options
151
#   Validate user options
148
#   Use either -spec or one command line argument
152
#   Use either -spec or one command line argument
149
#
153
#
150
Error ("No labels provided") if ( $#ARGV < 0);
154
Error ("No labels provided") if ( $#ARGV < 0);
151
Error ("Too many labels provided") if ( $#ARGV > 0);
155
Error ("Too many labels provided") if ( $#ARGV > 0);
152
Error ("Conflicting options") if ( $opt_clone && $opt_label );
156
Error ("Conflicting options: -clone and -label") if ( $opt_clone && $opt_label );
-
 
157
Error ("Conflicting options: -entireview and -label" ) if ( $opt_entire_view && $opt_label );
-
 
158
Error ("Conflicting options: -entireview and -exclude" ) if ( $opt_entire_view && @opt_exclude );
-
 
159
Error ("Conflicting options: -entireview and -files" ) if ( $opt_entire_view && @opt_files );
-
 
160
Error ("Conflicting options: -entireview and -dir" ) if ( $opt_entire_view && @opt_dirs );
-
 
161
Error ("Conflicting options: -entireview and -norecurse" ) if ( $opt_entire_view && !$opt_recurse );
-
 
162
 
153
$label = $ARGV[0];
163
$label = $ARGV[0];
154
 
164
 
155
#
165
#
156
#   Allow the exclude list to contain comma seperated names
166
#   Allow the exclude list to contain comma seperated names
157
#
167
#
Line 179... Line 189...
179
#   There is a potential problem/race condition if doing a rename
189
#   There is a potential problem/race condition if doing a rename
180
#   within a static view of a label that is a part of the views config spec
190
#   within a static view of a label that is a part of the views config spec
181
#
191
#
182
#   Work around: If performing a rename, then ensure that we have the VOB name
192
#   Work around: If performing a rename, then ensure that we have the VOB name
183
#
193
#
184
if ( $opt_rename && ! $opt_vob )
194
if ( ($opt_rename || $opt_entire_view ) && ! $opt_vob )
185
{
195
{
186
    Verbose ("Determine VOB name");
196
    Verbose ("Determine VOB name");
187
    ClearCmd ('describe', '-short', 'vob:.' );
197
    ClearCmd ('describe', '-short', 'vob:.' );
188
    Error ("Cannot determine vob from current directory") if ( @error_list || ! $last_result );
198
    Error ("Cannot determine vob from current directory") if ( @error_list || ! $last_result );
-
 
199
    $vob_base = $last_result;
189
    $vob_desc = '@' . $last_result;
200
    $vob_desc = '@' . $vob_base;
-
 
201
    $vob_desc =~ s~/~$VOB_SEP~g;
190
    Verbose ("VOB name: $vob_desc");
202
    Verbose ("VOB name: $vob_base");
191
    
-
 
192
}
203
}
193
elsif ( $opt_vob )
204
elsif ( $opt_vob )
194
{
205
{
195
    Error ("-vob option cannot be used with this command")
206
    Error ("-vob option cannot be used with this command")
196
        if ( $opt_clone || $opt_label || $opt_show || $opt_remove  );
207
        if ( $opt_clone || $opt_label || $opt_show || $opt_remove );
197
 
208
 
198
    $vob_desc = $UNIX_VOB_PREFIX if ( $UNIX );
209
    $vob_desc = $UNIX_VOB_PREFIX if ( $UNIX );
199
    $vob_desc = '@/' . $vob_desc . '/' . $opt_vob;
210
    $vob_desc = '@/' . $vob_desc . '/' . $opt_vob;
200
    $vob_desc =~ s~//~/~g;
211
    $vob_desc =~ s~//~/~g;
201
    $vob_desc =~ s~/~$VOB_SEP~g;
212
    $vob_desc =~ s~/~$VOB_SEP~g;
Line 216... Line 227...
216
#   Check to see if the label exists
227
#   Check to see if the label exists
217
#   Determine if its locked at the same time
228
#   Determine if its locked at the same time
218
#
229
#
219
Verbose ("Check label");
230
Verbose ("Check label");
220
ClearCmd ("describe", "-fmt", "%[locked]p", "lbtype:$label$vob_desc" );
231
ClearCmd ("describe", "-fmt", "%[locked]p", "lbtype:$label$vob_desc" );
-
 
232
$label_exists = 1 unless( $opt_test
221
$label_exists = 1 unless( $opt_test || grep ( /Label type not found/, @error_list ));
233
                          || grep ( /Label type not found/, @error_list )
-
 
234
                          || grep ( /Unable to determine VOB/, @error_list )
-
 
235
                            );
222
if ( $label_exists && $last_result )
236
if ( $label_exists && $last_result )
223
{
237
{
224
    $label_is_locked = ($last_result =~ m~unlocked~)? 0:1;
238
    $label_is_locked = ($last_result =~ m~unlocked~)? 0:1;
225
}
239
}
226
Verbose ("Check label: Exist:$label_exists, Locked:$label_is_locked");
240
Verbose ("Check label: Exist:$label_exists, Locked:$label_is_locked");
Line 229... Line 243...
229
#-------------------------------------------------------------------------------
243
#-------------------------------------------------------------------------------
230
#   Process command
244
#   Process command
231
#       Create a label
245
#       Create a label
232
#
246
#
233
if ( $opt_create || ( $opt_auto && ! $label_exists ) )
247
if ( $opt_create || ( $opt_auto && ! $label_exists ) )
-
 
248
 
234
{
249
{
235
    Verbose ("Create label");
250
    Verbose ("Create label");
236
    Error ("Label already exists") if ( $label_exists );
251
    Error ("Label already exists") if ( $label_exists );
237
 
252
 
238
    my @opts;
253
    my @opts;
Line 240... Line 255...
240
    push @opts, '-global' if ( $opt_admin_vob );
255
    push @opts, '-global' if ( $opt_admin_vob );
241
 
256
 
242
    ClearCmd ("mklbtype", @opts, "$label$vob_desc" ) unless $opt_test;
257
    ClearCmd ("mklbtype", @opts, "$label$vob_desc" ) unless $opt_test;
243
    Error ("Program Terminated") if ( @error_list );
258
    Error ("Program Terminated") if ( @error_list );
244
    $opr_done = 1;
259
    $opr_done = 1;
-
 
260
    $label_exists = 1;
245
}
261
}
246
 
262
 
247
#-------------------------------------------------------------------------------
263
#-------------------------------------------------------------------------------
248
#   Process command
264
#   Process command
249
#       Unlock a label - if it was locked
265
#       Unlock a label - if it was locked
Line 297... Line 313...
297
 
313
 
298
#-------------------------------------------------------------------------------
314
#-------------------------------------------------------------------------------
299
#   Process command
315
#   Process command
300
#       Label files and directories
316
#       Label files and directories
301
 
317
 
302
if ( $opt_label || ( $opt_auto && ! $opt_clone ) )
318
if ( $opt_label || ( $opt_auto && ! $opt_clone && ! $opt_entire_view ))
303
{
319
{
304
    my $label_error;
320
    my $label_error;
305
    my @cmd_opt;
321
    my @cmd_opt;
306
    my %info;
322
    my %info;
307
    push @cmd_opt, "-replace" if ( $opt_replace );
323
    push @cmd_opt, "-replace" if ( $opt_replace );
Line 392... Line 408...
392
    show_warning ("WARNING: Labels NOT applied to element-0 of files", 'element0_list' );
408
    show_warning ("WARNING: Labels NOT applied to element-0 of files", 'element0_list' );
393
    print        ("WARNING: Path to the VOB root contains a symbolic link. Labeling incomplete") if ( $info{'is_symlink'} );
409
    print        ("WARNING: Path to the VOB root contains a symbolic link. Labeling incomplete") if ( $info{'is_symlink'} );
394
    show_warning ("WARNING: Multiple build.pl files labeled", 'build_files', 1 );
410
    show_warning ("WARNING: Multiple build.pl files labeled", 'build_files', 1 );
395
 
411
 
396
    Error ("Program Terminated") if ( $label_error );
412
    Error ("Program Terminated") if ( $label_error );
-
 
413
    $opr_done = 1;
-
 
414
}
-
 
415
 
-
 
416
#-------------------------------------------------------------------------------
-
 
417
#   Process command
-
 
418
#       Label entire view.
-
 
419
#       Intended for 'buildtool' use as its not as flexible, bit it is faster
-
 
420
#
-
 
421
if ( $opt_entire_view )
-
 
422
{
-
 
423
    #
-
 
424
    #   The -recurse option doesn't do a good job of reporting
-
 
425
    #   errors if the label does not exist. Ensure thatit exists
-
 
426
    #
-
 
427
    Error ("Label does not exist: $label")
-
 
428
        unless ( $label_exists );
-
 
429
    
-
 
430
    #
-
 
431
    #   Calculate the root of the vob
-
 
432
    #
-
 
433
    my $here =  getcwd();
-
 
434
    Verbose ("Current dir: $here");
-
 
435
 
-
 
436
    $here =~ m~^(.*$vob_base)~;
-
 
437
    my $base_dir = $1;
-
 
438
    Verbose ("Path of base: $base_dir");
-
 
439
    Error ("Calculating Vob Root: $base_dir" ) unless ( -d  $base_dir );
-
 
440
    Message ("Labeling ENTIRE view", $base_dir);
-
 
441
 
-
 
442
    #
-
 
443
    #   Use -recurse option to label the entire view
-
 
444
    #
-
 
445
    my @cmd_opt = ('-recurse', '-follow');
-
 
446
    push @cmd_opt, '-replace' if ( $opt_replace );
-
 
447
    ClearCmd ("mklabel", @cmd_opt, $label, $base_dir  ) unless ( $opt_test );
-
 
448
 
-
 
449
    #
-
 
450
    #   Can't use the return value or the error list as the command will
-
 
451
    #   report errors for many different conditions
-
 
452
    #
-
 
453
    #   Look at the tail of @last_results
-
 
454
    #   The last line is the most informative.
-
 
455
    #       Check that its in the right form. ie: ' nnn failed'
-
 
456
    #
-
 
457
    Error ("Cannot parse comamnd result for recursive label", $last_result )
-
 
458
        unless ( $last_result =~ m~(\d+)\s+failed~ );
-
 
459
    my $fail_count = $1;
-
 
460
    if ( $fail_count )
-
 
461
    {
-
 
462
        #
-
 
463
        #   Pretty up the error list
-
 
464
        #   
-
 
465
        #
-
 
466
        @error_list = grep ( !/No such file or directory.$/, @error_list );
-
 
467
        @error_list = grep ( !/^Created label/, @error_list );
-
 
468
 
-
 
469
        Error ("Labeling entire view: $fail_count Errors" );
-
 
470
    }
-
 
471
    Message ("Labeling entire view", @last_results[-5 .. -1 ]);
397
 
472
 
398
    #
473
    #
399
    #   Double check the label process
474
    #   Since we don't have 100% confidence in this 'new' labeling
400
    #   We are seeing issues with ClearCase where a file, or dir, is not being
475
    #   process, within the auto build environment we will double
-
 
476
    #   check the process.
-
 
477
    #
401
    #   labeled. The following is a quick check. See if there is any thing to
478
    #   Note: This test can be removed at some time in the future
402
    #   label again
479
    #         When we have more faith in the process
403
    #
480
    #
404
    unless ( $opt_test )
481
    unless ( $opt_test )
405
    {
482
    {
406
        %info = ();
483
        my %info = ();
-
 
484
        @opt_files = ();
-
 
485
        @opt_dirs = $base_dir;
-
 
486
        undef $opt_up;
-
 
487
        $opt_recurse = 1;
-
 
488
 
407
        determine_dirs_to_label ( \%info );
489
        Message ("Double checking labeling");
408
        determine_files_to_label( \%info );
490
        determine_files_to_label( \%info );
409
        if ( @{$info{'dir_list'}}  || @{$info{'label_list'}} )
491
        if ( @{$info{'label_list'}} )
410
        {
492
        {
411
            DebugDumpData("DoubleCheck Data", \%info );
493
            DebugDumpData("DoubleCheck Data", \%info );
412
            Error ('ClearCase label problem detected',
494
            Error ('ClearCase label problem detected',
413
                   'Please report to david.purdie@vix-erg.com',
495
                   'Please report to david.purdie@vix-erg.com',
414
                   'Directories and Files not labled as requested:',
496
                   'Directories and Files not recursively labled as requested'
415
                   @{$info{'dir_list'}},
-
 
416
                   @{$info{'label_list'}}
-
 
417
                   );
497
                   );
418
        }
498
        }
419
    }
499
    }
420
 
500
 
421
    $opr_done = 1;
501
    $opr_done = 1;
Line 790... Line 870...
790
        my $find_arg = $opt_recurse && !$doing_files ? '' : '-nrecurse';
870
        my $find_arg = $opt_recurse && !$doing_files ? '' : '-nrecurse';
791
        my $cmd = QuoteCommand ("cleartool", "find", "$dir", "-cview", $find_arg, "-version", "{!lbtype($label)}", "-print");
871
        my $cmd = QuoteCommand ("cleartool", "find", "$dir", "-cview", $find_arg, "-version", "{!lbtype($label)}", "-print");
792
        Verbose2($cmd);
872
        Verbose2($cmd);
793
 
873
 
794
        my $cmd_handle;
874
        my $cmd_handle;
-
 
875
        @error_list = ();
-
 
876
        @last_results = ();
-
 
877
        $last_result = undef;
795
        open($cmd_handle, "$cmd 2>&1 |") || Error( "can't run command: $!");
878
        open($cmd_handle, "$cmd 2>&1 |") || Error( "can't run command: $!");
796
        while (<$cmd_handle>)
879
        while (<$cmd_handle>)
797
        {
880
        {
798
            #
881
            #
799
            #   Filter output from the user
882
            #   Filter output from the user
Line 947... Line 1030...
947
{
1030
{
948
    my $cmd = QuoteCommand (@_);
1031
    my $cmd = QuoteCommand (@_);
949
    Verbose2 "cleartool $cmd";
1032
    Verbose2 "cleartool $cmd";
950
 
1033
 
951
        @error_list = ();
1034
        @error_list = ();
-
 
1035
        @last_results = ();
-
 
1036
        $last_result = undef;
952
        my $cmd_handle;
1037
        my $cmd_handle;
953
        open($cmd_handle, "cleartool $cmd  2>&1 |")    || Error "can't run command: $!";
1038
        open($cmd_handle, "cleartool $cmd  2>&1 |")    || Error "can't run command: $!";
954
        while (<$cmd_handle>)
1039
        while (<$cmd_handle>)
955
        {
1040
        {
956
            chomp;
1041
            chomp;
957
            $last_result = $_;
1042
            $last_result = $_;
-
 
1043
            $last_result =~ tr~\\/~/~s;
-
 
1044
            push @last_results, $last_result;
958
            Verbose ( "cleartool resp:" . $_);
1045
            Verbose ( "cleartool resp:" . $_);
959
            push @error_list, $_ if ( m~Error:~ );
1046
            push @error_list, $_ if ( m~Error:~ );
960
        }
1047
        }
961
        close($cmd_handle);
1048
        close($cmd_handle);
962
 
1049
 
Line 984... Line 1071...
984
    -man               - Full documentation
1071
    -man               - Full documentation
985
    -auto              - Auto create and label
1072
    -auto              - Auto create and label
986
    -clone=xxx         - Apply new label to objects with label xxx
1073
    -clone=xxx         - Apply new label to objects with label xxx
987
    -create            - Create a label
1074
    -create            - Create a label
988
    -label             - Labels a directory tree
1075
    -label             - Labels a directory tree
-
 
1076
    -entireview        - Labels entire view
989
    -lock              - Lock the label
1077
    -lock              - Lock the label
990
    -remove            - Remove label from elements
1078
    -remove            - Remove label from elements
991
    -delete            - Delete label label from elements and vob
1079
    -delete            - Delete label label from elements and vob
992
    -rename=xxx        - Rename a label
1080
    -rename=xxx        - Rename a label
993
    -show              - Show elements with the label
1081
    -show              - Show elements with the label
Line 1121... Line 1209...
1121
The -replace option may be used to force labels to be moved.
1209
The -replace option may be used to force labels to be moved.
1122
 
1210
 
1123
The -norecurse option may be used to prevent recursion into all subdirectories,
1211
The -norecurse option may be used to prevent recursion into all subdirectories,
1124
and the labeling of any directories.
1212
and the labeling of any directories.
1125
 
1213
 
-
 
1214
=item B<-entireview>
-
 
1215
 
-
 
1216
This option will label all the files and directories in the current view. It may be
-
 
1217
invoked at any point within the view.
-
 
1218
 
-
 
1219
This option is intended to be used by the 'autobuild' process. It is not as
-
 
1220
flexible as the B<-label> option, nor can it be used in conjunction with
-
 
1221
may other options.
-
 
1222
 
-
 
1223
The -replace option may be used to force labels to be moved.
-
 
1224
 
-
 
1225
The option will determine the root of the vob and label all components in the
-
 
1226
current view, following vib-symbolic links in the process.
-
 
1227
 
1126
=item B<-lock>
1228
=item B<-lock>
1127
 
1229
 
1128
This option will lock the specified label. This operation will be done after any
1230
This option will lock the specified label. This operation will be done after any
1129
other operations have been performed.  If the label is already locked then
1231
other operations have been performed.  If the label is already locked then
1130
this operation will not attempt to lock the label.
1232
this operation will not attempt to lock the label.