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   : gen_metrics.pl
6
# Module type   : JATS Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): JATS
9
#
10
# Description   : Post process the JATS build and makefiles and generate
11
#                 a collection of program metrics
12
#
13
# Usage:          JATS etool gen_metrics
14
#
15
# Version   Who     Date        Description
16
#           DDP     07-Dec-04   Created
17
#......................................................................#
18
 
255 dpurdie 19
require 5.006_001;
227 dpurdie 20
 
21
use strict;
22
use warnings;
23
use JatsError;
24
use JatsMakeInfo;
25
use ReadBuildConfig qw(:All);
26
use FileUtils;
27
use JatsSystem;
28
use JatsMakeConfig;
29
 
30
use Pod::Usage;                             # Required for help support
31
use Getopt::Long;                           # Option processing
32
 
33
#
34
#   Global variables
35
#
36
my  $VERSION = "1.0.0";                     # Update this
37
my  %source;                                # Source files
38
my  %include;                               # Local include directories
39
my  $cccc_path = "c:/Program Files/CCCC/cccc.exe";   # Path to CCCC utility
40
my  $cccc_out  = "./interface/cccc";        # Output directory
41
 
42
#
43
#   Global variables - Options
44
#
45
my  $opt_help = 0;
46
my  $opt_manual;
47
my  $opt_verbose = 0;
48
my  $opt_headers = 0;
49
my  $opt_cccc_path;
50
 
51
my $result = GetOptions (
52
                "help+"         => \$opt_help,              # flag, multiple use allowed
53
                "manual"        => \$opt_manual,            # flag, multiple use allowed
54
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
55
                "headers!"      => \$opt_headers,           # Flag, +no allowed
56
                "cccc=s"        => \$opt_cccc_path          # String
57
                );
58
 
59
                #
60
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
61
                #
62
 
63
#-------------------------------------------------------------------------------
64
# Function        : Main entry point
65
#
66
# Description     : Parse user arguments
67
#                   Generate metrics
68
#
69
# Inputs          : None
70
#
71
# Returns         : Error code
72
#
73
 
74
#
75
#   Process help and manual options
76
#
77
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
78
pod2usage(-verbose => 1)  if ($opt_help == 2 );
79
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
80
 
81
#
82
#   Configure the Error reporting process now that we have the user options
83
#
84
ErrorConfig( 'name'    =>'METRICS',
85
             'verbose' => $opt_verbose,
86
            );
87
 
88
#
89
#   Ensure that we are in a suitable directory
90
#   Need to be in the project root directory
91
#
92
Verbose ("Locate project root directory");
93
 
94
#
95
#   Locate the base of the JATS build
96
#   This will be provided by Makefile.gbe
97
#
98
ReadMakeInfo();
99
my $interface_path = "$::ScmRoot/$::ScmInterface";
100
 
101
#
102
#   Read in all the makefile data in one hit
103
#
104
my $mfdata = JatsMakeConfigReader::GetAllMakeInfo();
105
#   Sanity test of user options
106
#
107
 
108
if ( $opt_cccc_path )
109
{
110
    Error ("CCCC not found: $opt_cccc_path") unless ( -x $opt_cccc_path );
111
    $cccc_path = $opt_cccc_path;
112
}
113
Error ("CCCC not found: $cccc_path" ) unless ( -x "$cccc_path" );
114
 
115
#-------------------------------------------------------------------------------
116
#   Process all the constituent makefile data and buildup a list of source files
117
#
118
foreach my $dir ( $mfdata->AllDirs() )
119
{
120
    my $mff = $mfdata->GetEntry($dir);
121
 
122
    Verbose ("Processing: $dir");
123
 
124
    foreach my $tgt ( $mff->GetPlatforms() )
125
    {
126
        my $cwd = $mff->GetDataItem($tgt, '$Cwd');
127
        Verbose( "Target: $tgt, CWD: $cwd\n");
128
 
129
        #
130
        #   Locate all the C, C++ and headers
131
        #   I don't think JATS handles Java file at the moment
132
        #
133
        foreach my $var ( '@CXXSRCS' ,'@CSRCS', '@CHDRS' )
134
        {
135
            if ( my $data = $mff->GetDataItem($tgt, $var) )
136
            {
137
                Verbose2( "$var : @{$data}");
138
                foreach my $file ( @$data )
139
                {
140
                    #
141
                    #   Add the makefile's CWD to the file unless the file
142
                    #   already has an absolute path
143
                    #
144
                    $file = $cwd . "/" . $file unless ( $file =~ m~^/~ );
145
                    unless ( $source{$file} )
146
                    {
147
                        $source{$file} = 1;
148
                        Verbose ("Adding: $file");
149
                    }
150
                }
151
            }
152
        }
153
 
154
        #
155
        #   Locate all the included directories in case we need
156
        #   an exhaustive search of all header files
157
        #
158
        foreach my $var ( '@INCDIRS' )
159
        {
160
            if ( my $data = $mff->GetDataItem($tgt, $var) )
161
            {
162
                Verbose2( "$var : @{$data}");
163
                foreach my $dir ( @$data )
164
                {
165
                    #
166
                    #   Add the makefile's CWD to the file unless the file
167
                    #   already has an absolute path
168
                    #
169
                    $dir = $cwd . "/" . $dir unless ( $dir =~ m~^/~ );
170
                    unless ( $include{$dir} )
171
                    {
172
                        $include{$dir} = 1;
173
                        Verbose ("Adding dir: $dir");
174
                    }
175
                }
176
            }
177
        }
178
    }
179
}
180
 
