Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
########################################################################
2
# Copyright ( C ) 2007 ERG Limited, All rights reserved
3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats build system
8
#
9
# Description   : Provide access to information from the build.pl file as parsed
10
#                 by JATS. This is more complete than the parser in the
11
#                 "BuildFile.pm"
12
#
13
#                 The purpose of this module is to provide an interface
14
#                 between (essentially) internal data structures and user
15
#                 scripts that need to access the data. These are primarily
16
#                 deployment scripts.
17
#
18
#                 The 'All' tag is used for backward compatabilty. It simply
19
#                 exports all the known data structures. NOT to be used by new
20
#                 code.
21
#
22
#
23
#
24
# Interface     : ReadBuildConfig           - Initialise module
25
#                 getPlatformParts          - Get a list of Platform parts
26
#
27
#......................................................................#
28
 
255 dpurdie 29
require 5.006_001;
227 dpurdie 30
use strict;
31
use warnings;
32
 
33
#===============================================================================
34
package ReadBuildConfig;
35
use JatsError;
36
use JatsMakeInfo qw(:basic);
37
 
38
# automatically export what we need into namespace of caller.
39
use Exporter();
40
our (@ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK);
41
@ISA         = qw(Exporter);
42
@EXPORT      = qw(  ReadBuildConfig
43
                    getPlatformParts
44
                    getPackagePaths
271 dpurdie 45
                    getPackageList
227 dpurdie 46
                );
47
@EXPORT_OK =  qw(   $InterfaceVersion
48
                    $ScmBuildMachType
49
                    $ScmInterfaceVersion
50
                    $ScmBuildName
51
                    $ScmBuildPackage
52
                    $ScmBuildVersion
53
                    $ScmBuildProject
54
                    $ScmBuildVersionFull
55
                    $ScmBuildPreviousVersion
56
                    $ScmSrcDir
57
                    $ScmLocal
58
                    $ScmDeploymentPatch
59
                    $ScmBuildSrc
60
                    $ScmExpert
261 dpurdie 61
                    $ScmAll
227 dpurdie 62
                    %ScmBuildAliases
63
                    %ScmBuildProducts
64
                    %ScmBuildPlatforms
65
                    %ScmBuildPkgRules
66
                    @BUILDPLATFORMS
67
                    @DEFBUILDPLATFORMS
68
                    @BUILDTOOLSPATH
69
                    %BUILDPLATFORM_PARTS
70
                    %BUILDINFO
247 dpurdie 71
                    %BUILD_KNOWNFILES
227 dpurdie 72
                );
73
 
74
%EXPORT_TAGS = (All => [@EXPORT, @EXPORT_OK]);
75
 
76
#-------------------------------------------------------------------------------
77
#   Global variables
78
#
79
 
80
my $interface;
81
my $platform;
82
 
83
#
84
#   The $InterfaceVersion value is manually maintained
85
#   The integer part should be changed to indicate a incompatible change
86
#   to the JATS files created within the interface directory
87
#
88
#   $InterfaceVersion is treated as a float. The fractional part can be
89
#   used to indicate minor changes to the file format.
90
#
91
our $InterfaceVersion       = "2.0";            # Change will issue error message
92
 
93
#
94
#   The following varaibles are "read" in from the build.cfg file
95
#   In order to access simply access we need to declare them
96
#
97
our %BUILDINFO;
98
our %BUILDPLATFORM_PARTS;
99
our $ScmInterfaceVersion;
100
our %ScmBuildPkgRules;
101
our $ScmBuildMachType;
102
 
