Subversion Repositories DevTools

Rev

Rev 4778 | Rev 4781 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4778 Rev 4780
Line 30... Line 30...
30
package jats_runutf;
30
package jats_runutf;
31
 
31
 
32
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
32
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
33
use Exporter;
33
use Exporter;
34
use JatsError qw(:name=jats_runutf);
34
use JatsError qw(:name=jats_runutf);
-
 
35
use Pod::Usage;                             # required for help support
35
use Getopt::Long;
36
use Getopt::Long;
36
use File::Spec;
37
use File::Spec;
37
use Time::HiRes;
38
use Time::HiRes;
38
 
39
 
39
 
-
 
40
$VERSION = 1.00;
40
$VERSION = 1.00;
41
@ISA = qw(Exporter);
41
@ISA = qw(Exporter);
42
 
42
 
43
# Symbols to autoexport (:DEFAULT tag)
43
# Symbols to autoexport (:DEFAULT tag)
44
@EXPORT = qw( processUtf $opt_filter );
44
@EXPORT = qw( processUtf help man );
45
 
45
 
46
#
46
#
47
#   Global Variables
47
#   Global Variables
48
#
48
#
49
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
49
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
50
my $opt_utfOuput;
50
my $opt_utfOuput;
-
 
51
my $opt_help = 0;
51
 
52
 
52
#   Data to be passed into the filter function
53
#   Data to be passed into the filter function
53
#   Defined values are:
54
#   Defined values are:
54
#       FILTER          - Name of the filter 
55
#       FILTER          - Name of the filter 
55
#       INTERFACE       - Abs Path to Interface directory
56
#       INTERFACE       - Abs Path to Interface directory
56
#       LOCAL           - Abs Path to Local directory
57
#       LOCAL           - Abs Path to Local directory
57
#       OUTDIR          - Abs Path to output directory
58
#       OUTDIR          - Abs Path to output directory
58
#       OUTFILE         - Abs Patch to suggested output file
59
#       OUTFILE         - Abs Path to suggested output file
59
#       PKGDIR          - Abs Path to Packaging directory
60
#       PKGDIR          - Abs Path to Packaging directory
60
#       ROOT            - Abs Path to Root of the build
61
#       ROOT            - Abs Path to Root of the build
61
#       TARGET          - Current make target
62
#       TARGET          - Current make target
62
#       TYPE            - Built type P or D
63
#       TYPE            - Built type P or D
63
#
64
#
64
our %usrData;
65
our %filterData;
-
 
66
 
-
 
67
#-------------------------------------------------------------------------------
-
 
68
# Function        : help
-
 
69
#                   man 
-
 
70
#
-
 
71
# Description     : Utility functions to make is easier for users to get POD
-
 
72
#                   from this module
-
 
73
#
-
 
74
# Inputs          : 
-
 
75
#
-
 
76
# Returns         : 
-
 
77
#
-
 
78
 
-
 
79
sub help
-
 
80
{
-
 
81
    pod2usage(-verbose => 0, -input =>  __FILE__);
-
 
82
}
65
 
83
 
66
#BEGIN
84
sub man
67
#{
85
{
68
#    Message "jats_runutf initiated";
86
    pod2usage(-verbose => 2, -input =>  __FILE__);
69
#}
87
}
70
 
88
 
71
#-------------------------------------------------------------------------------
89
#-------------------------------------------------------------------------------
72
# Function        : processUtf  
90
# Function        : processUtf  
73
#
91
#
74
# Description     : Main function to process UTF results
92
# Description     : Main function to process UTF results
Line 85... Line 103...
85
# Returns         : Nothing
103
# Returns         : Nothing
86
#
104
#
87
 
105
 
