Subversion Repositories DevTools

Rev

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