Subversion Repositories DevTools

Rev

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