Subversion Repositories DevTools

Rev

Rev 4780 | Go to most recent revision | Details | 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);
35
use Getopt::Long;
36
use File::Spec;
37
use Time::HiRes;
38
 
39
 
40
$VERSION = 1.00;
41
@ISA = qw(Exporter);
42
 
43
# Symbols to autoexport (:DEFAULT tag)
44
@EXPORT = qw( processUtf $opt_filter );
45
 
46
#
47
#   Global Variables
48
#
49
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
50
my $opt_utfOuput;
51
 
52
#   Data to be passed into the filter function
53
#   Defined values are:
54
#       FILTER          - Name of the filter 
55
#       INTERFACE       - Abs Path to Interface directory
56
#       LOCAL           - Abs Path to Local directory
57
#       OUTDIR          - Abs Path to output directory
58
#       OUTFILE         - Abs Patch to suggested output file
59
#       PKGDIR          - Abs Path to Packaging directory
60
#       ROOT            - Abs Path to Root of the build
61
#       TARGET          - Current make target
62
#       TYPE            - Built type P or D
63
#
64
our %usrData;
65
 
66
#BEGIN
67
#{
68
#    Message "jats_runutf initiated";
69
#}
70
 
71
#-------------------------------------------------------------------------------
72
# Function        : processUtf  
73
#
74
# Description     : Main function to process UTF results
75
#                   This function will locate a suitable filter process and invoke
76
#                   it to process the results
77
#
78
#                   The filter process will be provided in a Perl Module
79
#                   It may be a part of JATS or an external modules provided
80
#                   within an external package. ie(utf may provide its own filter)
81
#
82
#
83
# Inputs          : None. Parameters are passed via @ARGV
84
#
85
# Returns         : Nothing
86
#
87
 
88
sub processUtf
89
{
90
    my $result = GetOptions (
91
                    "verbose:+"     => \$opt_verbose,       # Only set to to 0,1 or 3
92
                    "root=s"        => \$usrData{ROOT},
93
                    "filter=s"      => \$usrData{FILTER},
94
                    "interface=s"   => \$usrData{INTERFACE},
95
                    "local=s"       => \$usrData{LOCAL},
96
                    "target=s"      => \$usrData{TARGET},
97
                    "pkgdir=s"      => \$usrData{PKGDIR},
98
                    );
99
    Error("Incorrect arguments passed to processUtf") 
100
        unless ($result);
101
 
102
    #   Reconfigure the verbosity level
103
    ErrorConfig( 'verbose', $opt_verbose);
104
    Error("Internal: No Filter specified") unless defined $usrData{FILTER};
105
    Error("Internal: No PkgDir specified") unless defined $usrData{PKGDIR};
106
 
107
    #
108
    #   Locate the required filter module
109
    #   Filter modules have a name of the form:
110
    #       UtfFilter_<FilterName>.pm
111
    #   And can be located:
112
    #       within JATS
113
    #           in 'TOOLS/LIB'
114
    #       within a Package declared
115
    #           with a BuildPkgArchive or a LinkPkgArchive
116
    #           within the packages 'tools/scripts' subdirectory
117
    #       within the current package
118
    #           Perl modules with ROOT/gbe/utfFilters_*.pm
119
    #                         or  ROOT/gbe/SomeDir/utfFilters_*.pm
120
    #                         or in the current directory
121
 
122
    my $module_name = join('_','UtfFilter', $usrData{FILTER});
123
    Verbose("Filter Module: $module_name");
124
 
125
    #   Extend Perl Module search path for package-local filters
126
    #   Check the current directory
127
    #       The current directory is also within @INC, but it is at the end
128
    #       thus local filter will not override external filters. Place the
129
    #       current directory first - if it conatins a filter.
130
 
131
    if (-f "$module_name.pm" )
132
    {
133
        Verbose("Extend the filter module search path: Current Directory");
134
        unshift @INC, '.';
135
    }
136
    else
137
    {
138
        #
139
        #   Check package-local directory
140
        #       <root>/gbe/utfFilters
141
        #
142
        my $localUtfPath = File::Spec->catfile($usrData{ROOT}, 'gbe', 'utfFilters');
143
        if ( -f( "$localUtfPath/$module_name.pm") )
144
        {
145
            Verbose("Extend the filter module search path: $localUtfPath");
146
            unshift @INC, $localUtfPath;
147
        }
148
    }
149
 
150
    #
151
    #   Locate a Perl Module of the required name
152
    #
153
    eval "require $module_name";
154
    if ($@)
155
    {
156
        Error ("Could not load required filter module: $module_name");
157
    }
158
 
159
    #
160
    #   Ensure that the filter contains the required interface methods
161
    #
162
    foreach my $fname ( qw(processUtf))
163
    {
164
        ReportError("Required function DOES NOT exist: $fname")
165
            unless (defined($module_name->can($fname)));
166
    }
167
    ErrorDoExit();
168
 
169
    #
170
    #   Convert potentially local paths to absolute paths
171
    #       Simplifies use when the CWD is changed
172
    #
173
    foreach my $entry ( qw(INTERFACE LOCAL PKGDIR ROOT))
174
    {
175
        $usrData{$entry}  = File::Spec->rel2abs($usrData{$entry} );
176
    }
177
 
178
    #
179
    #   Ensure that the output directory is present
180
    #       Store utf output directly into the packaging directory in a subdirectoy called 'utfResults'
181
    #           This location is known to the buildtool
182
    #       The output path is provided to the filter process
183
    #
184
    $opt_utfOuput = File::Spec->catfile($usrData{PKGDIR}, 'utfResults');
185
    $usrData{OUTDIR} = $opt_utfOuput;
186
    Error("Packaging directory does not exist") unless -d $usrData{PKGDIR};
187
    mkdir $opt_utfOuput;
188
    Error("Creating utfResults directory") unless -d $opt_utfOuput;
189
 
190
    #
191
    #   Add in known values from the environment
192
    #
193
    $usrData{TYPE} = $ENV{'GBE_MAKE_TYPE'};
194
 
195
    #
196
    #   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
198
    #
199
    #   Construct the output filename from the microsecond time.
200
    my $time = Time::HiRes::time;
201
    $time =~ s/\.//;
202
    #   Append enough '0' to make 15 chars. This make uniform length numbers
203
    #   and allows filename sorting.
204
    $time .= "0" x (15-length($time));
205
 
206
    my $filename = File::Spec->catfile($opt_utfOuput, "$usrData{TARGET}-$usrData{TYPE}-$time.xml");
207
 
208
    Error("Output file:$filename already exists: $!") if -e $filename;
209
    Verbose("Writing output to $filename");
210
 
211
    $usrData{OUTFILE} = $filename;
212
 
213
    #
214
    #   Invoke the process method
215
    #   If it has a problem it should use 'Error(...)' to report it
216
    #   There is no exit code processing
217
    #
218
    Message("Processing UTF test results using filter: $usrData{FILTER}");
219
    $module_name->processUtf(\%usrData);
220
}
221
 
222
 
223
1;