Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
3
# Copyright ( C ) 2004 ERG Limited, All rights reserved
4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Package Entry
11
#
12
#       New         Create a new package entry instance.
13
#
14
#       RuleInc     Check whether the specific 'include' path should
15
#                   be included within the PINCDIRS list.
16
#
17
#       RuleLib     Check whether the specific 'lib' path should
18
#                   be included within the PLIBDIRS list.
19
#
20
#       Cleanup     Performs any record cleanup required prior to the
21
#                   entry being published.
22
#
23
# Usage:
24
#
25
# Version   Who      Date        Description
26
#
27
#......................................................................#
28
 
255 dpurdie 29
require 5.006_001;
227 dpurdie 30
use strict;
31
use warnings;
32
 
33
use DescPkg;
34
use JatsError;
35
 
36
 
37
our $BUILDNAME_PACKAGE;
38
our $BUILDNAME_VERSION;
39
our $BUILDNAME_PROJECT;
40
our $BUILDINTERFACE;
41
our @BUILDTOOLS;
42
 
43
 
44
package PackageEntry;
45
 
46
our %DescPkgCache           = ();           # Hash of known packages
47
our %PackageDefined         = ();           # Quick defined package test
48
our @PackageList            = ();           # Ordered array of packages
49
 
311 dpurdie 50
 
51
#-------------------------------------------------------------------------------
52
# Function        : EmptyEntry
53
#
54
# Description     : Create an empty class element
55
#                   Populated with the basic items
56
#
57
# Inputs          : None
58
#
59
# Returns         : New, empty entry
60
#
61
sub EmptyEntry
227 dpurdie 62
{
63
    my ($self) = {
64
            PINCDIRS        => [],
65
            PLIBDIRS        => [],
66
            LIBEXAMINED     => {},
67
            INCEXAMINED     => {},
68
            TOOLDIRS        => [],
69
            THXDIRS         => [],
70
        };
311 dpurdie 71
    return bless $self, __PACKAGE__;
72
}
227 dpurdie 73
 
