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_dirlist.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 list of directories that need to be labeled
12
#
13
# Usage:          JATS etool gen_dirlist
14
#
15
# Version   Who     Date        Description
16
#           DDP     05-Sep-05   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 JatsMakeConfig;
28
 
29
use Pod::Usage;                             # Required for help support
30
use Getopt::Long;                           # Option processing
31
 
32
#
33
#   Global variables
34
#
35
my  $VERSION = "1.0.0";                     # Update this
36
my  %include;                               # Local include directories
37
 
38
#
39
#   Global variables - Options
40
#
41
my  $opt_help = 0;
42
my  $opt_manual;
43
my  $opt_verbose = 0;
44
 
45
my $result = GetOptions (
46
                "help+"         => \$opt_help,              # flag, multiple use allowed
47
                "manual"        => \$opt_manual,            # flag, multiple use allowed
48
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
49
                );
50
 
51
                #
52
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
53
                #
54
 
55
#-------------------------------------------------------------------------------
56
# Function        : Main entry point
57
#
58
# Description     : Parse user arguments
59
#                   Generate metrics
60
#
61
# Inputs          : None
62
#
63
# Returns         : Error code
64
#
65
 
66
#
67
#   Process help and manual options
68
#
69
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
70
pod2usage(-verbose => 1)  if ($opt_help == 2 );
71
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
72
 
73
ErrorConfig( 'name'    =>'DIRLIST',
74
             'verbose' => $opt_verbose,
75
            );
76
 
77
#
78
#   Ensure that we are in a suitable directory
79
#   Need to be in the project root directory
80
#
81
Verbose ("Locate project root directory");
82
 
83
#
84
#   Locate the base of the JATS build
85
#   This will be provided by Makefile.gbe
86
#
87
ReadMakeInfo();
88
my $interface_path = "$::ScmRoot/$::ScmInterface";
89
 
90
#
91
#   Read in all the makefile data in one hit
92
#
93
my $mfdata = JatsMakeConfigReader::GetAllMakeInfo();
94
 
95
#-------------------------------------------------------------------------------
96
#   Generate a list of known VOBS
97
#
98
    my %VOBS;
99
    my $cmd = "cleartool lsvob -short";
100
    open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
101
    while (<CMD>)
102
    {
103
        #
104
        #   Filter output from the user
105
        #
106
        chomp;
107
        tr~\\/~/~s;
108
        s~^/[^/]/~/~;
109
        s~^/~~;
110
        s~^vobs/~~;                             # Unix vobs prefix
111
        Verbose("lsvob: $_");
112
        $VOBS{$_} = 1;
113
    }
114
    close(CMD);
115
 
116
 
117
#-------------------------------------------------------------------------------
118
#   Process all the constituent makefile data and buildup a list of source directories
119
#
120
foreach my $dir ( $mfdata->AllDirs() )
121
{
122
    my $mff = $mfdata->GetEntry($dir);
123
 
124
    Verbose ("Processing: $dir");
125
 
126
    #
127
    #   Add the location of the makefile
128
    #   This will include the root makefile - even if it doesn't exist
129
    #
130
    AddToList( $dir, '.' );
131
 
132
 
133
    foreach my $tgt ( $mff->GetPlatforms() )
134
    {
135
        my $cwd = $mff->GetDataItem($tgt, '$Cwd');
136
        Verbose( "Target: $tgt, CWD: $cwd\n");
137
 
138
        #
139
        #   Add the location of the makefile
140
        #
141
        AddToList( $cwd, '.' );
142
 
143
        #
144
        #   Locate all the sources
145
        #
146
        foreach my $var ( '%SRCS' )
147
        {
148
            if ( my $data = $mff->GetDataItem($tgt, $var) )
149
            {
150
                Verbose2( "$var : ", values %{$data});
151
                foreach my $file ( values %$data )
152
                {
153
                    my $dir = $file;
154
                    $dir =~ s~[^/]*$~~;
155
                    AddToList( $cwd, $dir );
156
                }
157
            }
158
        }
159
 
160
        #
161
        #   Locate all the included directories in case we need
162
        #   an exhaustive search of all header files
163
        #
164
        foreach my $var ( '@INCDIRS', '@SRCDIRS' )
165
        {
166
            if ( my $data = $mff->GetDataItem($tgt, $var) )
167
            {
168
                Verbose2( "$var : @{$data}");
169
                foreach my $dir ( @$data )
170
                {
171
                    AddToList( $cwd, $dir );
172
                }
173
            }
174
        }
175
    }
176
}
177
 
