Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
########################################################################
5710 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 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);
4324 dpurdie 37
use FileUtils;
227 dpurdie 38
 
39
# automatically export what we need into namespace of caller.
40
use Exporter();
41
our (@ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK);
42
@ISA         = qw(Exporter);
43
@EXPORT      = qw(  ReadBuildConfig
44
                    getPlatformParts
45
                    getPackagePaths
271 dpurdie 46
                    getPackageList
4324 dpurdie 47
                    getToolInfo
227 dpurdie 48
                );
49
@EXPORT_OK =  qw(   $InterfaceVersion
50
                    $ScmBuildMachType
51
                    $ScmInterfaceVersion
52
                    $ScmBuildName
53
                    $ScmBuildPackage
54
                    $ScmBuildVersion
55
                    $ScmBuildProject
56
                    $ScmBuildVersionFull
57
                    $ScmBuildPreviousVersion
58
                    $ScmSrcDir
59
                    $ScmLocal
60
                    $ScmDeploymentPatch
61
                    $ScmBuildSrc
62
                    $ScmExpert
261 dpurdie 63
                    $ScmAll
4003 dpurdie 64
                    $ScmNoBuild
227 dpurdie 65
                    %ScmBuildAliases
66
                    %ScmBuildProducts
67
                    %ScmBuildPlatforms
68
                    %ScmBuildPkgRules
69
                    @BUILDPLATFORMS
70
                    @DEFBUILDPLATFORMS
71
                    @BUILDTOOLSPATH
72
                    %BUILDPLATFORM_PARTS
73
                    %BUILDINFO
247 dpurdie 74
                    %BUILD_KNOWNFILES
227 dpurdie 75
                );
76
 
77
%EXPORT_TAGS = (All => [@EXPORT, @EXPORT_OK]);
78
 
79
#-------------------------------------------------------------------------------
80
#   Global variables
81
#
82
 
83
my $interface;
84
my $platform;
85
 
86
#
87
#   The $InterfaceVersion value is manually maintained
88
#   The integer part should be changed to indicate a incompatible change
89
#   to the JATS files created within the interface directory
90
#
91
#   $InterfaceVersion is treated as a float. The fractional part can be
92
#   used to indicate minor changes to the file format.
93
#
94
our $InterfaceVersion       = "2.0";            # Change will issue error message
95
 
96
#
97
#   The following varaibles are "read" in from the build.cfg file
98
#   In order to access simply access we need to declare them
99
#
100
our %BUILDINFO;
101
our %BUILDPLATFORM_PARTS;
102
our $ScmInterfaceVersion;
103
our %ScmBuildPkgRules;
104
our $ScmBuildMachType;
105
 
