Subversion Repositories DevTools

Rev

Rev 4778 | Rev 4781 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4778 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : jats_runutf.pm
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : JATS Make Time Test Harness Support
10
#                 This package contains fucntions that will be used by JATS
11
#                 to invoke the tests.
12
#
13
#                 This is more powerful that the previous shell-based solution
14
#                 that had problems under windows.
15
#
16
#                 The functions are designed to be invoked as:
17
#                   $(GBE_PERL) -Mjats_runutf -e <function> -- <args>+
18
#
19
#                 The functions in this packages are designed to take parameters
20
#                 from @ARVG as this makes the interface easier to read.
21
#
22
# Usage         : See POD at the end of this file
23
#
24
#......................................................................#
25
 
26
require 5.008_002;
27
use strict;
28
use warnings;
29
 
30
package jats_runutf;
31
 
32
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
33
use Exporter;
34
use JatsError qw(:name=jats_runutf);
4780 dpurdie 35
use Pod::Usage;                             # required for help support
4778 dpurdie 36
use Getopt::Long;
37
use File::Spec;
38
use Time::HiRes;
39
 
40
$VERSION = 1.00;
41
@ISA = qw(Exporter);
42
 
43
# Symbols to autoexport (:DEFAULT tag)
4780 dpurdie 44
@EXPORT = qw( processUtf help man );
4778 dpurdie 45
 
46
#
47
#   Global Variables
48
#
49
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
50
my $opt_utfOuput;
4780 dpurdie 51
my $opt_help = 0;
4778 dpurdie 52
 
53
#   Data to be passed into the filter function
54
#   Defined values are:
55
#       FILTER          - Name of the filter 
56
#       INTERFACE       - Abs Path to Interface directory
57
#       LOCAL           - Abs Path to Local directory
58
#       OUTDIR          - Abs Path to output directory
4780 dpurdie 59
#       OUTFILE         - Abs Path to suggested output file
4778 dpurdie 60
#       PKGDIR          - Abs Path to Packaging directory
61
#       ROOT            - Abs Path to Root of the build
62
#       TARGET          - Current make target
63
#       TYPE            - Built type P or D
64
#
4780 dpurdie 65
our %filterData;
4778 dpurdie 66
 
4780 dpurdie 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
#
4778 dpurdie 78
 
4780 dpurdie 79
sub help
80
{
81
    pod2usage(-verbose => 0, -input =>  __FILE__);
82
}
83
 
84
sub man
85
{
86
    pod2usage(-verbose => 2, -input =>  __FILE__);
87
}
88
 
4778 dpurdie 89
#-------------------------------------------------------------------------------
90
# Function        : processUtf  
91
#
92
# Description     : Main function to process UTF results
93
#                   This function will locate a suitable filter process and invoke
94
#                   it to process the results
95
#
96
#                   The filter process will be provided in a Perl Module
97
#                   It may be a part of JATS or an external modules provided
98
#                   within an external package. ie(utf may provide its own filter)
99
#
100
#
101
# Inputs          : None. Parameters are passed via @ARGV
102
#
103
# Returns         : Nothing
104
#
105
 
