Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
6177 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Generate and test build manifest
11
#                 This tool is intended to be used by the automated build system
12
#
13
# Usage:
14
#
15
#
16
#......................................................................#
17
 
261 dpurdie 18
require 5.008_002;
227 dpurdie 19
 
20
use strict;
21
use warnings;
22
use JatsError;
23
use FileUtils;
24
 
25
use Pod::Usage;                             # required for help support
26
use Getopt::Long;
27
use Cwd;
28
use ExtUtils::Manifest qw(manifind);        # Needs perl later than 5.6.1
29
 
30
my $VERSION = "1.0.0";                      # Update this
31
 
32
#
33
#   Options
34
#
35
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
36
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
37
my $opt_help = 0;
38
my $opt_manual = 0;
39
my $opt_buildsystem;
40
my $opt_manifest_file;
41
my $opt_rootdir;
42
my $opt_check;
43
my $opt_generate;
44
my @opt_exclude;
45
my @opt_rewrite;
46
my %opt_rewrite;
379 dpurdie 47
my $opt_quiet;
227 dpurdie 48
 
49
my @num_excluded;
50
my @num_rewrite;
51
 
52
#-------------------------------------------------------------------------------
53
# Function        : Mainline Entry Point
54
#
55
# Description     :
56
#
57
# Inputs          :
58
#
59
my $result = GetOptions (
60
                "help+"         => \$opt_help,              # flag, multiple use allowed
61
                "manual|man"    => \$opt_manual,            # flag
379 dpurdie 62
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
63
                "quiet:+"       => \$opt_quiet,             # flag, multiple use allowed
227 dpurdie 64
                "buildsystem"   => \$opt_buildsystem,       # Flag,
65
                "rootdir=s"     => \$opt_rootdir,           # String
66
                "manifest=s"    => \$opt_manifest_file,     # String
67
                "check"         => \$opt_check,             # Flag
68
                "generate"      => \$opt_generate,          # Flag
69
                "exclude=s"     => \@opt_exclude,           # Multiple strings
70
                "rewrite=s"     => \@opt_rewrite,           # Multiple strings
71
                );
72
 
73
                #
74
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
75
                #
76
 
77
#
78
#   Process help and manual options
79
#
80
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
81
pod2usage(-verbose => 1) if ($opt_help == 2 );
82
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
83
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV >= 0 );
84
 
85
#
86
#   Configure the error reporting process now that we have the user options
87
#
88
ErrorConfig( 'name'    =>'MANIFEST',
89
             'verbose' => $opt_verbose,
90
            );
91
 
92
 
93
#
94
#   Validate user options
95
#
96
Error ("No Manifest file provided") if ( ! $opt_manifest_file);
97
#Error ("No Rootdir provided") if ( !$opt_rootdir);
98
 
99
#
100
#   Ensure the md5sum utility can be found
101
#
102
Verbose ("Check existance of utility: md5sum");
103
$result = qx( md5sum --version 2>&1 );
104
Error( "Cannot locate utility md5sum" )if ( $? );
105
 
106
#
107
#   Init the file utilities
108
#
109
InitFileUtils();
110
 
