Subversion Repositories DevTools

Rev

Rev 6276 | Rev 6511 | 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
 
6504 dpurdie 283
    my @searchList;
284
    my $path = "/tools/bin";
285
    foreach my $suffix ( "/$::GBE_MACHTYPE", "/$::GBE_MACHTYPE/bin" ) {
286
        push @searchList, $path . $suffix;
287
    }
288
 
289
    $path = "/tools/scripts";
290
    foreach my $suffix ( "/$::GBE_MACHTYPE", "" ) {
291
        push @searchList, $path . $suffix;
292
    }
293
 
294
    for my $path (@searchList )
227 dpurdie 295
    {
6504 dpurdie 296
        my $dir = $base_dir . $path;
297
        if ( isUsefulDir( $dir ) )
227 dpurdie 298
        {
6504 dpurdie 299
            ::UniquePush( \@{$self->{'TOOLDIRS'}}, $dir );
300
            ::UniquePush( \@BUILDTOOLS, $dir );
227 dpurdie 301
        }
302
    }
303
}
304
 
305
#-------------------------------------------------------------------------------
306
# Function        : ExamineThxPath
307
#
308
# Description     : Given the root of a package, locate some well known
309
#                   packaging directories for later use.
310
#
311
#                   Examine:
312
#                       /thx/$platform
313
#                       /thx
314
#
315
# Inputs          : self
316
#                   platform        - Current build platform
317
#
318
# Returns         : nothing
319
#
320
sub ExamineThxPath
321
{
322
    my( $self, $platform ) = @_;
323
 
324
    my $dir = $self->{'base'} . '/thx';
325
    if ( -d $dir )
326
    {
327
        push @{$self->{'THXDIRS'}}, "/thx/$platform" if isUsefulDir( "$dir/$platform" );
328
        push @{$self->{'THXDIRS'}}, "/thx" if isUsefulDir( $dir );
329
    }
330
}
331
 
332
sub Cleanup
333
{
334
    my ($self) = shift;
335
 
336
    delete $self->{LIBEXAMINED};
337
    delete $self->{INCEXAMINED};
338
}
339
 
340
 
341
#-------------------------------------------------------------------------------
342
# Function        : GetBaseDir
343
#
344
# Description     : Return the base directory of a given package
345
#                   Simple getter function
346
#
347
# Inputs          : self
348
#                   path    - Optional path within package
349
#
350
# Returns         : The base directory of the package
351
#
352
sub GetBaseDir
353
{
354
    my ($self, $path) = @_;
355
    my $dir = $self->{'base'};
356
    $dir .= '/' . $path if ( $path );
357
    return $dir;
358
}
359
 
360
 
361
#-------------------------------------------------------------------------------
362
# Function        : SanityTest
363
#
364
# Description     : Examine all the packages used in the current build.pl
365
#                   and all the packages used to build them. Then generate
366
#                   warning if there are mismatches.
367
#
368
#                   All the data has been collected and stored within
369
#                   $DescPkgCache. This routine processes the data and
370
#                   constructs a data structure to locate packages with
371
#                   multiple versions.
372
#
373
#                   The project name is considered to be a part of the package
374
#                   name. Thus aaaa_11.22.33.mass is different to aaaa_11.22.33.syd
375
#
376
# Inputs          :
377
#
378
# Returns         :
379
#
380
my %package_list;
381
 
382
sub AddEntry
383
{
384
    my( $root, $rver, $rproj, $name, $version ) = @_;
385
    my $ver;
386
    my $proj;
387
 
388
    if ($version eq "!current") {
389
        $ver = "current";
390
        $proj = "";
391
    } else {
392
        $version =~ m~(.*)\.(.*?)$~;
393
        $ver = $1  || 'BadVer';
394
        $proj = $2 || 'BadProj';
395
    }
396
 
397
    ::UniquePush( \@{$package_list{"$name$;$proj"}{$ver}},  "${root}_${rver}.${rproj}");
398
}
399
 
