Subversion Repositories DevTools

Rev

Rev 6192 | Rev 6504 | 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
########################################################################
6177 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 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
}
6276 dpurdie 73
#-------------------------------------------------------------------------------
74
# Function        : New 
75
#
76
# Description     : Create a new instance of the PackageEntry class
77
#
78
# Inputs          : $base           - Path to the package
79
#                   $name           - Package Name
80
#                   $version        - Version
81
#                   $type           - 'link' or 'build'
82
#                   $local          - Is from a local archive
83
#                                     No version check.
84
#                                     Display path to package
85
#                   $pkgSig         - Package Signature
86
#
87
# Returns         : 
88
#
227 dpurdie 89
 
311 dpurdie 90
sub New
91
{
6276 dpurdie 92
    my ($base, $name, $version, $type, $local, $pkgSig) = @_;
311 dpurdie 93
    my $self = EmptyEntry();
94
 
95
    #   Load package description ...
96
    #   Note:   The results are cached within DescPkgCache
97
    #..
227 dpurdie 98
    if ( ! exists( $DescPkgCache{$base} ) )
99
    {
100
        my ($rec);
101
        my ($desc) = "";
102
 
6276 dpurdie 103
        if ( -f "$base/descpkg" )
227 dpurdie 104
        {
105
            $rec = ::ReadDescpkg( "$base/descpkg", 1 );
106
        }
107
        else
108
        {                                       # doesn't exist
109
            ::Error( "Package description does not exist",
110
                     "Package Location: $base" )
111
        }
112
 
113
        ::Error("Cannot determine package description",
114
                "Package Location: $base" )
115
            unless ( $rec );
116
 
117
        ::Warning( "Package names do not match: $rec->{NAME}, $name" )
118
            if ( $rec->{NAME} ne $name );
119
 
6276 dpurdie 120
        if ( $local )
227 dpurdie 121
        {                                       # display results
331 dpurdie 122
            my $logPrefix = "               ->";
6276 dpurdie 123
            ::Log( "$logPrefix $base" );
227 dpurdie 124
        }
125
        elsif ( $rec->{VERSION_FULL} ne $version )
126
        {
127
            ::Warning( "Package versions do not match: $name : $rec->{VERSION_FULL}, $version" );
128
        }
129
 
130
        #
6177 dpurdie 131
        #   Extend the package information to contain sufficient data
227 dpurdie 132
        #   for general use. Information will be retained to allow the
133
        #   user to extact specific package information
134
        #
135
        $version =~ m~(\d+\.\d+\.\d+)\.(\w+)~ ;
136
        my $vnum = $1 || $version;
137
        my $proj = $2 || '';
138
 
139
        $rec->{UNAME}    = $name;
140
        $rec->{UVERSION} = $version;
141
        $rec->{UVNUM}    = $vnum;
142
        $rec->{UPROJ}    = $proj;
143
        $rec->{type}     = $type;
6276 dpurdie 144
        $rec->{PKGSIG}   = $pkgSig;
227 dpurdie 145
 
146
        $PackageDefined{$name}{$proj}{$vnum} = $base;
147
        push @PackageList, $base;
148
 
149
        $DescPkgCache{$base} = $rec;                  # cache result
150
    }
151
 
152
#   Build the package entry record
153
#..
154
    my ($descpkg) = $DescPkgCache{$base};       # descpkg details
155
 
156
    $self->{'base'}         = $base;
157
 
158
    $self->{'name'}         = $name;
159
    $self->{'version'}      = $version;
160
    $self->{'dname'}        = $descpkg->{NAME};
161
    $self->{'dversion'}     = $descpkg->{VERSION};
162
    $self->{'dproj'}        = $descpkg->{PROJ} || $descpkg->{UPROJ} || '';
163
    $self->{'packages'}     = $descpkg->{PACKAGES};
164
    $self->{'type'}         = $type;
6276 dpurdie 165
    $self->{'cfgdir'}       = "/gbe" if ( -d $base."/gbe" );
166
#    $self->{pkgsig}         = $descpkg->{PKGSIG};
227 dpurdie 167
 
311 dpurdie 168
    return $self;
227 dpurdie 169
}
170
 