111
#-------------------------------------------------------------------------------
112
#   Generate the manifest file
113
#   This is done using the MD5SUM utility
114
#
115
#   Note: The MD5SUM program has a significant startup time.
116
#         The script will process up to 10 files at a time to improve speed
117
#
118
if ( ! $opt_check || $opt_generate )
119
{
120
    #
121
    #   Process the rewrite array and create a hash of entries
122
    #   Any file that is rewritten will be excluded
123
    #
124
    foreach my $entry ( @opt_rewrite )
125
    {
126
        my( $old, $new, @rest ) = split('=', $entry );
127
        Error ("Bad rewite entry: $entry") if ( @rest || !$new || !$old );
128
        $opt_rewrite{$old} = $new;
129
        $opt_rewrite{$new} = "";
130
    }
131
 
132
    #
133
    #   Add in the excluded entries
134
    #
135
    foreach my $entry ( @opt_exclude )
136
    {
137
        $opt_rewrite{$entry} = "";
138
    }
139
#    DebugDumpData("RewriteData", \%opt_rewrite);
140
 
141
 
142
    #
143
    #   Delete the existing file, if it exists
144
    #   Done in the users current directory
145
    #
146
    Verbose ("Delete any existing manifest file");
147
    if ( -f $opt_manifest_file )
148
    {
149
        unlink ($opt_manifest_file) || Error( "Cannot delete existing manifest file: $opt_manifest_file");
150
    }
151
 
152
    #
153
    #   Open a handle to the manifest file
154
    #
155
    open (MANIFEST, ">", $opt_manifest_file) || Error("Cannot create manifest file: $opt_manifest_file");
156
 
157
    #
158
    #   Change to the specified subdirectory
159
    #
160
    if ( $opt_rootdir )
161
    {
162
        Verbose ("chdir to specified root directory");
163
        chdir( $opt_rootdir ) || Error("Specified Root Diretory not found: $opt_rootdir");
164
    }
165
 
166
    #
167
    #   Generate a list of files to be included in the manifest
168
    #   Directories are not included
169
    #
170
    Verbose ("Generate file list");
171
    my $found = manifind();
172
    #DebugDumpData( "Data", $found );
173
    my @files = sort keys %$found;
174
    $found = "";
175
    Verbose("Number of files in manifest: " . (1 + $#files));
176
    Error ("No files in manifest") unless ( $#files > 0 );
177
 
178
    #
179
    #   Generate Md5sum info for each file
180
    #
181
    Verbose ("Generate manifest file");
182
    my @list;
183
    foreach my $file ( @files )
184
    {
185
        #
186
        #   Detect files that require special handling
187
        #   Some files are rewritten ( auto.pl -> build.pl )
188
        #   Some file are excluded ( build.pl )
189
        #
190
        my $rewrite;
191
        my $fileonly = $file;
192
        $fileonly =~ s~.*/~~;
379 dpurdie 193
        Verbose2("Processing: $file");
227 dpurdie 194
        if ( exists $opt_rewrite{$fileonly} )
195
        {
196
            $rewrite = $opt_rewrite{$fileonly};
197
            unless ( $rewrite )
198
            {
199
                Verbose("Excluding: $file");
200
                push @num_excluded, $file;
201
                next;
202
            }
203
        }
204
 
205
        #
206
        #   Speed up MD5 processing by passing multiple files to the command
207
        #   When we hit a "rewritten" file, then we will first process and files
208
        #   in the speed up list, then the one special file
209
        #
210
        if ( ! $rewrite )
211
        {
212
            push @list, '"' . $file . '"';
213
        }
214
 
215
        if ( $#list >= 10 || $rewrite )
216
        {
379 dpurdie 217
            print '.' unless ( ($opt_verbose > 1) || $opt_quiet);
227 dpurdie 218
            process_list( @list );
219
            @list = "";
220
        }
221
 
222
        #
223
        #   Rewrite
224
        #   process a single entry. There will not be many of these
225
        #
226
        if ( $rewrite )
227
        {
228
            #
229
            #   Generate the MD5SUM info
230
            #
379 dpurdie 231
            print '.' unless ( ($opt_verbose > 1) || $opt_quiet);
227 dpurdie 232
            my $data = qx(md5sum "$file");
233
 
234
            #
235
            #   Rewrite any required file name
236
            #
237
            Verbose ("Rewrite: $fileonly to $rewrite");
238
            $data =~ s~$fileonly$~$rewrite~;
239
            push @num_rewrite, $file;
240
 
241
            #   Append to the output file
242
            #
243
            print MANIFEST "$data";
244
            chomp($data);
245
            Verbose2( "REWRITE: $data" );
246
        }
247
    }
248
    process_list( @list );
249
    close MANIFEST;
250
 
251
    #
252
    #   Informational warnings
253
    #
254
    Message("Number of files excluded : " . (1 + $#num_excluded), @num_excluded) if ( $#num_excluded >= 0);
255
    Message("Number of files rewritten: " . (1 + $#num_rewrite), @num_rewrite) if ( $#num_rewrite >= 0 );
379 dpurdie 256
    Message("Files scanned: " . (1 + $#files) );
227 dpurdie 257
 
258
}
259
 
260
sub process_list
261
{
262
    my @list = @_;
263
 
264
    #
265
    #   Anything to do
266
    #
379 dpurdie 267
    Verbose3 ("process_list", @list, $#list);
268
    return if ( $#list < 1 );
227 dpurdie 269
 
270
#    print ".";
271
    open(CMD, "md5sum @list |") || Error "Can't run command: $!";
272
    while (<CMD>)
273
    {
274
        print MANIFEST $_;
275
        chomp;
276
        Verbose2("CMD: $_");
277
    }
278
    close CMD;
279
}
280
 
281
#-------------------------------------------------------------------------------
282
#   Validate the manifest
283
#
284
if ( $opt_check )
285
{
286
    my @failed;
287
    my $match_count = 0;
288
    #
289
    #   Determine the absolute path to the manifest file
290
    #   Required as the file may be a relative path
291
    #
292
    my $abs_manifest = AbsPath( $opt_manifest_file );
293
    Verbose("AbsPath manifest path: $abs_manifest");
294
 
295
    #
296
    #   Ensure the file exists
297
    #
298
    Error("Cannot locate manifest file: $opt_manifest_file") unless -f $opt_manifest_file;
299
    Error("Cannot locate abs manifest file: $opt_manifest_file") unless -f $abs_manifest;
300
 
301
    #
302
    #   Change to the specified subdirectory
303
    #
304
    if ( $opt_rootdir )
305
    {
306
        Verbose ("chdir to specified root directory");
307
        chdir( $opt_rootdir ) || Error("Specified Root Diretory not found: $opt_rootdir");
308
    }
309
 
310
    #
311
    #   Test Md5sum info for each file
312
    #   Process each line to allow success to be suppressed
313
    #
314
    Verbose ("Validate manifest file");
315
    open(CMD, "md5sum --check $abs_manifest  2>&1 |") || Error "Can't run command: $!";
316
    while (<CMD>)
317
    {
318
        chomp;
319
        Verbose2("CMD: $_");
320
        next if ( $_ =~ /^md5sum/ );
321
        if ( $_ =~ /: OK$/ )
322
        {
323
            $match_count++;
324
            next;
325
        };
326
        push @failed, $_;
327
    }
328
    close CMD;
329
 
330
    #
331
    #   Report failed files
332
    #
333
    Message ("Files validated: $match_count");
334
    if ( @failed )
335
    {
336
        Error("The following lines failed the Md5SUM:", @failed);
337
    }
338
}
339
 
340
exit 0;
341
 
342
 
343
#-------------------------------------------------------------------------------
344
#   Documentation
345
#
346
 
347
=pod
348
 
361 dpurdie 349
=for htmltoc    SYSUTIL::
350
 
227 dpurdie 351
=head1 NAME
352
 
353
jats_manifest - Generate and Test a manifest
354
 
355
=head1 SYNOPSIS
356
 
357
jats etool jats_manifest [options]
358
 
359
 Options:
360
    -help              - brief help message
361
    -help -help        - Detailed help message
362
    -man               - Full documentation
379 dpurdie 363
    -verbose[=n]       - Verbose operation
364
    -quiet             - Supress progress messages
227 dpurdie 365
    -generate          - Generate the manifest(default)
366
    -check             - Check the provided manifest
367
    -manifest=file     - Path of the manifest file to use
368
    -rootdir=path      - Root of the file tree to process (default=.)
369
    -exclude=file      - File to excluded during generation
370
    -rewrite=old=new   - Filename to rewrite during generation
371
 
372
=head1 OPTIONS
373
 
374
=over 8
375
 
376
=item B<-help>
377
 
378
Print a brief help message and exits.
379
 
380
=item B<-help -help>
381
 
382
Print a detailed help message with an explanation for each option.
383
 
384
=item B<-man>
385
 
386
Prints the manual page and exits.
387
 
379 dpurdie 388
=item B<-verbose[=n]>
389
 
390
This option will increase the level of verbosity of the command.
391
 
392
If an argument is provided, then it will be used to set the level, otherwise the
393
existing level will be incremented. This option may be specified multiple times.
394
 
395
=item B<-quiet>
396
 
397
This option will supress the '.' progress messages that are created as the manifest
398
is generated.
399
 
227 dpurdie 400
=item B<-generate>
401
 
402
Generate the  manifest file. This is the default operation.
403
 
404
This option may be used in conjunction with B<-check> to generate and check the
405
manifest in the one operation.
406
 
407
=item B<-check>
408
 
409
Check the provided manifest against the provide directory tree.
410
 
411
=item B<-manifest>
412
 
413
This option specifies the path to the manifest file to generate or check. If the
414
file is within the rootdir, then it may cause an error on checking.
415
 
416
This option is mandatory.
417
 
418
=item B<-rootdir=path>
419
 
420
This option specifies the root of the directory tree to process. If it is not
421
provided then then current directory will be used.
422
 
423
=item B<-exclude=file>
424
 
425
This option specifies the name of a file to be excluded from the generated
426
manifest. It has no effect during checking. The named file does not include
427
any path information. All files matching the name will be excluded.
428
 
429
This option may be used multiple times to exclude multiple files.
430
 
431
=item B<-rewrite=old=new>
432
 
433
This option allows a file to be renamed during the manifest generation
434
process. This may be used within the build environment to allow the auto.pl file
435
to be known as build.pl within the manifest.
436
 
437
This option may be used multiple times to rename multiple files.
438
 
439
=back
440
 
441
=head1 DESCRIPTION
442
 
443
This program will generate and check a "manifest" file.
444
 
445
The file consists of a line of information for each file within the
446
specified directory tress. The file is created and processed by the MD5SUM
447
utility.
448
 
449
=head1 EXAMPLE
450
 
451
=head2 Generation
452
 
453
 jats etool jats_manifest -manifest=MANIFEST
454
                          -rootdir=c:/clearcase/view/DPG_SWBase
455
                          -rewrite=auto.pl=build.pl
456
 
457
This command will generate a file called MANIFEST in the current directory based
458
on all files in the directory tree rooted at c:/clearcase/view/DPG_SWBase. The
459
file 'auto.pl' will be stored in the manifest as build.pl.
460
 
461
=head2 Checking
462
 
463
 jats etool jats_manifest -manifest=MANIFEST
464
                          -rootdir=c:/my_static_view/DPG_SWBase
465
                          -check
466
 
467
This command will check the directory tree rooted at
468
c:/my_static_view/DPG_SWBase against the MANIFEST file found in the local directory.
469
 
470
=cut
471