103
#-------------------------------------------------------------------------------
104
# Function        : ReadBuildConfig
105
#
106
# Description     : Read in the build config information
107
#                   Read in build.cfg
108
#
109
# Inputs          : $interface              - Path to the interface directory
110
#                   $platform               - Platform being processed
111
#
112
# Returns         : Nothing
113
#
114
sub ReadBuildConfig
115
{
116
    $interface = shift;
117
    $platform = shift;
118
 
119
    my $no_test;
120
    foreach  ( @_ )
121
    {
122
        if ( m/^--NoTest/i ) {
123
            $no_test = 1;
124
        } else {
125
            Warning ("ReadBuildConfig, Unknown option: $_");
126
        }
127
    }
128
 
129
    Debug("BuildConfig::Reading config, $interface");
130
    my $cfgfile = "$interface/build.cfg";
131
    Error ("JATS internal file missing. Rebuild required",
132
           "BuildConfig: Cannot find file: $cfgfile" ) unless ( -f $cfgfile );
133
 
134
    #
135
    #   Include the build.cfg data
136
    #
137
    require ( $cfgfile );
138
 
139
    #
140
    #   Ensure that the version of the interface files can be consumed
141
    #   The $ScmInterfaceVersion is a written copy of $InterfaceVersion
142
    #
143
    #   Allow build.cfg files that do not have a ScmInterfaceVersion
144
    #   Assume that these are at version 1.0.
145
    #
146
    $ScmInterfaceVersion = '1.0' unless ( $ScmInterfaceVersion );
147
    Debug ("ReadBuildConfig: Version: $ScmInterfaceVersion, Need: $InterfaceVersion");
148
    if ( int($ScmInterfaceVersion) != int($InterfaceVersion)  )
149
    {
150
        Error ("JATS interface files are not compatible with this version of JATS",
151
               "Rebuild required.",
152
               "Current Interface Version: $ScmInterfaceVersion",
153
               "JATS Interface Version   : $InterfaceVersion" );
154
    }
155
 
156
    #
157
    #   Ensure that this config file is designed for this machine type
158
    #   At make-time this test may not be valid. It should have been
159
    #   validated before make-time.
160
    #
161
    TestMachType ($ScmBuildMachType, "build.cfg") unless $no_test;
162
 
163
    #
164
    #   Remove some unused data
165
    #   Reduces the size of Makefile.cfg. Speeds up writting
166
    #
167
    if ( $platform )
168
    {
169
        for (keys %::ScmBuildPlatforms)
170
        {
171
            next if ($_ eq $platform );
172
            delete ($::BUILDPLATFORM_PARTS{$_} );
173
            delete ($::BUILDINFO{$_} );
174
            delete ($::ScmBuildPkgRules{$_} );
175
        }
176
    }
177
 
178
    #   dump
179
    #
180
    Debug( "Aliases:" );
369 dpurdie 181
    if ( ! (%::ScmBuildAliases) ) {
227 dpurdie 182
        Debug( "  undefined" );
183
 
184
    } else {
185
        foreach my $key (keys %::ScmBuildAliases) {
186
            my( @value ) = split( ' ', $::ScmBuildAliases{ $key } );
187
            Debug( " $key\t= @value" );
188
        }
189
    }
190
 
191
    Debug( "Products:" );
369 dpurdie 192
    if ( ! (%::ScmBuildProducts) ) {
227 dpurdie 193
        Debug( "  undefined" );
194
 
195
    } else {
196
        foreach my $key (keys %::ScmBuildProducts) {
197
            my( @value ) = split( ',', $::ScmBuildProducts{ $key } );
198
            Debug( " $key\t= @value" );
199
        }
200
    }
201
 
202
    Debug( "Platforms:" );
369 dpurdie 203
    if ( ! (%::ScmBuildPlatforms) ) {
227 dpurdie 204
        Debug( "  undefined" );
205
 
206
    } else {
207
        foreach my $key (keys %::ScmBuildPlatforms) {
208
            my( @args ) = split( /$;/, $::ScmBuildPlatforms{ $key } );
209
            Debug( " $key\t= @args" );
210
        }
211
    }
212
}
213
 
