Subversion Repositories DevTools

Rev

Rev 6504 | Rev 6887 | 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:
6511 dpurdie 261
#       - tools/bin/GBE_MACHTYPE/bin    - Hardware specfic tools
262
#       - tools/bin/GBE_MACHTYPE        - Hardware specfic tools
263
#       - tools/bin                     - Hardware independent tools - scripts
264
#       - tools/scripts/GBE_MACHINE     - Hardware specific scripts
265
#       - tools/scripts                 - Hardware independent scripts (too)
227 dpurdie 266
#
267
# Inputs          : self
268
#
269
# Returns         : Nothing
270
#
271
sub ExamineToolPath
272
{
273
    my( $self ) = shift;
274
 
275
    #
276
    #   Determine base dir
277
    #       LinkPkgArchive  : From the package
278
    #       BuildPkgArchive : From the interface directory
279
    #
280
    my $base_dir = $self->{'base'};
281
    $base_dir = "$::Cwd/$BUILDINTERFACE"
282
        if ( $self->{'type'} eq 'build' );
283
 
6504 dpurdie 284
    my @searchList;
285
    my $path = "/tools/bin";
6511 dpurdie 286
    foreach my $suffix ( "/$::GBE_MACHTYPE", "/$::GBE_MACHTYPE/bin", "" ) {
6504 dpurdie 287
        push @searchList, $path . $suffix;
288
    }
289
 
290
    $path = "/tools/scripts";
291
    foreach my $suffix ( "/$::GBE_MACHTYPE", "" ) {
292
        push @searchList, $path . $suffix;
293
    }
294
 
295
    for my $path (@searchList )
227 dpurdie 296
    {
6504 dpurdie 297
        my $dir = $base_dir . $path;
298
        if ( isUsefulDir( $dir ) )
227 dpurdie 299
        {
6504 dpurdie 300
            ::UniquePush( \@{$self->{'TOOLDIRS'}}, $dir );
301
            ::UniquePush( \@BUILDTOOLS, $dir );
227 dpurdie 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
6177 dpurdie 479
#                   The list cannot be used directly. It is really a set of
227 dpurdie 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
#-------------------------------------------------------------------------------
6192 dpurdie 515
# Function        : GetNameVersion
516
#
517
# Description     : Return a package name and version for display purposes
518
#
519
# Inputs          : $tag        - An iteration tag provided by GetPackageList()
520
#
521
# Returns         : A list of
522
#                       Package name
523
#                       Package version
524
#                       Package type : build or link
525
#
526
sub GetNameVersion
527
{
528
    my ($tag) = @_;
529
    my $rec = $DescPkgCache{$tag};
530
    return join( ' ', $rec->{NAME}, $rec->{VERSION_FULL} );
531
}
532
 
533
#-------------------------------------------------------------------------------
227 dpurdie 534
# Function        : GetPackageVersionList
535
#
536
# Description     : A class function to return a list of package names as used
537
#                   to generate version strings
538
#
539
#
540
# Inputs          : None
541
#
542
# Returns         : An array of version list entries
543
#                   Each element of the form: "name (version)"
544
#
545
sub GetPackageVersionList
546
{
547
    my @list;
548
    foreach my $tag ( @PackageList )
549
    {
550
        my $rec = $DescPkgCache{$tag};
551
        push @list, "$rec->{UNAME} ($rec->{UVERSION})";
552
    }
553
 
554
    return @list;
555
}
556
 
6276 dpurdie 557
#-------------------------------------------------------------------------------
558
# Function        : GetPackageSignature
559
#
560
# Description     : A class function to return a packages signature
561
#
562
#
563
# Inputs          : None
564
#
565
# Returns         : An array of version list entries
566
#                   Each element of the form: "name (version)"
567
#
568
sub GetPackageSignature
569
{
570
    my ($tag) = @_;
571
    my $rec = $DescPkgCache{$tag};
572
    return $rec->{PKGSIG};
573
}
6192 dpurdie 574
 
575
#-------------------------------------------------------------------------------
576
# Function        : Dump 
577
#
578
# Description     : Internal diagnostic tool
579
#                   Dumps internal data structures    
580
#
581
# Inputs          : None 
582
#
583
# Returns         : Nothing 
584
#
585
 
586
sub Dump
587
{
588
    ::DebugDumpData("PackageEntry",\%DescPkgCache);
589
}
590
 
227 dpurdie 591
### End of package: PackageEntry
592
 
593
1;
594