106
sub processUtf
107
{
4780 dpurdie 108
    my $argCount = scalar @ARGV;
4778 dpurdie 109
    my $result = GetOptions (
4780 dpurdie 110
                    "help|h:+"      => \$opt_help,
111
                    "manual:3"      => \$opt_help,
4778 dpurdie 112
                    "verbose:+"     => \$opt_verbose,       # Only set to to 0,1 or 3
4780 dpurdie 113
                    "root=s"        => \$filterData{ROOT},
114
                    "filter=s"      => \$filterData{FILTER},
115
                    "interface=s"   => \$filterData{INTERFACE},
116
                    "local=s"       => \$filterData{LOCAL},
117
                    "target=s"      => \$filterData{TARGET},
118
                    "pkgdir=s"      => \$filterData{PKGDIR},
119
                    "type=s"        => \$filterData{TYPE},
4778 dpurdie 120
                    );
121
 
4780 dpurdie 122
    pod2usage(-verbose => 0, -input =>  __FILE__) if ($opt_help == 1 || ! $result || $argCount < 1);
123
    pod2usage(-verbose => 1, -input =>  __FILE__) if ($opt_help == 2 );
124
    pod2usage(-verbose => 2, -input =>  __FILE__) if ($opt_help  > 2);
125
 
4778 dpurdie 126
    #   Reconfigure the verbosity level
127
    ErrorConfig( 'verbose', $opt_verbose);
4780 dpurdie 128
    Error("Internal: No Filter specified") unless defined $filterData{FILTER};
129
    Error("Internal: No PkgDir specified") unless defined $filterData{PKGDIR};
4778 dpurdie 130
 
131
    #
132
    #   Locate the required filter module
133
    #   Filter modules have a name of the form:
134
    #       UtfFilter_<FilterName>.pm
135
    #   And can be located:
136
    #       within JATS
137
    #           in 'TOOLS/LIB'
138
    #       within a Package declared
139
    #           with a BuildPkgArchive or a LinkPkgArchive
140
    #           within the packages 'tools/scripts' subdirectory
141
    #       within the current package
142
    #           Perl modules with ROOT/gbe/utfFilters_*.pm
143
    #                         or  ROOT/gbe/SomeDir/utfFilters_*.pm
144
    #                         or in the current directory
145
 
4780 dpurdie 146
    my $module_name = join('_','UtfFilter', $filterData{FILTER});
4778 dpurdie 147
    Verbose("Filter Module: $module_name");
148
 
149
    #   Extend Perl Module search path for package-local filters
150
    #   Check the current directory
151
    #       The current directory is also within @INC, but it is at the end
152
    #       thus local filter will not override external filters. Place the
153
    #       current directory first - if it conatins a filter.
154
 
155
    if (-f "$module_name.pm" )
156
    {
157
        Verbose("Extend the filter module search path: Current Directory");
158
        unshift @INC, '.';
159
    }
160
    else
161
    {
162
        #
163
        #   Check package-local directory
164
        #       <root>/gbe/utfFilters
165
        #
4780 dpurdie 166
        my $localUtfPath = File::Spec->catfile($filterData{ROOT}, 'gbe', 'utfFilters');
4778 dpurdie 167
        if ( -f( "$localUtfPath/$module_name.pm") )
168
        {
169
            Verbose("Extend the filter module search path: $localUtfPath");
170
            unshift @INC, $localUtfPath;
171
        }
172
    }
173
 
174
    #
175
    #   Locate a Perl Module of the required name
176
    #
177
    eval "require $module_name";
178
    if ($@)
179
    {
180
        Error ("Could not load required filter module: $module_name");
181
    }
182
 
183
    #
184
    #   Ensure that the filter contains the required interface methods
185
    #
186
    foreach my $fname ( qw(processUtf))
187
    {
188
        ReportError("Required function DOES NOT exist: $fname")
189
            unless (defined($module_name->can($fname)));
190
    }
191
    ErrorDoExit();
192
 
193
    #
194
    #   Convert potentially local paths to absolute paths
195
    #       Simplifies use when the CWD is changed
196
    #
197
    foreach my $entry ( qw(INTERFACE LOCAL PKGDIR ROOT))
198
    {
4780 dpurdie 199
        $filterData{$entry}  = File::Spec->rel2abs($filterData{$entry} );
4778 dpurdie 200
    }
201
 
202
    #
203
    #   Ensure that the output directory is present
204
    #       Store utf output directly into the packaging directory in a subdirectoy called 'utfResults'
205
    #           This location is known to the buildtool
206
    #       The output path is provided to the filter process
207
    #
4780 dpurdie 208
    $opt_utfOuput = File::Spec->catfile($filterData{PKGDIR}, 'utfResults');
209
    $filterData{OUTDIR} = $opt_utfOuput;
210
    Error("Packaging directory does not exist") unless -d $filterData{PKGDIR};
4778 dpurdie 211
    mkdir $opt_utfOuput;
212
    Error("Creating utfResults directory") unless -d $opt_utfOuput;
213
 
214
    #
215
    #   Add in known values from the environment
216
    #
4780 dpurdie 217
    $filterData{TYPE} = $ENV{'GBE_MAKE_TYPE'};
218
    Error("Internal: EnvVar 'GBE_MAKE_TYPE' not specified") unless $filterData{TYPE};
4778 dpurdie 219
 
220
    #
221
    #   Create a uniq filename as a suggestion to the filter tool
222
    #       The filter is not forced to use it, but it is a good idea
223
    #
224
    #   Construct the output filename from the microsecond time.
225
    my $time = Time::HiRes::time;
226
    $time =~ s/\.//;
227
    #   Append enough '0' to make 15 chars. This make uniform length numbers
228
    #   and allows filename sorting.
229
    $time .= "0" x (15-length($time));
230
 
4780 dpurdie 231
    my $filename = File::Spec->catfile($opt_utfOuput, "$filterData{TARGET}-$filterData{TYPE}-$time.xml");
4778 dpurdie 232
 
233
    Error("Output file:$filename already exists: $!") if -e $filename;
234
    Verbose("Writing output to $filename");
235
 
4780 dpurdie 236
    $filterData{OUTFILE} = $filename;
4778 dpurdie 237
 
238
    #
4780 dpurdie 239
    #   Diagnostics
240
    #
241
    if (IsVerbose(1))
242
    {
243
        DebugDumpData("Filter Parameters", \%filterData);
244
    }
245
 
246
    #
4778 dpurdie 247
    #   Invoke the process method
248
    #   If it has a problem it should use 'Error(...)' to report it
249
    #   There is no exit code processing
250
    #
4780 dpurdie 251
    Message("Processing UTF test results using filter: $filterData{FILTER}");
252
    $module_name->processUtf(\%filterData);
4778 dpurdie 253
}
254
 
4780 dpurdie 255
=pod 1
4778 dpurdie 256
 
4780 dpurdie 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
 
516
 
4778 dpurdie 517
1;