400
sub SanityTest
401
{
402
    foreach my $package ( keys %DescPkgCache )
403
    {
404
        my $pptr = $DescPkgCache{$package};
405
        my $lver = $pptr->{'VERSION'};
406
           $lver .= '.' . $pptr->{'PROJ'} if ( $pptr->{'PROJ'} );
407
        AddEntry( $BUILDNAME_PACKAGE, $BUILDNAME_VERSION, $BUILDNAME_PROJECT, $pptr->{'NAME'}, $lver );
408
 
409
 
410
        foreach my $subpkg ( @{$pptr->{'PACKAGES'}} )
411
        {
412
            my $name = $subpkg->{name};
413
            my $ver = $subpkg->{version};
414
 
415
            AddEntry( $pptr->{'NAME'}, $pptr->{'VERSION'}, $pptr->{'PROJ'}, $name, $ver );
416
        }
417
    }
418
 
419
    #::DebugDumpData("XXX", \%package_list );
420
 
421
    #
422
    #   Detect and print warnings about multiple entries
423
    #
424
    my $first_found = 0;
425
    foreach my $pentry ( sort keys %package_list)
426
    {
427
        my @versions = keys %{$package_list{$pentry}};
428
 
429
        if ( $#versions > 0 )
430
        {
431
            ::Warning("Package mismatchs detected.") unless ( $first_found++ );
432
 
433
            my ($pname, $pproj) = split $;, $pentry ;
434
            foreach my $version ( @versions )
435
            {
436
                ::Warning("Package ${pname}_${version}.${pproj} used by:", @{$package_list{$pentry}{$version}});
437
            }
438
        }
439
 
440
    }
441
}
442
 
443
#-------------------------------------------------------------------------------
444
# Function        : Exists
445
#
446
# Description     : A class function to determine if a given package is known
447
#                   to the PackageEntry manager. Used to detect multiple package
448
#                   definitions.
449
#
450
#                   The test ignores package versions
451
#                   It is not possible to include different versions of the
452
#                   same package. The test ignores the project part of the
453
#                   version. This allows for
454
#                           sysbasetypes aa.bb.cc.mas and
455
#                           sysbasetypes xx.yy.zz.syd
456
#
457
# Inputs          : $name           - User package name
458
#                   $version        - User version ( with project )
459
#
460
# Returns         : True: Package exists
461
#
462
 
463
sub Exists
464
{
465
    my ($name, $version) = @_;
466
 
467
    $version =~ m~(\d+\.\d+\.\d+)\.(\w+)~ ;
468
    my $vnum = $1 || $version;
469
    my $proj = $2 || '';
470
 
471
    return exists( $PackageDefined{$name}{$proj} );
472
}
473
 
474
#-------------------------------------------------------------------------------
475
# Function        : GetPackageList
476
#
477
# Description     : A class function to return a list of packages
6177 dpurdie 478
#                   The list cannot be used directly. It is really a set of
227 dpurdie 479
#                   keys to an internal data structure.
480
#
481
#                   The result can be used to iterate over the list of packages
482
#                   using other functions.
483
#
484
# Inputs          : None
485
#
486
# Returns         : An array of package tags
487
#                   The array is ordered by package definition order
488
#
489
sub GetPackageList
490
{
491
    return @PackageList;
492
}
493
 
494
#-------------------------------------------------------------------------------
495
# Function        : GetPackageData
496
#
497
# Description     : A class function to return specific data for a given package
498
#
499
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
500
#
501
# Returns         : A list of
502
#                       Package name
503
#                       Package version
504
#                       Package type : build or link
505
#
506
sub GetPackageData
507
{
508
    my ($tag) = @_;
509
    my $rec = $DescPkgCache{$tag};
510
    return $rec->{UNAME}, $rec->{UVERSION}, $rec->{type};
511
}
512
 
513
#-------------------------------------------------------------------------------
6192 dpurdie 514
# Function        : GetNameVersion
515
#
516
# Description     : Return a package name and version for display purposes
517
#
518
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
519
#
520
# Returns         : A list of
521
#                       Package name
522
#                       Package version
523
#                       Package type : build or link
524
#
525
sub GetNameVersion
526
{
527
    my ($tag) = @_;
528
    my $rec = $DescPkgCache{$tag};
529
    return join( ' ', $rec->{NAME}, $rec->{VERSION_FULL} );
530
}
531
 
532
#-------------------------------------------------------------------------------
227 dpurdie 533
# Function        : GetPackageVersionList
534
#
535
# Description     : A class function to return a list of package names as used
536
#                   to generate version strings
537
#
538
#
539
# Inputs          : None
540
#
541
# Returns         : An array of version list entries
542
#                   Each element of the form: "name (version)"
543
#
544
sub GetPackageVersionList
545
{
546
    my @list;
547
    foreach my $tag ( @PackageList )
548
    {
549
        my $rec = $DescPkgCache{$tag};
550
        push @list, "$rec->{UNAME} ($rec->{UVERSION})";
551
    }
552
 
553
    return @list;
554
}
555
 
6276 dpurdie 556
#-------------------------------------------------------------------------------
557
# Function        : GetPackageSignature
558
#
559
# Description     : A class function to return a packages signature
560
#
561
#
562
# Inputs          : None
563
#
564
# Returns         : An array of version list entries
565
#                   Each element of the form: "name (version)"
566
#
567
sub GetPackageSignature
568
{
569
    my ($tag) = @_;
570
    my $rec = $DescPkgCache{$tag};
571
    return $rec->{PKGSIG};
572
}
6192 dpurdie 573
 
574
#-------------------------------------------------------------------------------
575
# Function        : Dump 
576
#
577
# Description     : Internal diagnostic tool
578
#                   Dumps internal data structures    
579
#
580
# Inputs          : None 
581
#
582
# Returns         : Nothing 
583
#
584
 
585
sub Dump
586
{
587
    ::DebugDumpData("PackageEntry",\%DescPkgCache);
588
}
589
 
227 dpurdie 590
### End of package: PackageEntry
591
 
592
1;
593