311 dpurdie 74
sub New
75
{
76
    my ($base, $name, $version, $sandbox, $type) = @_;
77
    my $self = EmptyEntry();
78
 
79
    #   Load package description ...
80
    #
81
    #       If a sandbox link, parse the build.pl and retrieve the BuildName()
82
    #       otherwise, load the description from the 'descpkg'.
83
    #
84
    #   Note:   The results are cached within DescPkgCache
85
    #..
227 dpurdie 86
    if ( ! exists( $DescPkgCache{$base} ) )
87
    {
88
        my ($rec);
89
        my ($desc) = "";
90
 
91
        if ( $sandbox )
92
        {
93
            open (BUILDPL, "$base/build.pl") ||
94
                ::Error( "cannot open '$base/build.pl'" );
95
            while (<BUILDPL>) {
96
                if ( $_ =~ /^\s*BuildName\s*\(\s*[\"\'](.*)[\'\"]\s*\)/ ) {
97
                    $desc = $1;                 # BuildName() argument
98
                    ($rec->{NAME}, $rec->{VERSION}, $rec->{PROJ}) = split( ' ', $desc );
99
                    last;
100
                }
101
            }
102
            close (BUILDPL);
103
        }
104
        elsif ( -f "$base/descpkg" )
105
        {
106
            $rec = ::ReadDescpkg( "$base/descpkg", 1 );
107
        }
108
        else
109
        {                                       # doesn't exist
110
            ::Error( "Package description does not exist",
111
                     "Package Location: $base" )
112
        }
113
 
114
        ::Error("Cannot determine package description",
115
                "Package Location: $base" )
116
            unless ( $rec );
117
 
118
        ::Warning( "Package names do not match: $rec->{NAME}, $name" )
119
            if ( $rec->{NAME} ne $name );
120
 
121
        if ( substr($version,0,8) eq '!current' ||
122
                substr($version,0,8) eq '!sandbox' )
123
        {                                       # display results
124
            ::Log( "          -> " );
125
            if ($rec->{NAME} eq "") {
126
                ::Log( "n/a\n" );
127
            } else {
128
                ::Log( "$rec->{NAME} $rec->{VERSION} $rec->{PROJ}\n" );
129
            }
130
        }
131
        elsif ( $rec->{VERSION_FULL} ne $version )
132
        {
133
            ::Warning( "Package versions do not match: $name : $rec->{VERSION_FULL}, $version" );
134
        }
135
 
136
        #
137
        #   Extend the package information to contain suffiecient data
138
        #   for general use. Information will be retained to allow the
139
        #   user to extact specific package information
140
        #
141
        $version =~ m~(\d+\.\d+\.\d+)\.(\w+)~ ;
142
        my $vnum = $1 || $version;
143
        my $proj = $2 || '';
144
 
145
        $rec->{UNAME}    = $name;
146
        $rec->{UVERSION} = $version;
147
        $rec->{UVNUM}    = $vnum;
148
        $rec->{UPROJ}    = $proj;
149
        $rec->{type}     = $type;
150
 
151
        $PackageDefined{$name}{$proj}{$vnum} = $base;
152
        push @PackageList, $base;
153
 
154
        $DescPkgCache{$base} = $rec;                  # cache result
155
    }
156
 
157
#   Build the package entry record
158
#..
159
    my ($descpkg) = $DescPkgCache{$base};       # descpkg details
160
 
161
    $self->{'base'}         = $base;
162
    $self->{'base'}         .= "/local"
163
        if ( $sandbox );
164
 
165
    $self->{'name'}         = $name;
166
    $self->{'version'}      = $version;
167
    $self->{'sandbox'}      = $sandbox;
168
    $self->{'dname'}        = $descpkg->{NAME};
169
    $self->{'dversion'}     = $descpkg->{VERSION};
170
    $self->{'dproj'}        = $descpkg->{PROJ} || $descpkg->{UPROJ} || '';
171
    $self->{'packages'}     = $descpkg->{PACKAGES};
172
    $self->{'type'}         = $type;
173
    $self->{'cfgdir'}       = "/gbe"
174
        if ( $sandbox || -d $base."/gbe" );
175
 
311 dpurdie 176
    return $self;
227 dpurdie 177
}
178
 
311 dpurdie 179
#-------------------------------------------------------------------------------
180
# Function        : Interface
181
#
182
# Description     : Create a specialised 'interface' entry
183
#
184
# Inputs          : $base           - Path to the Interface directory
185
#
186
# Returns         : Ref to this class
187
#
188
sub Interface
189
{
190
    my ($base) = @_;
191
    my $self = EmptyEntry();
192
 
193
    $self->{'base'}         = $base;
194
    $self->{'name'}         = 'INTERFACE';
195
    $self->{'version'}      = '0.0.0';
196
    $self->{'sandbox'}      = 0;
197
    $self->{'dname'}        = $self->{'name'};
198
    $self->{'dversion'}     = $self->{'version'};
199
    $self->{'dproj'}        = '';
200
    $self->{'packages'}     = '';
201
    $self->{'type'}         = 'interface';
202
    $self->{'cfgdir'}       = '/gbe';
203
 
204
    return $self;
205
 
206
}
207
 
227 dpurdie 208
sub RuleInc
209
{
210
    my( $self ) = shift;
211
    my( $path ) = @_;
212
    my( $examined ) = $self->{INCEXAMINED};
213
    my( $list ) = $self->{PINCDIRS};
214
 
215
    return if ( $$examined{$path} );
216
    $$examined{$path} = 1;
217
 
218
    push @$list, $path      if ( $self->{'sandbox'} || -d $self->{'base'}.$path );
219
}
220
 
221
#
222
#   Examine Path to ensure that it is a directory and that it contains files
223
#   Simplify Lib Path searching by removing useless paths.
224
#
225
#   If there are ANY files then the directory is useful
226
#   If there are no files ( only subdirectories ) then the directory is not useful
227
#
228
sub isUsefulDir
229
{
230
    my ($path) = @_;
231
 
232
    if ( -d $path )
233
    {
234
        opendir (USEFUL, $path) or ::Error ("Cannot open $path");
235
        my @dirlist = readdir USEFUL;
285 dpurdie 236
        closedir USEFUL;
227 dpurdie 237
 
238
        foreach ( @dirlist )
239
        {
240
            return 1 if ( -f "$path/$_" );
241
        }
242
    }
243
    return 0;
244
}
245
 
246
sub RuleLib
247
{
248
    my( $self ) = shift;
249
    my( $path ) = @_;
250
    my( $examined ) = $self->{LIBEXAMINED};
251
    my( $list ) = $self->{PLIBDIRS};
252
 
253
    return if ( $$examined{$path} );
254
    $$examined{$path} = 1;
255
 
256
    push @$list, $path."D"  if ( $self->{'sandbox'} || isUsefulDir($self->{'base'}.$path."D") );
257
    push @$list, $path."P"  if ( $self->{'sandbox'} || isUsefulDir($self->{'base'}.$path."P") );
258
    push @$list, $path      if ( $self->{'sandbox'} || isUsefulDir($self->{'base'}.$path) );
259
}
260
 
261
#-------------------------------------------------------------------------------
262
# Function        : ExamineToolPath
263
#
264
# Description     : Given the root of a package, locate any
265
#                   toolset extension paths within the tree. These will be
266
#                   saved and later used when user tools and scripts are
267
#                   invoked.
268
#
269
#   Examine:
270
#       - tools/bin/GBE_MACHTYPE    - Hardware specfic tools
271
#       - tools/bin                 - Hardware independent tools - scripts
272
#       - tools/scripts/GBE_MACHINE - Hardware specific scripts
273
#       - tools/scripts             - Hardware independent scripts (too)
274
#
275
# Inputs          : self
276
#
277
# Returns         : Nothing
278
#
279
sub ExamineToolPath
280
{
281
    my( $self ) = shift;
282
 
283
    #
284
    #   Determine base dir
285
    #       LinkPkgArchive  : From the package
286
    #       BuildPkgArchive : From the interface directory
287
    #
288
    my $base_dir = $self->{'base'};
289
    $base_dir = "$::Cwd/$BUILDINTERFACE"
290
        if ( $self->{'type'} eq 'build' );
291
 
292
    for my $path ("/tools/bin", "/tools/scripts" )
293
    {
294
        foreach my $suffix ( "/$::GBE_MACHTYPE", "" )
295
        {
296
            my $dir = $base_dir . $path . $suffix;
297
            if ( isUsefulDir( $dir ) )
298
            {
299
                ::UniquePush( \@{$self->{'TOOLDIRS'}}, $dir );
300
                ::UniquePush( \@BUILDTOOLS, $dir );
301
            }
302
        }
303
    }
304
}
305
 
306
#-------------------------------------------------------------------------------
307
# Function        : ExamineThxPath
308
#
309
# Description     : Given the root of a package, locate some well known
310
#                   packaging directories for later use.
311
#
312
#                   Examine:
313
#                       /thx/$platform
314
#                       /thx
315
#
316
# Inputs          : self
317
#                   platform        - Current build platform
318
#
319
# Returns         : nothing
320
#
321
sub ExamineThxPath
322
{
323
    my( $self, $platform ) = @_;
324
 
325
    my $dir = $self->{'base'} . '/thx';
326
    if ( -d $dir )
327
    {
328
        push @{$self->{'THXDIRS'}}, "/thx/$platform" if isUsefulDir( "$dir/$platform" );
329
        push @{$self->{'THXDIRS'}}, "/thx" if isUsefulDir( $dir );
330
    }
331
}
332
 
333
sub Cleanup
334
{
335
    my ($self) = shift;
336
 
337
    delete $self->{LIBEXAMINED};
338
    delete $self->{INCEXAMINED};
339
}
340
 
341
 
342
#-------------------------------------------------------------------------------
343
# Function        : GetBaseDir
344
#
345
# Description     : Return the base directory of a given package
346
#                   Simple getter function
347
#
348
# Inputs          : self
349
#                   path    - Optional path within package
350
#
351
# Returns         : The base directory of the package
352
#
353
sub GetBaseDir
354
{
355
    my ($self, $path) = @_;
356
    my $dir = $self->{'base'};
357
    $dir .= '/' . $path if ( $path );
358
    return $dir;
359
}
360
 
361
 
362
#-------------------------------------------------------------------------------
363
# Function        : SanityTest
364
#
365
# Description     : Examine all the packages used in the current build.pl
366
#                   and all the packages used to build them. Then generate
367
#                   warning if there are mismatches.
368
#
369
#                   All the data has been collected and stored within
370
#                   $DescPkgCache. This routine processes the data and
371
#                   constructs a data structure to locate packages with
372
#                   multiple versions.
373
#
374
#                   The project name is considered to be a part of the package
375
#                   name. Thus aaaa_11.22.33.mass is different to aaaa_11.22.33.syd
376
#
377
# Inputs          :
378
#
379
# Returns         :
380
#
381
my %package_list;
382
 
383
sub AddEntry
384
{
385
    my( $root, $rver, $rproj, $name, $version ) = @_;
386
    my $ver;
387
    my $proj;
388
 
389
    if ($version eq "!current") {
390
        $ver = "current";
391
        $proj = "";
392
    } else {
393
        $version =~ m~(.*)\.(.*?)$~;
394
        $ver = $1  || 'BadVer';
395
        $proj = $2 || 'BadProj';
396
    }
397
 
398
    ::UniquePush( \@{$package_list{"$name$;$proj"}{$ver}},  "${root}_${rver}.${rproj}");
399
}
400
 
401
sub SanityTest
402
{
403
    foreach my $package ( keys %DescPkgCache )
404
    {
405
        my $pptr = $DescPkgCache{$package};
406
        my $lver = $pptr->{'VERSION'};
407
           $lver .= '.' . $pptr->{'PROJ'} if ( $pptr->{'PROJ'} );
408
        AddEntry( $BUILDNAME_PACKAGE, $BUILDNAME_VERSION, $BUILDNAME_PROJECT, $pptr->{'NAME'}, $lver );
409
 
410
 
411
        foreach my $subpkg ( @{$pptr->{'PACKAGES'}} )
412
        {
413
            my $name = $subpkg->{name};
414
            my $ver = $subpkg->{version};
415
 
416
            AddEntry( $pptr->{'NAME'}, $pptr->{'VERSION'}, $pptr->{'PROJ'}, $name, $ver );
417
        }
418
    }
419
 
420
    #::DebugDumpData("XXX", \%package_list );
421
 
422
    #
423
    #   Detect and print warnings about multiple entries
424
    #
425
    my $first_found = 0;
426
    foreach my $pentry ( sort keys %package_list)
427
    {
428
        my @versions = keys %{$package_list{$pentry}};
429
 
430
        if ( $#versions > 0 )
431
        {
432
            ::Warning("Package mismatchs detected.") unless ( $first_found++ );
433
 
434
            my ($pname, $pproj) = split $;, $pentry ;
435
            foreach my $version ( @versions )
436
            {
437
                ::Warning("Package ${pname}_${version}.${pproj} used by:", @{$package_list{$pentry}{$version}});
438
            }
439
        }
440
 
441
    }
442
}
443
 
444
#-------------------------------------------------------------------------------
445
# Function        : Exists
446
#
447
# Description     : A class function to determine if a given package is known
448
#                   to the PackageEntry manager. Used to detect multiple package
449
#                   definitions.
450
#
451
#                   The test ignores package versions
452
#                   It is not possible to include different versions of the
453
#                   same package. The test ignores the project part of the
454
#                   version. This allows for
455
#                           sysbasetypes aa.bb.cc.mas and
456
#                           sysbasetypes xx.yy.zz.syd
457
#
458
# Inputs          : $name           - User package name
459
#                   $version        - User version ( with project )
460
#
461
# Returns         : True: Package exists
462
#
463
 
464
sub Exists
465
{
466
    my ($name, $version) = @_;
467
 
468
    $version =~ m~(\d+\.\d+\.\d+)\.(\w+)~ ;
469
    my $vnum = $1 || $version;
470
    my $proj = $2 || '';
471
 
472
    return exists( $PackageDefined{$name}{$proj} );
473
}
474
 
475
#-------------------------------------------------------------------------------
476
# Function        : GetPackageList
477
#
478
# Description     : A class function to return a list of packages
479
#                   The list cannot be used directory. It is really a set of
480
#                   keys to an internal data structure.
481
#
482
#                   The result can be used to iterate over the list of packages
483
#                   using other functions.
484
#
485
# Inputs          : None
486
#
487
# Returns         : An array of package tags
488
#                   The array is ordered by package definition order
489
#
490
sub GetPackageList
491
{
492
    return @PackageList;
493
}
494
 
495
#-------------------------------------------------------------------------------
496
# Function        : GetPackageData
497
#
498
# Description     : A class function to return specific data for a given package
499
#
500
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
501
#
502
# Returns         : A list of
503
#                       Package name
504
#                       Package version
505
#                       Package type : build or link
506
#
507
sub GetPackageData
508
{
509
    my ($tag) = @_;
510
    my $rec = $DescPkgCache{$tag};
511
    return $rec->{UNAME}, $rec->{UVERSION}, $rec->{type};
512
}
513
 
514
#-------------------------------------------------------------------------------
515
# Function        : GetPackageVersionList
516
#
517
# Description     : A class function to return a list of package names as used
518
#                   to generate version strings
519
#
520
#
521
# Inputs          : None
522
#
523
# Returns         : An array of version list entries
524
#                   Each element of the form: "name (version)"
525
#
526
sub GetPackageVersionList
527
{
528
    my @list;
529
    foreach my $tag ( @PackageList )
530
    {
531
        my $rec = $DescPkgCache{$tag};
532
        push @list, "$rec->{UNAME} ($rec->{UVERSION})";
533
    }
534
 
535
    return @list;
536
}
537
 
538
### End of package: PackageEntry
539
 
540
1;
541