311 dpurdie 171
#-------------------------------------------------------------------------------
172
# Function        : Interface
173
#
174
# Description     : Create a specialised 'interface' entry
175
#
176
# Inputs          : $base           - Path to the Interface directory
177
#
178
# Returns         : Ref to this class
179
#
180
sub Interface
181
{
182
    my ($base) = @_;
183
    my $self = EmptyEntry();
184
 
185
    $self->{'base'}         = $base;
186
    $self->{'name'}         = 'INTERFACE';
187
    $self->{'version'}      = '0.0.0';
188
    $self->{'dname'}        = $self->{'name'};
189
    $self->{'dversion'}     = $self->{'version'};
190
    $self->{'dproj'}        = '';
191
    $self->{'packages'}     = '';
192
    $self->{'type'}         = 'interface';
193
    $self->{'cfgdir'}       = '/gbe';
194
 
195
    return $self;
196
 
197
}
198
 
227 dpurdie 199
sub RuleInc
200
{
201
    my( $self ) = shift;
202
    my( $path ) = @_;
203
    my( $examined ) = $self->{INCEXAMINED};
204
    my( $list ) = $self->{PINCDIRS};
205
 
206
    return if ( $$examined{$path} );
207
    $$examined{$path} = 1;
208
 
6276 dpurdie 209
    push @$list, $path      if ( -d $self->{'base'}.$path );
227 dpurdie 210
}
211
 
212
#
213
#   Examine Path to ensure that it is a directory and that it contains files
214
#   Simplify Lib Path searching by removing useless paths.
215
#
216
#   If there are ANY files then the directory is useful
217
#   If there are no files ( only subdirectories ) then the directory is not useful
218
#
219
sub isUsefulDir
220
{
221
    my ($path) = @_;
222
 
223
    if ( -d $path )
224
    {
225
        opendir (USEFUL, $path) or ::Error ("Cannot open $path");
226
        my @dirlist = readdir USEFUL;
285 dpurdie 227
        closedir USEFUL;
227 dpurdie 228
 
229
        foreach ( @dirlist )
230
        {
231
            return 1 if ( -f "$path/$_" );
232
        }
233
    }
234
    return 0;
235
}
236
 
237
sub RuleLib
238
{
239
    my( $self ) = shift;
240
    my( $path ) = @_;
241
    my( $examined ) = $self->{LIBEXAMINED};
242
    my( $list ) = $self->{PLIBDIRS};
243
 
244
    return if ( $$examined{$path} );
245
    $$examined{$path} = 1;
246
 
6276 dpurdie 247
    push @$list, $path."D"  if ( isUsefulDir($self->{'base'}.$path."D") );
248
    push @$list, $path."P"  if ( isUsefulDir($self->{'base'}.$path."P") );
249
    push @$list, $path      if ( isUsefulDir($self->{'base'}.$path) );
227 dpurdie 250
}
251
 
252
#-------------------------------------------------------------------------------
253
# Function        : ExamineToolPath
254
#
255
# Description     : Given the root of a package, locate any
256
#                   toolset extension paths within the tree. These will be
257
#                   saved and later used when user tools and scripts are
258
#                   invoked.
259
#
260
#   Examine:
261
#       - tools/bin/GBE_MACHTYPE    - Hardware specfic tools
262
#       - tools/bin                 - Hardware independent tools - scripts
263
#       - tools/scripts/GBE_MACHINE - Hardware specific scripts
264
#       - tools/scripts             - Hardware independent scripts (too)
265
#
266
# Inputs          : self
267
#
268
# Returns         : Nothing
269
#
270
sub ExamineToolPath
271
{
272
    my( $self ) = shift;
273
 
274
    #
275
    #   Determine base dir
276
    #       LinkPkgArchive  : From the package
277
    #       BuildPkgArchive : From the interface directory
278
    #
279
    my $base_dir = $self->{'base'};
280
    $base_dir = "$::Cwd/$BUILDINTERFACE"
281
        if ( $self->{'type'} eq 'build' );
282
 
283
    for my $path ("/tools/bin", "/tools/scripts" )
284
    {
285
        foreach my $suffix ( "/$::GBE_MACHTYPE", "" )
286
        {
287
            my $dir = $base_dir . $path . $suffix;
288
            if ( isUsefulDir( $dir ) )
289
            {
290
                ::UniquePush( \@{$self->{'TOOLDIRS'}}, $dir );
291
                ::UniquePush( \@BUILDTOOLS, $dir );
292
            }
293
        }
294
    }
295
}
296
 