178
#-------------------------------------------------------------------------------
179
#   Display the results
180
#       Display directories that are within a VOB
181
#       Display directories not within a VOB
182
#       Warn if multiple VOBS have been found
183
#
184
my @no_vob;
185
my %vobs_used;
186
foreach ( sort keys %include )
187
{
188
    my $vob = $include{$_};
189
    push( @no_vob, $_ ) unless ( $vob );
190
    print "$_\n" if $vob;
191
    $vobs_used{$vob} = 1 if ( $vob );
192
}
193
 
194
if ( @no_vob )
195
{
196
    print "\nItems not located in a VOB\n";
197
    foreach (@no_vob )
198
    {
199
        print "    $_\n";
200
    }
201
}
202
 
203
 
204
my @vobs_used = sort keys %vobs_used;
205
my $vob_count = $#vobs_used + 1;
206
 
207
if ( $vob_count > 1 )
208
{
209
    print "\nWarning: Multiple VOBS used: @vobs_used\n";
210
}
211
 
212
 
213
 
214
#print Data::Dumper->Dump([\%include]);
215
 
216
 
217
#-------------------------------------------------------------------------------
218
# Function        : AddToList
219
#
220
# Description     : Add the specified directory to the list
221
#
222
# Inputs          : A directory
223
#
224
# Returns         : Nothing
225
#
226
sub AddToList
227
{
228
    my ($cwd, $dir) = @_;
229
 
230
    #
231
    #   Ignore paths that have a $(xxx) construct
232
    #
233
    return if ( $dir =~ m~\$\(~ );
234
 
235
    #
236
    #   Ignore entrires that have a drive letter
237
    #   These are external packages
238
    #
239
#    return if ( $dir =~ m~^\w\:~ );
240
 
241
    #
242
    #   Convert relative address into absolute address
243
    #
244
 
245
    $dir = $cwd . "/" . $dir unless ( $dir =~ m~^/~ || $dir =~ m~^\w\:~);
246
    $dir = CleanDirName( $dir );
247
    unless ( $include{$dir} )
248
    {
249
        my $vob = FindVob($dir);
250
        $include{$dir} = $vob;
251
        Verbose ("Adding dir: $dir");
252
    }
253
}
254
 
255
#-------------------------------------------------------------------------------
256
# Function        : FindVob
257
#
258
# Description     : Determine the VOB that contains a specified directory
259
#
260
# Inputs          : Directory
261
#
262
# Returns         : The name of the VOB that contains the directory
263
#
264
sub FindVob
265
{
266
    my($udir) = @_;
267
 
268
    #
269
    #   Split into parts
270
    #
271
    my @dirs = split( '/', $udir );
272
    foreach ( @dirs )
273
    {
274
        return $_
275
            if exists( $VOBS{$_} );
276
    }
277
 
278
    return undef;
279
}
280
 
281
#-------------------------------------------------------------------------------
282
#   Documentation
283
#
284
 
285
=pod
286
 
361 dpurdie 287
=for htmltoc    SYSUTIL::
288
 
227 dpurdie 289
=head1 NAME
290
 
291
gen_metrics - Create Metrics
292
 
293
=head1 SYNOPSIS
294
 
295
 jats etool gen_metrics [options]
296
 
297
 Options:
298
    -help              - Brief help message
299
    -help -help        - Detailed help message
300
    -man               - Full documentation
301
    -verbose           - Verbose display of operation
302
 
303
=head1 OPTIONS
304
 
305
=over 8
306
 
307
=item B<-help>
308
 
309
Print a brief help message and exits.
310
 
311
=item B<-help -help>
312
 
313
Print a detailed help message with an explanation for each option.
314
 
315
=item B<-man>
316
 
317
Prints the manual page and exits.
318
 
319
=item B<-verbose>
320
 
321
Prints internal information during the execution of the script.
361 dpurdie 322
 
227 dpurdie 323
=back
324
 
325
=head1 DESCRIPTION
326
 
327
The program will Post process the JATS build and makefiles and generate a list
328
of directories that need to be labeled. It does this by examining all the source
329
files located in the generated makefiles.
330
 
331
=cut
332