106
#-------------------------------------------------------------------------------
107
# Function        : ReadBuildConfig
108
#
109
# Description     : Read in the build config information
110
#                   Read in build.cfg
111
#
112
# Inputs          : $interface              - Path to the interface directory
113
#                   $platform               - Platform being processed
114
#
115
# Returns         : Nothing
116
#
117
sub ReadBuildConfig
118
{
119
    $interface = shift;
120
    $platform = shift;
121
 
122
    my $no_test;
123
    foreach  ( @_ )
124
    {
125
        if ( m/^--NoTest/i ) {
126
            $no_test = 1;
127
        } else {
128
            Warning ("ReadBuildConfig, Unknown option: $_");
129
        }
130
    }
131
 
132
    Debug("BuildConfig::Reading config, $interface");
133
    my $cfgfile = "$interface/build.cfg";
134
    Error ("JATS internal file missing. Rebuild required",
135
           "BuildConfig: Cannot find file: $cfgfile" ) unless ( -f $cfgfile );
136
 
137
    #
138
    #   Include the build.cfg data
139
    #
140
    require ( $cfgfile );
141
 
142
    #
143
    #   Ensure that the version of the interface files can be consumed
144
    #   The $ScmInterfaceVersion is a written copy of $InterfaceVersion
145
    #
146
    #   Allow build.cfg files that do not have a ScmInterfaceVersion
147
    #   Assume that these are at version 1.0.
148
    #
149
    $ScmInterfaceVersion = '1.0' unless ( $ScmInterfaceVersion );
150
    Debug ("ReadBuildConfig: Version: $ScmInterfaceVersion, Need: $InterfaceVersion");
151
    if ( int($ScmInterfaceVersion) != int($InterfaceVersion)  )
152
    {
153
        Error ("JATS interface files are not compatible with this version of JATS",
154
               "Rebuild required.",
155
               "Current Interface Version: $ScmInterfaceVersion",
156
               "JATS Interface Version   : $InterfaceVersion" );
157
    }
158
 
159
    #
160
    #   Ensure that this config file is designed for this machine type
161
    #   At make-time this test may not be valid. It should have been
162
    #   validated before make-time.
163
    #
164
    TestMachType ($ScmBuildMachType, "build.cfg") unless $no_test;
165
 
166
    #
167
    #   Remove some unused data
168
    #   Reduces the size of Makefile.cfg. Speeds up writting
169
    #
170
    if ( $platform )
171
    {
172
        for (keys %::ScmBuildPlatforms)
173
        {
174
            next if ($_ eq $platform );
175
            delete ($::BUILDPLATFORM_PARTS{$_} );
176
            delete ($::BUILDINFO{$_} );
177
            delete ($::ScmBuildPkgRules{$_} );
178
        }
179
    }
180
 
181
    #   dump
182
    #
183
    Debug( "Aliases:" );
369 dpurdie 184
    if ( ! (%::ScmBuildAliases) ) {
227 dpurdie 185
        Debug( "  undefined" );
186
 
187
    } else {
188
        foreach my $key (keys %::ScmBuildAliases) {
189
            my( @value ) = split( ' ', $::ScmBuildAliases{ $key } );
190
            Debug( " $key\t= @value" );
191
        }
192
    }
193
 
194
    Debug( "Products:" );
369 dpurdie 195
    if ( ! (%::ScmBuildProducts) ) {
227 dpurdie 196
        Debug( "  undefined" );
197
 
198
    } else {
199
        foreach my $key (keys %::ScmBuildProducts) {
200
            my( @value ) = split( ',', $::ScmBuildProducts{ $key } );
201
            Debug( " $key\t= @value" );
202
        }
203
    }
204
 
205
    Debug( "Platforms:" );
369 dpurdie 206
    if ( ! (%::ScmBuildPlatforms) ) {
227 dpurdie 207
        Debug( "  undefined" );
208
 
209
    } else {
210
        foreach my $key (keys %::ScmBuildPlatforms) {
211
            my( @args ) = split( /$;/, $::ScmBuildPlatforms{ $key } );
212
            Debug( " $key\t= @args" );
213
        }
214
    }
215
}
216
 
217
#-------------------------------------------------------------------------------
218
# Function        : getPlatformParts
219
#
220
# Description     : return a list of platform parts
221
#
222
# Inputs          : None
223
#
224
# Returns         : A list of platform parts to search in the interface
225
#                   directory, local directory or other
226
#
227
sub getPlatformParts
228
{
229
    Error ("BuildConfig. Not initialised") unless ( $platform );
230
    return @{$BUILDINFO{$platform}{PARTS}};
231
}
232
 
233
#-------------------------------------------------------------------------------
234
# Function        : getPackagePaths
235
#
236
# Description     : Return a list of all packages
237
#                   LinkPkgarchive packages will be provided as is
238
#                   BuildPkgArchive packages will be provided as a single
239
#                   reference to the interface directory
240
#
241
# Inputs          : Options
242
#                       --Interface=xxxx            Path to the interface dir
243
#                                                   If provided, then the path
244
#                                                   will be used for the first
245
#                                                   BuildPkgArchive
246
#                       --All                       All paths
247
#                       --Tools                     All Tools Paths
248
#                       --Gbe                       All Gbe paths
249
#
250
# Returns         : An array of paths
251
#
252
sub getPackagePaths
253
{
254
    Error ("BuildConfig. Not initialised") unless ( $platform );
255
 
256
    my $interface;
257
    my $all;
258
    my $need;
259
    my @result;
260
 
261
    #
262
    #   Parse Options
263
    #
264
    foreach ( @_ )
265
    {
266
        if ( m~^--Interface=(.+)~ ) {
267
            $interface = $1;
268
        } elsif ( m~^--All~ ) {
269
            $all = 1;
270
        } elsif ( m~^--Tools~ ) {
271
            $need = 'TOOLDIRS';
272
        } elsif ( m~^--Gbe~ ) {
273
            $need = 'CFGDIR';
274
        } else {
275
            Error ("BuildConfig. Unknown Option: $_");
276
        }
277
    }
278
 
279
    #
311 dpurdie 280
    #   Locate required entries
227 dpurdie 281
    #
282
    for my $entry (@{$ScmBuildPkgRules{$platform} })
283
    {
284
        #
285
        #   Do we need this entry
286
        #   Select tools and gbe entries
287
        #
288
        my @subdirs = '/';
289
        if ( $need )
290
        {
291
            next unless ( exists ($entry->{$need} ) );
292
            my $subdir = $entry->{$need};
293
            if ( ref($subdir) eq 'ARRAY' ) {
294
                @subdirs = @{$subdir};
295
            } else {
296
                @subdirs = $subdir;
297
            }
298
        }
299
 
300
        #
311 dpurdie 301
        #   Skip the Pseudo INTERFACE package if we are processing all packages
302
        #   Skip BuildPkgArchives if we aren't processing all
227 dpurdie 303
        #
311 dpurdie 304
        next if ( ($entry->{'TYPE'} eq 'interface') && $all );
305
        next if ( ($entry->{'TYPE'} eq 'build') && !$all );
306
 
307
        #
308
        #   Select appropriate root
309
        #       Use provided interface path - not too sure why
310
        #       Should be able to simplify this
311
        #
312
        my $dir = $entry->{'ROOT'};
313
        $dir = $interface if ( $entry->{'TYPE'} eq 'interface' );
314
 
315
        foreach my $subdir ( @subdirs )
227 dpurdie 316
        {
311 dpurdie 317
            my $dir = $entry->{'ROOT'} . $subdir;
318
            $dir =~ s~/+~/~g;
319
            $dir =~ s~/+$~~g;
320
            push @result, $dir;
227 dpurdie 321
        }
322
    }
323
 
324
    return @result;
325
}
326
 