181
#-------------------------------------------------------------------------------
182
#   Now have a complete list of files that are specified as source files
183
#   within all the project makefile.pl's, but these are not all the source
184
#   files as the included header files are not mentioned
185
#
186
#   This may be sufficient as it is a list of the interface file
187
#
188
#   If requested add all the header files from all the include directories
189
if ( $opt_headers )
190
{
191
    foreach my $dir ( keys %include )
192
    {
193
        my @files = glob ( "$dir/*.h" );
194
        foreach my $file ( @files )
195
        {
196
            unless ( $source{$file} )
197
            {
198
                $source{$file} = 1;
199
                Verbose ("Adding header: $file");
200
            }
201
        }
202
    }
203
}
204
 
205
#-------------------------------------------------------------------------------
206
#   Kick of the CCCC processing of all the discovered source files
207
#   Remove any existing CCCC output
208
#
209
    System ("rm -rf $cccc_out");
210
    System ("mkdir -p $cccc_out");
211
 
212
    my @file_list = sort keys( %source );
213
    System ("\"$cccc_path\" --outdir=$cccc_out @file_list");
214
 
215
    # --debug_mask=plc
216
 
217
    exit;
218
 
219
#-------------------------------------------------------------------------------
220
#   Documentation
221
#
222
 
223
=pod
224
 
361 dpurdie 225
=for htmltoc    SYSUTIL::
226
 
227 dpurdie 227
=head1 NAME
228
 
229
gen_metrics - Create Metrics
230
 
231
=head1 SYNOPSIS
232
 
233
 jats etool gen_metrics [options]
234
 
235
 Options:
236
    -help              - Brief help message
237
    -help -help        - Detailed help message
238
    -man               - Full documentation
239
    -verbose           - Verbose display of operation
240
    -cccc=path         - Alternate location of the CCCC program
241
    -[no]headers       - Add all headers files from included subdirectories
242
 
243
=head1 OPTIONS
244
 
245
=over 8
246
 
247
=item B<-help>
248
 
249
Print a brief help message and exits.
250
 
251
=item B<-help -help>
252
 
253
Print a detailed help message with an explanation for each option.
254
 
255
=item B<-man>
256
 
257
Prints the manual page and exits.
258
 
259
=item B<-verbose>
260
 
261
Prints internal information during the execution of the script. This option
262
does not affect the operation of the underlying CCCC program
263
 
264
=item B<-cccc=path>
265
 
266
This option specifies the absolute path of the F<CCCC.EXE> utility program. The
267
default operation looks for "cccc" in its standard installed location. Under
268
Windows this is F<c:/Program Files/CCCC/cccc.exe>
269
 
270
=item B<-[no]headers>
271
 
272
Includes all the ".h" files in directories named in "IncDir" directives.
273
The default operation is "noheaders"
274
 
275
=back
276
 
277
=head1 DESCRIPTION
278
 
279
The program uses a utility called CCCC to generate a variety of static
280
program metrics including:
281
 
282
=over 8
283
 
284
=item *
285
 
286
Lines of Code
287
 
288
=item *
289
 
290
Comment Lines
291
 
292
=item  *
293
 
294
McCabe's Cyclomatic Complexity
295
 
296
=back
297
 
298
CCCC is a tool for the analysis of source code in various languages (primarily
299
C++), which generates a report in HTML format on various measurements of the
300
code processed. Although the tool was originally implemented to process C++ and
301
ANSI C, the present version is also able to process Java source files, and
302
support has been present in earlier versions for Ada95. The name CCCC stands for
303
'C and C++ Code Counter'.
304
 
305
This program uses the information generated by the "JATS BUILD" process to
306
determine a list of files to been processed by the utility. Files for
307
inclusion are:
308
 
309
=over 4
310
 
311
=item *
312
 
313
Files specified with a "Src" directive
314
Only C, C++ and Header files are included
315
 
316
=item *
317
 
318
All headers files in directories named in a "AddIncDir" or
319
"AddDir" directive. This operation is not default. It must
320
been invoked with the "-header" option
321
 
322
=back
323
 
324
The CCCC program generates a number of output files in the interface/cccc
325
directory. The main files of interest are:
326
 
327
=over 4
328
 
329
=item *
330
 
331
cccc.html - Main output file
332
 
333
=item *
334
 
335
anonymous.html - Details of "C" files by function.
336
This file contains information that is not present in the
337
summary file.
338
 
339
=back
340
 
341
CCCC also generates a series of XML files that contains the same information
342
as the HTML files.
343
 
344
=head1 USAGE
345
 
346
The gen_metrics program uses information extracted from the build.pl and
347
makefile.pl files when the sandbox build environment is created. This
348
information is generated by the JATS BUILD command. This command must been run
349
before the gen_metrics program.
350
 
351
The gen_metrics program is an extension to the JATS framework. It must be run
352
within the JATS framework and not standalone.
353
 
354
=head2  Example
355
 
356
The following command will generate a set of metrics for the files in a sandbox.
357
It is assumed that the user is in the same directory as the packages build.pl
358
script.
359
 
360
    jats build
361
    jats etool gen_metrics.pl
362
 
363
This command sequence will do the following:
364
 
365
=over 4
366
 
367
=item C<jats build>
368
 
369
This will build the sandbox, generate makefile files and store information
370
extracted from the makefile.pl for possible post processing.
371
 
372
This command does not have to immediately preceed the metrics generation
373
command, but it does need to be performed at some stage before the metrics
374
cane be generated.
375
 
376
=item C<jats etool gen_metrics.pl>
377
 
378
This will post process the stored information and determine the source files
379
for the package, before running the CCCC utility over the files.
380
 
381
=back
382
 
383
=cut
384