214
#-------------------------------------------------------------------------------
215
# Function        : getPlatformParts
216
#
217
# Description     : return a list of platform parts
218
#
219
# Inputs          : None
220
#
221
# Returns         : A list of platform parts to search in the interface
222
#                   directory, local directory or other
223
#
224
sub getPlatformParts
225
{
226
    Error ("BuildConfig. Not initialised") unless ( $platform );
227
    return @{$BUILDINFO{$platform}{PARTS}};
228
}
229
 
230
#-------------------------------------------------------------------------------
231
# Function        : getPackagePaths
232
#
233
# Description     : Return a list of all packages
234
#                   LinkPkgarchive packages will be provided as is
235
#                   BuildPkgArchive packages will be provided as a single
236
#                   reference to the interface directory
237
#
238
# Inputs          : Options
239
#                       --Interface=xxxx            Path to the interface dir
240
#                                                   If provided, then the path
241
#                                                   will be used for the first
242
#                                                   BuildPkgArchive
243
#                       --All                       All paths
244
#                       --Tools                     All Tools Paths
245
#                       --Gbe                       All Gbe paths
246
#
247
# Returns         : An array of paths
248
#
249
sub getPackagePaths
250
{
251
    Error ("BuildConfig. Not initialised") unless ( $platform );
252
 
253
    my $interface;
254
    my $all;
255
    my $need;
256
    my @result;
257
 
258
    #
259
    #   Parse Options
260
    #
261
    foreach ( @_ )
262
    {
263
        if ( m~^--Interface=(.+)~ ) {
264
            $interface = $1;
265
        } elsif ( m~^--All~ ) {
266
            $all = 1;
267
        } elsif ( m~^--Tools~ ) {
268
            $need = 'TOOLDIRS';
269
        } elsif ( m~^--Gbe~ ) {
270
            $need = 'CFGDIR';
271
        } else {
272
            Error ("BuildConfig. Unknown Option: $_");
273
        }
274
    }
275
 
276
    #
311 dpurdie 277
    #   Locate required entries
227 dpurdie 278
    #
279
    for my $entry (@{$ScmBuildPkgRules{$platform} })
280
    {
281
        #
282
        #   Do we need this entry
283
        #   Select tools and gbe entries
284
        #
285
        my @subdirs = '/';
286
        if ( $need )
287
        {
288
            next unless ( exists ($entry->{$need} ) );
289
            my $subdir = $entry->{$need};
290
            if ( ref($subdir) eq 'ARRAY' ) {
291
                @subdirs = @{$subdir};
292
            } else {
293
                @subdirs = $subdir;
294
            }
295
        }
296
 
297
        #
311 dpurdie 298
        #   Skip the Pseudo INTERFACE package if we are processing all packages
299
        #   Skip BuildPkgArchives if we aren't processing all
227 dpurdie 300
        #
311 dpurdie 301
        next if ( ($entry->{'TYPE'} eq 'interface') && $all );
302
        next if ( ($entry->{'TYPE'} eq 'build') && !$all );
303
 
304
        #
305
        #   Select appropriate root
306
        #       Use provided interface path - not too sure why
307
        #       Should be able to simplify this
308
        #
309
        my $dir = $entry->{'ROOT'};
310
        $dir = $interface if ( $entry->{'TYPE'} eq 'interface' );
311
 
312
        foreach my $subdir ( @subdirs )
227 dpurdie 313
        {
311 dpurdie 314
            my $dir = $entry->{'ROOT'} . $subdir;
315
            $dir =~ s~/+~/~g;
316
            $dir =~ s~/+$~~g;
317
            push @result, $dir;
227 dpurdie 318
        }
319
    }
320
 
321
    return @result;
322
}
323
 