297
#-------------------------------------------------------------------------------
298
# Function        : ExamineThxPath
299
#
300
# Description     : Given the root of a package, locate some well known
301
#                   packaging directories for later use.
302
#
303
#                   Examine:
304
#                       /thx/$platform
305
#                       /thx
306
#
307
# Inputs          : self
308
#                   platform        - Current build platform
309
#
310
# Returns         : nothing
311
#
312
sub ExamineThxPath
313
{
314
    my( $self, $platform ) = @_;
315
 
316
    my $dir = $self->{'base'} . '/thx';
317
    if ( -d $dir )
318
    {
319
        push @{$self->{'THXDIRS'}}, "/thx/$platform" if isUsefulDir( "$dir/$platform" );
320
        push @{$self->{'THXDIRS'}}, "/thx" if isUsefulDir( $dir );
321
    }
322
}
323
 
324
sub Cleanup
325
{
326
    my ($self) = shift;
327
 
328
    delete $self->{LIBEXAMINED};
329
    delete $self->{INCEXAMINED};
330
}
331
 
332
 
333
#-------------------------------------------------------------------------------
334
# Function        : GetBaseDir
335
#
336
# Description     : Return the base directory of a given package
337
#                   Simple getter function
338
#
339
# Inputs          : self
340
#                   path    - Optional path within package
341
#
342
# Returns         : The base directory of the package
343
#
344
sub GetBaseDir
345
{
346
    my ($self, $path) = @_;
347
    my $dir = $self->{'base'};
348
    $dir .= '/' . $path if ( $path );
349
    return $dir;
350
}
351
 
352
 
353
#-------------------------------------------------------------------------------
354
# Function        : SanityTest
355
#
356
# Description     : Examine all the packages used in the current build.pl
357
#                   and all the packages used to build them. Then generate
358
#                   warning if there are mismatches.
359
#
360
#                   All the data has been collected and stored within
361
#                   $DescPkgCache. This routine processes the data and
362
#                   constructs a data structure to locate packages with
363
#                   multiple versions.
364
#
365
#                   The project name is considered to be a part of the package
366
#                   name. Thus aaaa_11.22.33.mass is different to aaaa_11.22.33.syd
367
#
368
# Inputs          :
369
#
370
# Returns         :
371
#
372
my %package_list;
373
 
374
sub AddEntry
375
{
376
    my( $root, $rver, $rproj, $name, $version ) = @_;
377
    my $ver;
378
    my $proj;
379
 
380
    if ($version eq "!current") {
381
        $ver = "current";
382
        $proj = "";
383
    } else {
384
        $version =~ m~(.*)\.(.*?)$~;
385
        $ver = $1  || 'BadVer';
386
        $proj = $2 || 'BadProj';
387
    }
388
 
389
    ::UniquePush( \@{$package_list{"$name$;$proj"}{$ver}},  "${root}_${rver}.${rproj}");
390
}
391
 