271 dpurdie 327
#-------------------------------------------------------------------------------
328
# Function        : getPackageList
329
#
330
# Description     : Returns a list of package entries
4324 dpurdie 331
#                   Only real use of the returned values is to iterate over it
332
#                   and pass the values into other functions within this
271 dpurdie 333
#                   class.
334
#
335
# Inputs          : Nothing
336
#
337
# Returns         : A list of refs to package data
338
#
339
sub getPackageList
340
{
341
    Error ("BuildConfig. Not initialised") unless ( $platform );
342
    my @result;
343
 
344
    foreach ( @ {$ScmBuildPkgRules{$platform} } )
345
    {
346
#        my %self;
347
#        $self{DATA} = $_;
348
        push @result, bless $_, "PackageEntry";
349
    }
350
    return ( @result );
351
}
352
 
4324 dpurdie 353
#-------------------------------------------------------------------------------
354
# Function        : getToolInfo 
355
#
356
# Description     : Locate and load the tool information for the named tool
357
#
358
# Inputs          : $toolname           - tool to locate
359
#                   ...                 - Optional,Names of fields to expect in the package
360
#                                         If any of the required fields ar missing an error
361
#                                         will be reported
362
#
363
# Returns         : A hash of Tool info
364
#
365
sub getToolInfo
366
{
367
    my ($toolname, @fnames) = @_;
368
    my $toolroot;
369
    my $toolinfo;
370
    my $pentry;
371
    my %data;
372
    my @searchPath;
373
 
374
    foreach my $entry ( getPackageList() )
375
    {
376
        my $path = $entry->getBase(2);
377
        Verbose("getToolInfo: $path");
378
        #   Generic
379
        $toolinfo = catdir($path, 'gbe', 'INFO', 'info.' . $toolname . '.generic');
380
        push @searchPath, $toolinfo;
381
        if ( -f $toolinfo )
382
        {
383
            $toolroot = $path;
384
            $pentry = $entry;
385
            last;
386
        }
387
        #   Machine specific
388
        $toolinfo = catdir($path, 'gbe', 'INFO', 'info.' . $toolname . '.'. $ENV{GBE_HOSTMACH});
389
        push @searchPath, $toolinfo;
390
        if ( -f $toolinfo )
391
        {
392
            $toolroot = $path;
393
            $pentry = $entry;
394
            last;
395
        }
396
    }
397
    if (defined $toolroot)
398
    {
399
        open (my $DATA, '<', $toolinfo ) || Error("Cannot open tool info file. $!", "File: $toolinfo");
400
        while ( <$DATA> )
401
        {
402
            $_ =~ s~\s+$~~;
403
            next if ( m~^#~ );
404
            next if length($_) < 1;
405
            m~(.*?)\s*=\s*(.*)~;
406
            $data{$1} = $2;
407
        }
408
        close $DATA;
409
        $data{PKGBASE} = $toolroot;
410
        $data{PKGENTRY} = $pentry;
411
#DebugDumpData("Data", \%data);
412
 
413
        #
414
        #   Ensure that the required fields are in the info file
415
        #   These will be a mix of mandatory and user fields
416
        #
417
        my @missing;
418
        for my $fname ('TOOLNAME','TOOLROOT', @fnames)
419
        {
420
            next if defined $data{$fname};
421
            push @missing, $fname;
422
        }
423
        if (@missing)
424
        {
425
            Error("Tool Package '$toolname' is missing required fields:", @missing);
426
        }
427
        return \%data;
428
    }
429
 
430
    #   Didn't find the required tool
431
    Error ("Cannot find required tool in any package: $toolname", "Search Path:", @searchPath);
432
}
433
 
434
 
271 dpurdie 435
################################################################################
436
#   PackageEntry
437
################################################################################
438
#
439
#   A class to access the data embedded into $ScmBuildPkgRules
440
#   Use a class interface to abstract the data
441
#
442
package PackageEntry;
443
 
444
#-------------------------------------------------------------------------------
445
# Function        : dump
446
#
447
# Description     : Diagnostic Dump of the body of the package entry
448
#
449
# Inputs          : None
450
#
451
# Returns         : None
452
#
453
sub dump
454
{
455
    my $self = shift;
456
    ::DebugDumpData("PackageEntry", $self );
457
}
458
 
459
#-------------------------------------------------------------------------------
5411 dpurdie 460
# Function        : getUnifiedName 
461
#
462
# Description     : Return a Package Name based on PackageName and project suffix
463
#                   Package Name is cleaned up a bit
464
#                       Replace non-alphanumenrics with a '_'
465
#                       Converted to upper case 
466
#
467
# Inputs          : $self
468
#                   $prefix         - Optional Prefix 
469
#                   $suffix         - Optional Suffix 
470
#
471
# Returns         : String
472
#
473
sub getUnifiedName
474
{
475
    my ($self,$prefix,$suffix) = @_;
476
 
477
    my $name = $prefix || '';
478
    $name .= $self->{'DNAME'};
479
    $name .= '_' . $self->{'DPROJ'} if $self->{'DPROJ'};
480
    $name .= $suffix || '';
481
 
482
    $name =~ s~\W~_~g; 
483
    $name =~ s~-~_~g; 
484
    $name =~ tr~_~_~s;
485
    $name = uc $name;
486
    return $name;
487
}
488
 
489
 
490
#-------------------------------------------------------------------------------
271 dpurdie 491
# Function        : getBase
492
#
493
# Description     : Determine the base directory of the package
494
#
495
# Inputs          : $self                   - Class Ref
496
#                   $type                   - 0: Empty
497
#                                             1: abs dpkg_archive
498
#                                             2: May be in the interface
311 dpurdie 499
#                                             3: Interface, LinkPkgs
271 dpurdie 500
#
501
# Returns         : As above
502
#
503
sub getBase
504
{
505
    my ($self, $type ) = @_;
371 dpurdie 506
 
271 dpurdie 507
    if ( $type == 1 ) {
508
        return $self->{ROOT};
509
    } elsif ( $type == 2 ) {
311 dpurdie 510
        if ( $self->{'TYPE'} eq 'build' ) {
511
            return $interface;
512
        } else {
271 dpurdie 513
            return $self->{ROOT};
514
        }
311 dpurdie 515
    } elsif ( $type == 3 ) {
516
        return if ( $self->{'TYPE'} eq 'build' );
371 dpurdie 517
        return $self->{ROOT};
271 dpurdie 518
    } else  {
519
        return '';
520
    }
521
}
522
 
523
#-------------------------------------------------------------------------------
524
# Function        : getLibDirs
525
#
526
# Description     : Return an array of library directories
527
#
528
# Inputs          : $self                   - Class ref
529
#                   $type                   - 0 : Relative to base of the package
530
#                                             1 : abs to the dpkg_archive package
531
#                                             2 : abs to the interface
311 dpurdie 532
#                                             3: Interface, LinkPkgs
271 dpurdie 533
#
534
# Returns         : An array
535
#
536
sub getLibDirs
537
{
538
    my ($self, $type ) = @_;
539
    my @result;
540
    my $prefix = getBase( $self, $type );
541
 
542
    foreach ( @{$self->{PLIBDIRS}} )
543
    {
544
        push @result, $prefix . $_;
545
    }
546
    return @result;
547
}
548
 
549
#-------------------------------------------------------------------------------
550
# Function        : getIncDirs
551
#
552
# Description     : Return an array of include directories
553
#
554
# Inputs          : $self                   - Class ref
555
#                   $type                   - 0 : Relative to base of the package
556
#                                             1 : abs to the dpkg_archive package
557
#                                             2 : abs to the interface
311 dpurdie 558
#                                             3: Interface, LinkPkgs
271 dpurdie 559
#
560
# Returns         : An array
561
#
562
sub getIncDirs
563
{
564
    my ($self, $type ) = @_;
565
    my @result;
566
    my $prefix = getBase( $self, $type );
567
 
568
    foreach ( @{$self->{PINCDIRS}} )
569
    {
570
        push @result, $prefix . $_;
571
    }
572
    return @result;
573
}
574
 
227 dpurdie 575
#------------------------------------------------------------------------------
576
1;