88
sub processUtf
106
sub processUtf
89
{
107
{
-
 
108
    my $argCount = scalar @ARGV;
90
    my $result = GetOptions (
109
    my $result = GetOptions (
-
 
110
                    "help|h:+"      => \$opt_help,
-
 
111
                    "manual:3"      => \$opt_help,
91
                    "verbose:+"     => \$opt_verbose,       # Only set to to 0,1 or 3
112
                    "verbose:+"     => \$opt_verbose,       # Only set to to 0,1 or 3
92
                    "root=s"        => \$usrData{ROOT},
113
                    "root=s"        => \$filterData{ROOT},
93
                    "filter=s"      => \$usrData{FILTER},
114
                    "filter=s"      => \$filterData{FILTER},
94
                    "interface=s"   => \$usrData{INTERFACE},
115
                    "interface=s"   => \$filterData{INTERFACE},
95
                    "local=s"       => \$usrData{LOCAL},
116
                    "local=s"       => \$filterData{LOCAL},
96
                    "target=s"      => \$usrData{TARGET},
117
                    "target=s"      => \$filterData{TARGET},
97
                    "pkgdir=s"      => \$usrData{PKGDIR},
118
                    "pkgdir=s"      => \$filterData{PKGDIR},
-
 
119
                    "type=s"        => \$filterData{TYPE},
98
                    );
120
                    );
-
 
121
 
-
 
122
    pod2usage(-verbose => 0, -input =>  __FILE__) if ($opt_help == 1 || ! $result || $argCount < 1);
99
    Error("Incorrect arguments passed to processUtf") 
123
    pod2usage(-verbose => 1, -input =>  __FILE__) if ($opt_help == 2 );
100
        unless ($result);
124
    pod2usage(-verbose => 2, -input =>  __FILE__) if ($opt_help  > 2);
101
 
125
 
102
    #   Reconfigure the verbosity level
126
    #   Reconfigure the verbosity level
103
    ErrorConfig( 'verbose', $opt_verbose);
127
    ErrorConfig( 'verbose', $opt_verbose);
104
    Error("Internal: No Filter specified") unless defined $usrData{FILTER};
128
    Error("Internal: No Filter specified") unless defined $filterData{FILTER};
105
    Error("Internal: No PkgDir specified") unless defined $usrData{PKGDIR};
129
    Error("Internal: No PkgDir specified") unless defined $filterData{PKGDIR};
106
    
130
    
107
    #
131
    #
108
    #   Locate the required filter module
132
    #   Locate the required filter module
109
    #   Filter modules have a name of the form:
133
    #   Filter modules have a name of the form:
110
    #       UtfFilter_<FilterName>.pm
134
    #       UtfFilter_<FilterName>.pm
Line 117... Line 141...
117
    #       within the current package
141
    #       within the current package
118
    #           Perl modules with ROOT/gbe/utfFilters_*.pm
142
    #           Perl modules with ROOT/gbe/utfFilters_*.pm
119
    #                         or  ROOT/gbe/SomeDir/utfFilters_*.pm
143
    #                         or  ROOT/gbe/SomeDir/utfFilters_*.pm
120
    #                         or in the current directory
144
    #                         or in the current directory
121
 
145
 
122
    my $module_name = join('_','UtfFilter', $usrData{FILTER});
146
    my $module_name = join('_','UtfFilter', $filterData{FILTER});
123
    Verbose("Filter Module: $module_name");
147
    Verbose("Filter Module: $module_name");
124
 
148
 
125
    #   Extend Perl Module search path for package-local filters
149
    #   Extend Perl Module search path for package-local filters
126
    #   Check the current directory
150
    #   Check the current directory
127
    #       The current directory is also within @INC, but it is at the end
151
    #       The current directory is also within @INC, but it is at the end
Line 137... Line 161...
137
    {
161
    {
138
        #
162
        #
139
        #   Check package-local directory
163
        #   Check package-local directory
140
        #       <root>/gbe/utfFilters
164
        #       <root>/gbe/utfFilters
141
        #
165
        #
142
        my $localUtfPath = File::Spec->catfile($usrData{ROOT}, 'gbe', 'utfFilters');
166
        my $localUtfPath = File::Spec->catfile($filterData{ROOT}, 'gbe', 'utfFilters');
143
        if ( -f( "$localUtfPath/$module_name.pm") )
167
        if ( -f( "$localUtfPath/$module_name.pm") )
144
        {
168
        {
145
            Verbose("Extend the filter module search path: $localUtfPath");
169
            Verbose("Extend the filter module search path: $localUtfPath");
146
            unshift @INC, $localUtfPath;
170
            unshift @INC, $localUtfPath;
147
        }
171
        }
Line 170... Line 194...
170
    #   Convert potentially local paths to absolute paths
194
    #   Convert potentially local paths to absolute paths
171
    #       Simplifies use when the CWD is changed
195
    #       Simplifies use when the CWD is changed
172
    #
196
    #
173
    foreach my $entry ( qw(INTERFACE LOCAL PKGDIR ROOT))
197
    foreach my $entry ( qw(INTERFACE LOCAL PKGDIR ROOT))
174
    {
198
    {
175
        $usrData{$entry}  = File::Spec->rel2abs($usrData{$entry} );
199
        $filterData{$entry}  = File::Spec->rel2abs($filterData{$entry} );
176
    }
200
    }
177
    
201
    
178
    #
202
    #
179
    #   Ensure that the output directory is present
203
    #   Ensure that the output directory is present
180
    #       Store utf output directly into the packaging directory in a subdirectoy called 'utfResults'
204
    #       Store utf output directly into the packaging directory in a subdirectoy called 'utfResults'
181
    #           This location is known to the buildtool
205
    #           This location is known to the buildtool
182
    #       The output path is provided to the filter process
206
    #       The output path is provided to the filter process
183
    #
207
    #
184
    $opt_utfOuput = File::Spec->catfile($usrData{PKGDIR}, 'utfResults');
208
    $opt_utfOuput = File::Spec->catfile($filterData{PKGDIR}, 'utfResults');
185
    $usrData{OUTDIR} = $opt_utfOuput;
209
    $filterData{OUTDIR} = $opt_utfOuput;
186
    Error("Packaging directory does not exist") unless -d $usrData{PKGDIR};
210
    Error("Packaging directory does not exist") unless -d $filterData{PKGDIR};
187
    mkdir $opt_utfOuput;
211
    mkdir $opt_utfOuput;
188
    Error("Creating utfResults directory") unless -d $opt_utfOuput;
212
    Error("Creating utfResults directory") unless -d $opt_utfOuput;
189
 
213
 
190
    #
214
    #
191
    #   Add in known values from the environment
215
    #   Add in known values from the environment
192
    #
216
    #
193
    $usrData{TYPE} = $ENV{'GBE_MAKE_TYPE'};
217
    $filterData{TYPE} = $ENV{'GBE_MAKE_TYPE'};
-
 
218
    Error("Internal: EnvVar 'GBE_MAKE_TYPE' not specified") unless $filterData{TYPE};
194
 
219
 
195
    #
220
    #
196
    #   Create a uniq filename as a suggestion to the filter tool
221
    #   Create a uniq filename as a suggestion to the filter tool
197
    #       The filter is not forced to use it, but it is a good idea
222
    #       The filter is not forced to use it, but it is a good idea
198
    #
223
    #
Line 201... Line 226...
201
    $time =~ s/\.//;
226
    $time =~ s/\.//;
202
    #   Append enough '0' to make 15 chars. This make uniform length numbers
227
    #   Append enough '0' to make 15 chars. This make uniform length numbers
203
    #   and allows filename sorting.
228
    #   and allows filename sorting.
204
    $time .= "0" x (15-length($time));
229
    $time .= "0" x (15-length($time));
205
 
230
 
206
    my $filename = File::Spec->catfile($opt_utfOuput, "$usrData{TARGET}-$usrData{TYPE}-$time.xml");
231
    my $filename = File::Spec->catfile($opt_utfOuput, "$filterData{TARGET}-$filterData{TYPE}-$time.xml");
207
 
232
 
208
    Error("Output file:$filename already exists: $!") if -e $filename;
233
    Error("Output file:$filename already exists: $!") if -e $filename;
209
    Verbose("Writing output to $filename");
234
    Verbose("Writing output to $filename");
210
 
235
 
211
    $usrData{OUTFILE} = $filename;
236
    $filterData{OUTFILE} = $filename;
-
 
237
 
-
 
238
    #
-
 
239
    #   Diagnostics
-
 
240
    #
-
 
241
    if (IsVerbose(1))
-
 
242
    {
-
 
243
        DebugDumpData("Filter Parameters", \%filterData);
-
 
244
    }
212
 
245
 
213
    #
246
    #
214
    #   Invoke the process method
247
    #   Invoke the process method
215
    #   If it has a problem it should use 'Error(...)' to report it
248
    #   If it has a problem it should use 'Error(...)' to report it
216
    #   There is no exit code processing
249
    #   There is no exit code processing
217
    #
250
    #
218
    Message("Processing UTF test results using filter: $usrData{FILTER}");
251
    Message("Processing UTF test results using filter: $filterData{FILTER}");
219
    $module_name->processUtf(\%usrData);
252
    $module_name->processUtf(\%filterData);
220
}
253
}
221
 
254
 
-
 
255
=pod 1
-
 
256
 
-
 
257
=for htmltoc    SYSUTIL::
-
 
258
 
-
 
259
=head1 NAME
-
 
260
 
-
 
261
jats_runutf - Post Process UTF results for build system
-
 
262
 
-
 
263
=head1 SYNOPSIS
-
 
264
 
-
 
265
  $(GBE_PERL) -Mjats_runutf -e processUtf -- <args>
-
 
266
 
-
 
267
 Options:
-
 
268
    -help[=n]       - Brief help message
-
 
269
    -help -help     - Detailed help message
-
 
270
    -man            - Full documentation
-
 
271
    -verbose[=n]    - Verbose operation
-
 
272
    -filter=name    - Name of the required processing filter
-
 
273
    -target=name    - Current build target
-
 
274
    -root=path      - Path to the root of the build
-
 
275
    -pkgdir=path    - Path to the packaging directory
-
 
276
    -interface=path - Path to the build interface directory
-
 
277
    -local=path     - Path to the local build directory
-
 
278
 
-
 
279
=head1 OPTIONS
-
 
280
 
-
 
281
=over 8
-
 
282
 
-
 
283
=item B<-help>
-
 
284
 
-
 
285
Print a brief help message and exits.
-
 
286
 
-
 
287
=item B<-help -help>
-
 
288
 
-
 
289
Print a detailed help message with an explanation for each option.
-
 
290
 
-
 
291
=item B<-man>
-
 
292
 
-
 
293
Prints the manual page and exits.
-
 
294
 
-
 
295
=item B<-verbose>
-
 
296
 
-
 
297
This option will display progress information as the program executes.
-
 
298
 
-
 
299
=item B<-filter=name>
-
 
300
 
-
 
301
Name of the required processing filter.
-
 
302
 
-
 
303
=item B<-target=name>
-
 
304
 
-
 
305
The current build target.
-
 
306
 
-
 
307
=item B<-root=path>
-
 
308
 
-
 
309
The path to the root of the current build.
-
 
310
 
-
 
311
=item B<-pkgdir=path>
-
 
312
 
-
 
313
The path to the packaging directory
-
 
314
 
-
 
315
=item B<-interface=path>
-
 
316
 
-
 
317
The path to the build interface directory
-
 
318
 
-
 
319
=item B<-local=path>
-
 
320
 
-
 
321
The path to the local build directory
-
 
322
 
-
 
323
=back
-
 
324
 
-
 
325
=head1 DESCRIPTION
-
 
326
 
-
 
327
This tool is not designed to be run directly by users. It is intended to be run by the 
-
 
328
JATS generated makefiles in conjunction with unit tests to process the output from a unit 
-
 
329
test to provide a common output format to be passed on the build system.
-
 
330
 
-
 
331
Normally this process only occurs with the Auto BuildTool environment.
-
 
332
 
-
 
333
The tool provides the following operations:
-
 
334
 
-
 
335
=over 4
-
 
336
 
-
 
337
=item *
-
 
338
 
-
 
339
Sanitize environment
-
 
340
 
-
 
341
The environment passed to the filter processing module will be verified. 
-
 
342
The path to the output directory will be created if required. All paths will be absolute.
-
 
343
 
-
 
344
=item *
-
 
345
 
-
 
346
Locate the required filter processing module. The module must be a Perl Module with a name of the form 'UtfFilter_<name>'
-
 
347
 
-
 
348
=item *
-
 
349
 
-
 
350
Invoke the required filter module.
-
 
351
 
-
 
352
=back
-
 
353
 
-
 
354
=head2 Locating the Filter Module
-
 
355
 
-
 
356
The filter module may be located, in order of precedence, within:
-
 
357
 
-
 
358
=over 4
-
 
359
 
-
 
360
=item *
-
 
361
 
-
 
362
The package currently being built.
-
 
363
 
-
 
364
The package may provide its own UTF post processing module. This is not encouraged.
-
 
365
 
-
 
366
The following locations will be examined for a suitable module:
-
 
367
 
-
 
368
=over 4
-
 
369
 
-
 
370
=item *
-
 
371
 
-
 
372
The current directory. The directory of the makefile.pl that is running the unit test.
-
 
373
 
-
 
374
=item *
-
 
375
 
-
 
376
A directory in the Build Root called 'gbe/UtfFilters'
-
 
377
 
-
 
378
=back
-
 
379
 
-
 
380
=item *
-
 
381
 
-
 
382
An external Package, within the gbe/scripts directory.
-
 
383
 
-
 
384
The package can be specified with either LinkPkgArchive or BuildPkgArchive directive 
-
 
385
within the current packages build.pl file.
-
 
386
 
-
 
387
=item *
-
 
388
 
-
 
389
Within JATS.
-
 
390
 
-
 
391
Jats may provide useful filter modules.
-
 
392
 
-
 
393
=back
-
 
394
 
-
 
395
=head2 Filter Module Interface
-
 
396
 
-
 
397
The filter module Interface consists of four items:
-
 
398
 
-
 
399
=over 4
-
 
400
 
-
 
401
=item 1 The name of the Package
-
 
402
 
-
 
403
=item 1 The named function with the package
-
 
404
 
-
 
405
=item 1 Arguments passed to the named function
-
 
406
 
-
 
407
=item 1 The processing expected to be done by the named function
-
 
408
 
-
 
409
=item 1 The Output Format
-
 
410
 
-
 
411
=back
-
 
412
 
-
 
413
=head3 The name of the Package
-
 
414
 
-
 
415
Each filter function is in its own package. The package name is created by concatenating the 
-
 
416
text 'UtfFilter_' with the name of the required filter. 
-
 
417
 
-
 
418
ie: If the required filter is 'junit4', then the name of the filter package must 
-
 
419
be UtfFilter_junit4 and it will be held in a file named UtfFilter_junit4.pm.
-
 
420
 
-
 
421
=head3 The named function with the package
-
 
422
 
-
 
423
The filter package must provide a function called 'processUtf'
-
 
424
 
-
 
425
=head3 Arguments passed to the named function
-
 
426
 
-
 
427
The processing function 'processUtf' is called with two arguments:
-
 
428
 
-
 
429
=over 4
-
 
430
 
-
 
431
=item 1
-
 
432
 
-
 
433
The name of the package
-
 
434
 
-
 
435
=item 2
-
 
436
 
-
 
437
A reference to a Perl hash. The hach will contain the following named items:
-
 
438
 
-
 
439
=over 4
-
 
440
 
-
 
441
=item       FILTER          
-
 
442
 
-
 
443
The Name of the filter 
-
 
444
 
-
 
445
=item       INTERFACE       
-
 
446
 
-
 
447
The absolute Path to Interface directory
-
 
448
 
-
 
449
=item       LOCAL
-
 
450
 
-
 
451
The absolute Path to Local directory
-
 
452
 
-
 
453
=item       OUTDIR
-
 
454
 
-
 
455
The absolute Path to output directory
-
 
456
 
-
 
457
=item       OUTFILE
-
 
458
 
-
 
459
The absolute Path to suggested output file. The user does not need to use this name. It is 
-
 
460
provided to remove the need for each filter to create a unique name.
-
 
461
 
-
 
462
This file will not exist.
-
 
463
 
-
 
464
=item       PKGDIR
-
 
465
 
-
 
466
The absolute Path to Packaging directory. This directory will exist.
-
 
467
 
-
 
468
=item       ROOT
-
 
469
 
-
 
470
The absolute Path to Root of the build
-
 
471
 
-
 
472
=item       TARGET
-
 
473
 
-
 
474
The current make target
-
 
475
 
-
 
476
=item       TYPE
-
 
477
 
-
 
478
The build type P or D
-
 
479
 
-
 
480
=back
-
 
481
 
-
 
482
The return value from the function 'processUtf' is ignored. If the function encounters 
-
 
483
any error it should use the Jats 'Error' function to report the error.
-
 
484
 
-
 
485
=back
-
 
486
 
-
 
487
=head3 The processing expected to be done by the named function
-
 
488
 
-
 
489
The processing function is expected to transform the results of a unit test into 
-
 
490
a constient form so that they can be processed by the remainder of the build tool.
-
 
491
 
-
 
492
The processing should:
-
 
493
 
-
 
494
=over 4
-
 
495
 
-
 
496
=item *
-
 
497
 
-
 
498
Create information in the OUTDIR directory. 
-
 
499
 
-
 
500
The filter may create a new file or insert information into an existing file. 
-
 
501
 
-
 
502
The user may make use of the OUTFILE path, but this is not mandatory.
-
 
503
 
-
 
504
=item *
-
 
505
 
-
 
506
Report errors by calling the Jats 'Error' function. This will terminate processing.
-
 
507
 
-
 
508
=back
-
 
509
 
-
 
510
=head3 The Output Format
-
 
511
 
-
 
512
Yet to be defined.
-
 
513
 
-
 
514
=cut
-
 
515
 
222
 
516
 
223
1;
517
1;