Subversion Repositories DevTools

Rev

Rev 5709 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
#! /usr/bin/perl
2
########################################################################
6177 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
392 dpurdie 4
#
5
# Module name   : jats_cbuilder.pl
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s):
9
#
10
# Description   : A script to determine differences between two versions of
11
#                 a build.
12
#
13
#                 Can, with a bit of work, create a BeyondCompare@ view of
14
#                 the stuff
15
#
16
#
17
#......................................................................#
18
 
19
require 5.006_001;
20
use strict;
21
use warnings;
22
use JatsError;
23
use JatsSystem;
24
use FileUtils;
25
 
26
use Pod::Usage;                             # required for help support
27
use Getopt::Long;
28
use File::Path;
29
use Cwd;
30
use Sys::Hostname;                          # For hostname
31
 
32
my $VERSION = "1.5.5";                      # 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_drive = 'o';
42
my $opt_tag = 'dynamic';
43
my $opt_outfile;
44
 
45
#
46
#   Globals - Provided by the JATS environment
47
#
48
my $USER            = $ENV{'USER'};
49
my $UNIX            = $ENV{'GBE_UNIX'};
50
my $TMP             = $UNIX ? "/tmp" : $ENV{'TMP'};
51
 
52
#
53
#   Globals
54
#
55
my $MACHINENAME;
56
my @error_list;                             # ClearCmd detected errors
57
my $UNIX_VOB_PREFIX = '/vobs';
58
my $VOB_SEP         = $UNIX ? '/' : '\\';
59
my $BC2             = 'c:/Program Files/Beyond Compare 2/BC2.exe';
60
 
61
my @view_tags;
62
my %files;
63
 
64
 
65
#-------------------------------------------------------------------------------
66
# Function        : Mainline Entry Point
67
#
68
# Description     :
69
#
70
# Inputs          :
71
#
72
 
73
#
74
#   Parse the user options
75
#
76
my $result = GetOptions (
77
                "help+"         => \$opt_help,              # flag, multiple use allowed
78
                "manual"        => \$opt_manual,            # flag, multiple use allowed
79
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
80
                "out=s"         => \$opt_outfile,           # String
81
                );
82
 
83
                #
84
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
85
                #
86
 
87
#
88
#   Process help and manual options
89
#
90
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result || $#ARGV < 0);
91
pod2usage(-verbose => 1)  if ($opt_help == 2 );
92
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
93
 
94
InitFileUtils();
95
 
96
#
97
#   Configure the error reporting process now that we have the user options
98
#
99
ErrorConfig( 'name'    => 'CCVIEW',
100
             'verbose' => $opt_verbose );
101
 
102
#
103
#   Only for windows
104
#
105
Error ("This program only works under WIndows")
106
    if ( $UNIX );
107
 
108
#Error ("No output file specified")
109
#    unless ( $opt_outfile );
110
 
111
#
112
#   Validate user options
113
#   Use either -label or one command line argument
114
#
115
my $label1 = shift @ARGV;
116
my $label2 = shift @ARGV;
117
 
118
Error ("Need two labels on the command line")
119
    unless ( $label1 && $label2 );