392
sub SanityTest
393
{
394
    foreach my $package ( keys %DescPkgCache )
395
    {
396
        my $pptr = $DescPkgCache{$package};
397
        my $lver = $pptr->{'VERSION'};
398
           $lver .= '.' . $pptr->{'PROJ'} if ( $pptr->{'PROJ'} );
399
        AddEntry( $BUILDNAME_PACKAGE, $BUILDNAME_VERSION, $BUILDNAME_PROJECT, $pptr->{'NAME'}, $lver );
400
 
401
 
402
        foreach my $subpkg ( @{$pptr->{'PACKAGES'}} )
403
        {
404
            my $name = $subpkg->{name};
405
            my $ver = $subpkg->{version};
406
 
407
            AddEntry( $pptr->{'NAME'}, $pptr->{'VERSION'}, $pptr->{'PROJ'}, $name, $ver );
408
        }
409
    }
410
 
411
    #::DebugDumpData("XXX", \%package_list );
412
 
413
    #
414
    #   Detect and print warnings about multiple entries
415
    #
416
    my $first_found = 0;
417
    foreach my $pentry ( sort keys %package_list)
418
    {
419
        my @versions = keys %{$package_list{$pentry}};
420
 
421
        if ( $#versions > 0 )
422
        {
423
            ::Warning("Package mismatchs detected.") unless ( $first_found++ );
424
 
425
            my ($pname, $pproj) = split $;, $pentry ;
426
            foreach my $version ( @versions )
427
            {
428
                ::Warning("Package ${pname}_${version}.${pproj} used by:", @{$package_list{$pentry}{$version}});
429
            }
430
        }
431
 
432
    }
433
}
434
 
435
#-------------------------------------------------------------------------------
436
# Function        : Exists
437
#
438
# Description     : A class function to determine if a given package is known
439
#                   to the PackageEntry manager. Used to detect multiple package
440
#                   definitions.
441
#
442
#                   The test ignores package versions
443
#                   It is not possible to include different versions of the
444
#                   same package. The test ignores the project part of the
445
#                   version. This allows for
446
#                           sysbasetypes aa.bb.cc.mas and
447
#                           sysbasetypes xx.yy.zz.syd
448
#
449
# Inputs          : $name           - User package name
450
#                   $version        - User version ( with project )
451
#
452
# Returns         : True: Package exists
453
#
454
 
455
sub Exists
456
{
457
    my ($name, $version) = @_;
458
 
459
    $version =~ m~(\d+\.\d+\.\d+)\.(\w+)~ ;
460
    my $vnum = $1 || $version;
461
    my $proj = $2 || '';
462
 
463
    return exists( $PackageDefined{$name}{$proj} );
464
}
465
 
466
#-------------------------------------------------------------------------------
467
# Function        : GetPackageList
468
#
469
# Description     : A class function to return a list of packages
6177 dpurdie 470
#                   The list cannot be used directly. It is really a set of
227 dpurdie 471
#                   keys to an internal data structure.
472
#
473
#                   The result can be used to iterate over the list of packages
474
#                   using other functions.
475
#
476
# Inputs          : None
477
#
478
# Returns         : An array of package tags
479
#                   The array is ordered by package definition order
480
#
481
sub GetPackageList
482
{
483
    return @PackageList;
484
}
485
 
486
#-------------------------------------------------------------------------------
487
# Function        : GetPackageData
488
#
489
# Description     : A class function to return specific data for a given package
490
#
491
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
492
#
493
# Returns         : A list of
494
#                       Package name
495
#                       Package version
496
#                       Package type : build or link
497
#
498
sub GetPackageData
499
{
500
    my ($tag) = @_;
501
    my $rec = $DescPkgCache{$tag};
502
    return $rec->{UNAME}, $rec->{UVERSION}, $rec->{type};
503
}
504
 
505
#-------------------------------------------------------------------------------
6192 dpurdie 506
# Function        : GetNameVersion
507
#
508
# Description     : Return a package name and version for display purposes
509
#
510
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
511
#
512
# Returns         : A list of
513
#                       Package name
514
#                       Package version
515
#                       Package type : build or link
516
#
517
sub GetNameVersion
518
{
519
    my ($tag) = @_;
520
    my $rec = $DescPkgCache{$tag};
521
    return join( ' ', $rec->{NAME}, $rec->{VERSION_FULL} );
522
}
523
 
524
#-------------------------------------------------------------------------------
227 dpurdie 525
# Function        : GetPackageVersionList
526
#
527
# Description     : A class function to return a list of package names as used
528
#                   to generate version strings
529
#
530
#
531
# Inputs          : None
532
#
533
# Returns         : An array of version list entries
534
#                   Each element of the form: "name (version)"
535
#
536
sub GetPackageVersionList
537
{
538
    my @list;
539
    foreach my $tag ( @PackageList )
540
    {
541
        my $rec = $DescPkgCache{$tag};
542
        push @list, "$rec->{UNAME} ($rec->{UVERSION})";
543
    }
544
 
545
    return @list;
546
}
547
 
6276 dpurdie 548
#-------------------------------------------------------------------------------
549
# Function        : GetPackageSignature
550
#
551
# Description     : A class function to return a packages signature
552
#
553
#
554
# Inputs          : None
555
#
556
# Returns         : An array of version list entries
557
#                   Each element of the form: "name (version)"
558
#
559
sub GetPackageSignature
560
{
561
    my ($tag) = @_;
562
    my $rec = $DescPkgCache{$tag};
563
    return $rec->{PKGSIG};
564
}
6192 dpurdie 565
 
566
#-------------------------------------------------------------------------------
567
# Function        : Dump 
568
#
569
# Description     : Internal diagnostic tool
570
#                   Dumps internal data structures    
571
#
572
# Inputs          : None 
573
#
574
# Returns         : Nothing 
575
#
576
 
577
sub Dump
578
{
579
    ::DebugDumpData("PackageEntry",\%DescPkgCache);
580
}
581
 
227 dpurdie 582
### End of package: PackageEntry
583
 
584
1;
585