271 dpurdie 324
#-------------------------------------------------------------------------------
325
# Function        : getPackageList
326
#
327
# Description     : Returns a list of package entries
328
#                   Only real use of the returnd values is to iterate over it
329
#                   and pass the values into other functiosn within this
330
#                   class.
331
#
332
# Inputs          : Nothing
333
#
334
# Returns         : A list of refs to package data
335
#
336
sub getPackageList
337
{
338
    Error ("BuildConfig. Not initialised") unless ( $platform );
339
    my @result;
340
 
341
    foreach ( @ {$ScmBuildPkgRules{$platform} } )
342
    {
343
#        my %self;
344
#        $self{DATA} = $_;
345
        push @result, bless $_, "PackageEntry";
346
    }
347
    return ( @result );
348
}
349
 
350
################################################################################
351
#   PackageEntry
352
################################################################################
353
#
354
#   A class to access the data embedded into $ScmBuildPkgRules
355
#   Use a class interface to abstract the data
356
#
357
package PackageEntry;
358
 
359
#-------------------------------------------------------------------------------
360
# Function        : dump
361
#
362
# Description     : Diagnostic Dump of the body of the package entry
363
#
364
# Inputs          : None
365
#
366
# Returns         : None
367
#
368
sub dump
369
{
370
    my $self = shift;
371
    ::DebugDumpData("PackageEntry", $self );
372
}
373
 
374
#-------------------------------------------------------------------------------
375
# Function        : getBase
376
#
377
# Description     : Determine the base directory of the package
378
#
379
# Inputs          : $self                   - Class Ref
380
#                   $type                   - 0: Empty
381
#                                             1: abs dpkg_archive
382
#                                             2: May be in the interface
311 dpurdie 383
#                                             3: Interface, LinkPkgs
271 dpurdie 384
#
385
# Returns         : As above
386
#
387
sub getBase
388
{
389
    my ($self, $type ) = @_;
371 dpurdie 390
 
271 dpurdie 391
    if ( $type == 1 ) {
392
        return $self->{ROOT};
393
    } elsif ( $type == 2 ) {
311 dpurdie 394
        if ( $self->{'TYPE'} eq 'build' ) {
395
            return $interface;
396
        } else {
271 dpurdie 397
            return $self->{ROOT};
398
        }
311 dpurdie 399
    } elsif ( $type == 3 ) {
400
        return if ( $self->{'TYPE'} eq 'build' );
371 dpurdie 401
        return $self->{ROOT};
271 dpurdie 402
    } else  {
403
        return '';
404
    }
405
}
406
 
407
#-------------------------------------------------------------------------------
408
# Function        : getLibDirs
409
#
410
# Description     : Return an array of library directories
411
#
412
# Inputs          : $self                   - Class ref
413
#                   $type                   - 0 : Relative to base of the package
414
#                                             1 : abs to the dpkg_archive package
415
#                                             2 : abs to the interface
311 dpurdie 416
#                                             3: Interface, LinkPkgs
271 dpurdie 417
#
418
# Returns         : An array
419
#
420
sub getLibDirs
421
{
422
    my ($self, $type ) = @_;
423
    my @result;
424
    my $prefix = getBase( $self, $type );
425
 
426
    foreach ( @{$self->{PLIBDIRS}} )
427
    {
428
        push @result, $prefix . $_;
429
    }
430
    return @result;
431
}
432
 
433
#-------------------------------------------------------------------------------
434
# Function        : getIncDirs
435
#
436
# Description     : Return an array of include directories
437
#
438
# Inputs          : $self                   - Class ref
439
#                   $type                   - 0 : Relative to base of the package
440
#                                             1 : abs to the dpkg_archive package
441
#                                             2 : abs to the interface
311 dpurdie 442
#                                             3: Interface, LinkPkgs
271 dpurdie 443
#
444
# Returns         : An array
445
#
446
sub getIncDirs
447
{
448
    my ($self, $type ) = @_;
449
    my @result;
450
    my $prefix = getBase( $self, $type );
451
 
452
    foreach ( @{$self->{PINCDIRS}} )
453
    {
454
        push @result, $prefix . $_;
455
    }
456
    return @result;
457
}
458
 
227 dpurdie 459
#------------------------------------------------------------------------------
460
1;