120
Error ("Too many command line arguments" )
121
    unless ( $#ARGV < 0 );
122
 
123
#
124
#   Determine the machine type
125
#
126
Verbose ("Machine Type: UNIX=$UNIX");
127
 
128
$MACHINENAME = hostname;
129
Error ("Machine Name not determined")
130
    unless ( $MACHINENAME );
131
chomp( $MACHINENAME );
132
 
133
Error ("USER name not determined" )
134
    unless ( $USER );
135
 
136
Error ("TMP not found or not a directory")
137
    unless ( $TMP && -d $TMP );
138
$TMP = "$TMP/$$";
139
 
140
Error ("Beyond Compare not found",
141
       "Looking in: $BC2" )
142
    unless ( -x $BC2 );
143
 
144
#
145
#   Ensure that the 'cleartool' program can be located
146
#
147
Verbose ("Locate clearcase utility in users path");
148
Error ("Cannot locate the 'cleartool' utility in the users PATH")
149
    unless ( LocateProgInPath('cleartool', '--All') );
150
 
151
 
152
#
153
#   Create dynamic views for the two views
154
#   Verify that the view are present
155
#
156
 
157
my $tag1 = create_dynamic_view( $label1 );
158
my $tag2 = create_dynamic_view( $label2 );
159
 
160
my $path1 = "$opt_drive:/$tag1";
161
my $path2 = "$opt_drive:/$tag2";
162
 
163
Error ("Cannot locate view directory: $path1" ) unless (-d $path1);
164
Error ("Cannot locate view directory: $path2" ) unless (-d $path2);
165
 
166
System ( $BC2, $path1, $path2 );
167
exit 0;
168
 
169
#
170
#   Scan the two views and create a hash of the files int he view with a
171
#   tag of the view that they are in. The hash key is the file name+branch
172
#
173
 
174
my @files1 = files_from_from_view( $path1, 1 );
175
my @files2 = files_from_from_view( $path2, 2 );
176
 
177
#DebugDumpData ("Files", \%files );
178
 
179
#
180
#   Create a hash of files that are different
181
#   The hash key will be the file name
182
#   The tag will be the branch that the file is on
183
#
184
my %diffs;
185
foreach my $file ( sort keys %files )
186
{
187
    #
188
    #   These files are the same
189
    #
190
    next if ( $files{$file}{1} && $files{$file}{2} );
191
 
192
    my $tag = 1;
193
    $tag = 2 if $files{$file}{2};
194
 
195
    #
196
    #   Break path into file and version
197
    #
198
    my ($f,$b) = split ('@@', $file );
199
    $diffs{$f}{$tag} = $file;
200
 
201
#    print "$file\n";
202
}
203
 
204
#
205
#   Process files that are common, but have changed
206
#
207
open (FO, ">", $opt_outfile) || Error ("Cannot open file: $opt_outfile");
208
foreach my $file ( sort keys %diffs )
209
{
210
    #
211
    #   Files are are common
212
    #
213
    if ( $diffs{$file}{1} && $diffs{$file}{2} )
214
    {
215
        ClearDiff("-serial_format $path1/$diffs{$file}{1} $path2/$diffs{$file}{2}");
216
    }
217
    elsif ($diffs{$file}{1} )
218
    {
219
        #
220
        #   File has been deleted
221
        #
222
    }
223
    else
224
    {
225
        #
226
        #   File has been added
227
        #
228
    }
229
}
230
close FO;
231
 
232
 
233
 
234
#DebugDumpData ("Files", \%diffs);
235
 
236
 
237
 
238
#System ( $BC2, $path1, $path2 );
239
 
240
exit (0);
241
 
242
#-------------------------------------------------------------------------------
243
# Function        : create_dynamic_view
244
#
245
# Description     : Create a dynamic view, based on a label
246
#
247
# Inputs          : $label          - Base label
248
#
249
# Returns         : 
250
#
251
sub create_dynamic_view
252
{
253
    my ($label) = @_;
254
    my $config = "${TMP}.config_ccview.txt";
255
 
256
    #
257
    #   Create a config spec
258
    #
259
    Verbose ("Create tmp file: $config");
260
    open (CF, ">$config" ) || Error ("Cannot create temp config spec file");
261
    print CF "element * CHECKEDOUT\n";
262
    print CF "element .../lost+found -none\n";
263
    print CF "element * $label\n";
264
    close CF;
265
 
266
    my $tag = "${USER}_${MACHINENAME}_${opt_tag}_${label}";
267
    push @view_tags, $tag;
268
 
269
    ClearCmd ( "rmview -tag $tag" );
270
    ClearCmd ( "mkview -tag $tag -stgloc -auto" );
271
    ClearCmd ( "setcs  -tag $tag $config" );
272
 
273
    unlink $config;
274
 
275
    return $tag;
276
}
277
 
278
#-------------------------------------------------------------------------------
279
# Function        : files_from_from_view
280
#
281
# Description     : Determine the list of files/versions in a given view
282
#
283
# Inputs          : $vpath          - Path to the view
284
#                   $tag            - File tag
285
#
286
# Returns         : Nothing
287
#                   Populates the %files array
288
#
289
sub files_from_from_view
290
{
291
    my ($vpath, $tag) = @_;
292
    my @files;
293
    my $cutlen = length ($vpath );
294
 
295
    my @dir_list = glob ( "$vpath/*" );
296
    foreach my $dir ( @dir_list )
297
    {
298
        #
299
        #   Skip top-level files - there will not be any
300
        #   Skip ClearCase directories that are place-holders
301
        #
302
        next unless ( -d $dir );
303
        next unless ( glob ("$dir/*") );
304
 
305
print "Processing: $dir\n";
306
        my $cmd = "cleartool ls -rec -short $dir";
307
 
308
        Verbose ("ClearTool: $cmd");
309
        open(CMD, "$cmd 2>&1 |") || Error "can't run command: $!";
310
        while (<CMD>)
311
        {
312
            s~[\r\n]+$~~;
313
            tr~\\/~/~s;
314
            print "$_\n" if $opt_verbose;
315
 
316
            #
317
            #   Strip the base path of the file name
318
            #   They are in differnt VOBS
319
            #
320
            my $file = substr ($_, $cutlen );
321
            $files{$file}{$tag} = 1;
322
        }
323
        close(CMD);
324
        Verbose2 "ClearTool Exit Status: $?";
325
    }
326
}
327
 
328
#-------------------------------------------------------------------------------
329
# Function        : END
330
#
331
# Description     : This function will be called as the program exists
332
#                   It will also be called under error conditions
333
#                   Close down stuff we created
334
#
335
# Inputs          : 
336
#
337
# Returns         : 
338
#
339
 
340
sub END
341
{
342
    Message ("Cleaning up views") if @view_tags;
343
    foreach my $tag ( @view_tags )
344
    {
345
#        Message ("NOT Cleaning up views");
346
        ClearCmd ( "rmview -tag $tag" );
347
    }
348
}
349
 
350
#-------------------------------------------------------------------------------
351
# Function        : ClearDiff
352
#
353
# Description     : Issue a cleartool command
354
#                   Filter out many of the stupid messages
355
#
356
# Inputs          : Options and Command line
357
#                   Options:
358
#                       --Quiet     - Supress all command output
359
#
360
# Returns         : Error code
361
#
362
sub ClearDiff
363
{
364
    my $quiet;
365
 
366
    #
367
    #   Scan for initial options
368
    #       --Quiet
369
    #
370
    if ( $_[0] eq '--Quiet' )
371
    {
372
        $quiet = 1;
373
        shift;
374
    }
375
 
376
    my $cmd = "cleardiff @_";
377
 
378
    Verbose ("ClearTool: $cmd");
379
    open(CMD, "$cmd 2>&1 |") || Error "can't run command: $!";
380
    while (<CMD>)
381
    {
382
        #
383
        #   Filter output from the user
384
        #
385
        next if ( $quiet );
386
        s~(file 1: )$path1/~$1~;
387
        s~(file 2: )$path2/~$1~;
388
        print FO $_;
389
    }
390
    close(CMD);
391
 
392
    Verbose2 "ClearTool Exit Status: $?";
393
    return $? / 256;
394
}
395
 
396
#-------------------------------------------------------------------------------
397
# Function        : ClearCmd
398
#
399
# Description     : Execute a cleartool command
400
#                   Capture error messages only
401
#
402
# Inputs          : Command to execute
403
#
404
# Returns         : Exit code
405
#                   Also the global @error_list
406
#
407
sub ClearCmd
408
{
409
    my( $cmd ) = @_;
410
    Verbose2 "cleartool $cmd";
411
 
412
        @error_list = ();
413
        open(CMD, "cleartool $cmd  2>&1 |")    || Error "can't run command: $!";
414
        while (<CMD>)
415
        {
416
            chomp;
417
            Verbose ($_);
418
            push @error_list, $_ if ( m~Error:~ );
419
        }
420
        close(CMD);
421
 
422
    Verbose2 "Exit Status: $?";
423
    return $? / 256;
424
}
425
 
426
#-------------------------------------------------------------------------------
427
#   Documentation
428
#
429
 
430
=pod
431
 
432
=head1 NAME
433
 
434
jats_cbuilder - Build a package given a clearcase label
435
 
436
=head1 SYNOPSIS
437
 
438
  jats jats_ccview [options] label-1 label-2
439
 
440
 Options:
441
    -help              - brief help message
442
    -help -help        - Detailed help message
443
    -man               - Full documentation
444
 
445
=head1 OPTIONS
446
 
447
=over 8
448
 
449
=item B<-help>
450
 
451
Print a brief help message and exits.
452
 
453
=item B<-help -help>
454
 
455
Print a detailed help message with an explanation for each option.
456
 
457
=item B<-man>
458
 
459
Prints the manual page and exits.
460
 
461
=back
462
 
463
=head1 DESCRIPTION
464
 
465
This program is the primary tool for ...
466
 
467
=cut
468