Subversion Repositories DevTools

Rev

Rev 6133 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6133 Rev 6177
Line 1... Line 1...
1
########################################################################
1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
3
#
3
#
4
# Module name   : jats_generate_deployable.pl
4
# Module name   : jats_generate_deployable.pl
5
# Module type   : Makefile system
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
# Environment(s): jats build system
7
# Environment(s): jats build system
Line 50... Line 50...
50
 
50
 
51
#
51
#
52
#   Constants
52
#   Constants
53
#
53
#
54
my $CONFFILE = '.bomGen';
54
my $CONFFILE = '.bomGen';
-
 
55
my $BOMFILE = '.bomCots';
55
my $MANIFEST = 'MANIFEST.json';
56
my $MANIFEST = 'MANIFEST.json';
56
my $TFVARS   = 'MANIFEST.tf';
57
my $TFVARS   = 'MANIFEST.tf';
57
 
58
 
58
#
59
#
59
#   Globals
60
#   Globals
60
#
61
#
61
my $DM_DB;              # Data Base Interface
62
my $DM_DB;              # Data Base Interface
62
my %bomList;            # All files in the BOM
63
my %bomList;            # All files in the BOM
63
my $bomInfo;            # Sbom meta data
64
my $bomInfo;            # Sbom meta data
-
 
65
my %baseList;           # List of files in bin
64
 
66
 
65
#
67
#
66
#   Configuration file vars
68
#   Configuration file vars
67
#
69
#
68
my @confFilters;
70
my @confFilters;
Line 128... Line 130...
128
#   Non Filter operations
130
#   Non Filter operations
129
#   Must supply an rtagid
131
#   Must supply an rtagid
130
Error("Need --rtagid", "Example: -rtagid=2362" )
132
Error("Need --rtagid", "Example: -rtagid=2362" )
131
    unless ($opt_rtagid);
133
    unless ($opt_rtagid);
132
 
134
 
-
 
135
Error("No Filters defined.", "Add filters before creating BOM") 
-
 
136
    unless ( @confFilters );
-
 
137
 
133
#
138
#
134
#   This command is destined to be used in a directory where group permissions
139
#   This command is destined to be used in a directory where group permissions
135
#   are important. Ensure that the user is not killing group access
140
#   are important. Ensure that the user is not killing group access
136
#
141
#
137
umask 0002;
142
umask 0002;
Line 299... Line 304...
299
            Error("Failed to make project directory tree $opt_rootdir") if ( $@ || ! -d $opt_rootdir );
304
            Error("Failed to make project directory tree $opt_rootdir") if ( $@ || ! -d $opt_rootdir );
300
        }
305
        }
301
    }
306
    }
302
 
307
 
303
    #
308
    #
-
 
309
    #   Generate a list of all files in the directory
-
 
310
    #
-
 
311
    foreach my $file ( glob("$opt_rootdir/*") ) {
-
 
312
        $baseList{$file}{data} = 1;
-
 
313
    }
-
 
314
 
-
 
315
    #
304
    #   Determine the files to be transferred
316
    #   Determine the files to be transferred
305
    #
317
    #
306
    my @filelist;
318
    my @filelist;
307
    foreach my $file ( keys %bomList)
319
    foreach my $file ( keys %bomList)
308
    {
320
    {
Line 365... Line 377...
365
        push (@filelist, $dstFile) unless (exists $bomList{$dstFile} );
377
        push (@filelist, $dstFile) unless (exists $bomList{$dstFile} );
366
    }
378
    }
367
 
379
 
368
    if ( @filelist)
380
    if ( @filelist)
369
    {
381
    {
370
        Message ("Delete execess files", @filelist );
382
        #Message ("Delete execess files", @filelist );
371
        unless ( defined($opt_test) )
383
        unless ( defined($opt_test) )
372
        {
384
        {
373
            foreach my $file ( @filelist )
385
            foreach my $file ( @filelist )
374
            {
386
            {
375
                Verbose("Delete: $file...");
387
                Verbose("Delete: $file...");
Line 378... Line 390...
378
                    Warning("Failed to delete: $file. ($!)");
390
                    Warning("Failed to delete: $file. ($!)");
379
                }
391
                }
380
            }
392
            }
381
        }
393
        }
382
    }
394
    }
-
 
395
 
-
 
396
    #
-
 
397
    #   Report changed files
-
 
398
    #   Generate a list of all files in the directory
-
 
399
    #
-
 
400
    foreach my $file ( glob("$opt_rootdir/*") ) {
-
 
401
        $baseList{$file}{data} |= 2;
-
 
402
    }
-
 
403
 
-
 
404
    #
-
 
405
    #   Determined added, removed and replaced
-
 
406
    #       
-
 
407
    #
-
 
408
    my (@replaced, @added, @removed, @unchanged, %newList);
-
 
409
    foreach my $entry ( keys %baseList )
-
 
410
    {
-
 
411
        (my $key = $entry) =~ s~\d+~z~g;
-
 
412
        $baseList{$entry}{key} = $key;
-
 
413
 
-
 
414
        (my $name = $entry) =~ s~^\./~~;
-
 
415
        $newList{$key}{$baseList{$entry}{data}} = $entry;
-
 
416
    }
-
 
417
    
-
 
418
    foreach my $key ( sort keys %newList )
-
 
419
    {
-
 
420
        if (exists $newList{$key}{1} && exists $newList{$key}{2}  ) {
-
 
421
            push @replaced, "$newList{$key}{1}   =>   $newList{$key}{2}";
-
 
422
        } elsif (exists $newList{$key}{1}) {
-
 
423
            push @removed, $newList{$key}{1};
-
 
424
        } elsif (exists $newList{$key}{2}) {
-
 
425
            push @added, $newList{$key}{2};
-
 
426
        } elsif (exists $newList{$key}{3}) {
-
 
427
            push @unchanged, $newList{$key}{3};
-
 
428
        }
-
 
429
    }
-
 
430
    
-
 
431
    Message ("Unchanged: " .(@unchanged ? scalar(@unchanged ) : 'None') );
-
 
432
    Message ("Replaced: " . (@replaced ?  scalar(@replaced )  : 'None'), @replaced);
-
 
433
    Message ("Added: " .    (@added    ?  scalar(@added )     : 'None'), @added);
-
 
434
    Message ("Removed: " .  (@removed  ?  scalar(@removed )   : 'None'), @removed);
383
}
435
}
384
 
436
 
385
#-------------------------------------------------------------------------------
437
#-------------------------------------------------------------------------------
386
# Function        : RemoveDuplicates 
438
# Function        : RemoveDuplicates 
387
#
439
#
Line 440... Line 492...
440
sub LoadFilterConfig
492
sub LoadFilterConfig
441
{
493
{
442
    if ( -f "$opt_rootdir/$CONFFILE" )
494
    if ( -f "$opt_rootdir/$CONFFILE" )
443
    {
495
    {
444
        Message("Loading Config File");
496
        Message("Loading Config File");
445
 
-
 
446
        local $/;
-
 
447
        open(my $fh, "<$opt_rootdir/$CONFFILE") || Error("Failed to open config file");
-
 
448
        my $json_text = <$fh>;
-
 
449
        my $perl_scalar = decode_json( $json_text );
497
        my $perl_scalar = ReadJsonFile("$opt_rootdir/$CONFFILE");
450
        Error ("Invalid format in Config file")
498
        Error ("Invalid format in Config file")
451
            unless (ref($perl_scalar->{filters}) eq 'ARRAY');
499
            unless (ref($perl_scalar->{filters}) eq 'ARRAY');
452
 
500
 
453
        push (@confFilters, @{$perl_scalar->{filters}});
501
        push (@confFilters, @{$perl_scalar->{filters}});
454
        push (@confFiles, @{$perl_scalar->{keptfiles}}) if exists ($perl_scalar->{keptfiles});
502
        push (@confFiles, @{$perl_scalar->{keptfiles}}) if exists ($perl_scalar->{keptfiles});
455
        close($fh);
-
 
456
    }
503
    }
457
}
504
}
458
 
505
 
459
#-------------------------------------------------------------------------------
506
#-------------------------------------------------------------------------------
-
 
507
# Function        : ReadJsonFile 
-
 
508
#
-
 
509
# Description     : Read a JSON file and return the data 
-
 
510
#
-
 
511
# Inputs          : $fname  - Name of the file to read 
-
 
512
#
-
 
513
# Returns         : Ref to the JSON 
-
 
514
#
-
 
515
sub ReadJsonFile
-
 
516
{
-
 
517
    my ($fname) = @_;
-
 
518
    local $/;
-
 
519
    open(my $fh, $fname ) || Error("Failed to open $fname. $!");
-
 
520
    my $json_text = <$fh>;
-
 
521
    my $perl_scalar = decode_json( $json_text );
-
 
522
    close($fh);
-
 
523
 
-
 
524
    return $perl_scalar;
-
 
525
}
-
 
526
 
-
 
527
#-------------------------------------------------------------------------------
-
 
528
# Function        : WriteJsonFile 
-
 
529
#
-
 
530
# Description     : Write data into a file as JSON
-
 
531
#
-
 
532
# Inputs          : $fname  - Name of file to write
-
 
533
#                   $data   - Ref to data to write 
-
 
534
#
-
 
535
# Returns         : Will not return on error
-
 
536
#
-
 
537
sub WriteJsonFile
-
 
538
{
-
 
539
    my ($fname, $data) = @_;
-
 
540
    FileCreate ($fname, to_json( $data, { ascii => 1, pretty => 1 }));
-
 
541
}
-
 
542
 
-
 
543
 
-
 
544
#-------------------------------------------------------------------------------
460
# Function        : ProcessFilterArgs
545
# Function        : ProcessFilterArgs
461
#
546
#
462
# Description     : Process the filter based arguments 
547
# Description     : Process the filter based arguments 
463
#
548
#
464
# Inputs          : 
549
# Inputs          : 
Line 469... Line 554...
469
{
554
{
470
    my $filterArgSeen;
555
    my $filterArgSeen;
471
    my $writeConf;
556
    my $writeConf;
472
 
557
 
473
 
558
 
474
    unless ( @confFilters )
-
 
475
    {
-
 
476
        Error("No Filters defined.", "Add filters before creating BOM");
-
 
477
    }
-
 
478
 
559
 
479
    if ( @opt_addFilters )
560
    if ( @opt_addFilters )
480
    {
561
    {
481
        Message ("Adding command line filters to the release config file");
562
        Message ("Adding command line filters to the release config file");
482
        foreach my $element (@opt_addFilters) {
563
        foreach my $element (@opt_addFilters) {
Line 520... Line 601...
520
        Verbose ("Write config file");
601
        Verbose ("Write config file");
521
 
602
 
522
        #
603
        #
523
        #   Add known files
604
        #   Add known files
524
        #
605
        #
525
        UniquePush (\@confFiles, $CONFFILE, $MANIFEST, $TFVARS);
606
        UniquePush (\@confFiles, $CONFFILE, $BOMFILE, $MANIFEST, $TFVARS);
526
 
607
 
527
        my $config;
608
        my $config;
528
        push @{$config->{filters}},@confFilters;
609
        push @{$config->{filters}},@confFilters;
529
        push @{$config->{keptfiles}},@confFiles;
610
        push @{$config->{keptfiles}},@confFiles;
530
        FileCreate ("$opt_rootdir/$CONFFILE", to_json( $config, { ascii => 1, pretty => 1 }));
611
        WriteJsonFile("$opt_rootdir/$CONFFILE",$config);
531
    }
612
    }
532
 
613
 
533
    #
614
    #
534
    #   Display information to the user
615
    #   Display information to the user
535
    #
616
    #
Line 581... Line 662...
581
    push @tfData2, "// Terraform variable definitions to map clean package name to full file name";
662
    push @tfData2, "// Terraform variable definitions to map clean package name to full file name";
582
    push @tfData2, "variable vixFileName {";
663
    push @tfData2, "variable vixFileName {";
583
    push @tfData2, "    type = \"map\"";
664
    push @tfData2, "    type = \"map\"";
584
    push @tfData2, "    default = {" ;
665
    push @tfData2, "    default = {" ;
585
 
666
 
586
    foreach my $item ( sort keys $bomInfo->{files} )
667
    foreach my $item ( sort keys %{$bomInfo->{files}} )
587
    {
668
    {
588
        push @tfData2, "        \"". $item  ."\" = \"" .$bomInfo->{files}{$item}{fullname} ."\"";
669
        push @tfData2, "        \"". $item  ."\" = \"" .$bomInfo->{files}{$item}{fullname} ."\"";
589
    }
670
    }
590
 
671
 
591
    push @tfData2, "    }" ;
672
    push @tfData2, "    }" ;
Line 655... Line 736...
655
#
736
#
656
# Returns         : 
737
# Returns         : 
657
#
738
#
658
sub GetPackageData
739
sub GetPackageData
659
{
740
{
660
    my $m_sqlstr =  "SELECT p.PKG_NAME, pv.PKG_VERSION" .
741
    my $m_sqlstr =  "SELECT p.PKG_NAME, " .
-
 
742
                    " pv.PKG_VERSION, " .
-
 
743
                    " l.name " .
661
                    " FROM package_versions pv, RELEASE_CONTENT rc, PACKAGES p" .
744
                    "FROM package_versions pv, " .
-
 
745
                    " RELEASE_MANAGER.RELEASE_CONTENT rc, " .
-
 
746
                    " RELEASE_MANAGER.PACKAGES p, " .
-
 
747
                    " RELEASE_MANAGER.LICENCING pl, " .
-
 
748
                    " RELEASE_MANAGER.LICENCES l " .
662
                    " WHERE rc.rtag_id = " . $opt_rtagid .
749
                    "WHERE rc.rtag_id     = $opt_rtagid " .
663
                    " AND rc.pv_id = pv.pv_id" .
750
                    " AND rc.pv_id         = pv.pv_id " .
664
                    " and p.PKG_ID = pv.pkg_id" .
751
                    " AND p.PKG_ID         = pv.pkg_id " .
665
                    " and pv.IS_DEPLOYABLE = 'Y'";
752
                    " AND pv.IS_DEPLOYABLE = 'Y' " .
-
 
753
                    " AND pl.PV_ID(+)      = pv.pv_id " .
-
 
754
                    " AND pl.LICENCE       = l.LICENCE(+)" ;
666
#                    " and ( pv.IS_DEPLOYABLE = 'Y' or upper( p.PKG_NAME) like 'ERG%' or upper( p.PKG_NAME) like 'VIX%' )";
755
#                    " and ( pv.IS_DEPLOYABLE = 'Y' or upper( p.PKG_NAME) like 'ERG%' or upper( p.PKG_NAME) like 'VIX%' )";
667
 
756
 
-
 
757
 
-
 
758
 
668
    my ( $PKG_NAME, $PKG_VERSION );
759
    my ( $PKG_NAME, $PKG_VERSION, $LICENSE );
669
    my $sth = $DM_DB->prepare($m_sqlstr);
760
    my $sth = $DM_DB->prepare($m_sqlstr);
670
    if ( defined($sth) )
761
    if ( defined($sth) )
671
    {
762
    {
672
        if ( $sth->execute( ) )
763
        if ( $sth->execute( ) )
673
        {
764
        {
674
            if ( $sth->rows )
765
            if ( $sth->rows )
675
            {
766
            {
676
                while ( ( $PKG_NAME, $PKG_VERSION ) = $sth->fetchrow_array )
767
                while ( ( $PKG_NAME, $PKG_VERSION, $LICENSE ) = $sth->fetchrow_array )
677
                {
768
                {
678
                    Verbose ("Deployable: $PKG_NAME, $PKG_VERSION");
769
                    Verbose ("Deployable: $PKG_NAME, $PKG_VERSION");
679
                    my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
770
                    my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
680
                    my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
771
                    my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
681
                    my $dstDir = $opt_rootdir;
772
                    my $dstDir = $opt_rootdir;
Line 698... Line 789...
698
                                my $srcFile = $srcPath;
789
                                my $srcFile = $srcPath;
699
                                $srcFile =~ s~^$srcDir/~~;
790
                                $srcFile =~ s~^$srcDir/~~;
700
                                $bomList{$srcFile}{path} = $srcPath;
791
                                $bomList{$srcFile}{path} = $srcPath;
701
                                $bomList{$srcFile}{package} = $PKG_NAME;
792
                                $bomList{$srcFile}{package} = $PKG_NAME;
702
                                $bomList{$srcFile}{version} = $PKG_VERSION;
793
                                $bomList{$srcFile}{version} = $PKG_VERSION;
-
 
794
                                $bomList{$srcFile}{license} = $LICENSE || '';
703
                            }
795
                            }
704
                        }
796
                        }
705
 
797
 
706
                        # if no files found using filters then issue warning
798
                        # if no files found using filters then issue warning
707
                        Warning("No Files found for Package Version $PKG_NAME/$PKG_VERSION using supplied filters") 
799
                        Warning("No Files found for Package Version $PKG_NAME/$PKG_VERSION using supplied filters") 
Line 750... Line 842...
750
    }
842
    }
751
    else
843
    else
752
    {
844
    {
753
        Error("Prepare failure", $sth->errstr(), $m_sqlstr );
845
        Error("Prepare failure", $sth->errstr(), $m_sqlstr );
754
    }
846
    }
-
 
847
 
-
 
848
    #
-
 
849
    #   Report Commercial packages
-
 
850
    #   Write out a file to contain the list of COTS files
-
 
851
    #
-
 
852
    my @Commercial;
-
 
853
    foreach my $file (sort keys %bomList)
-
 
854
    {
-
 
855
        next unless ($bomList{$file}{license} =~ m ~^Commercial~);
-
 
856
        $bomList{$file}{cots} = 1;
-
 
857
        push @Commercial, $file;
-
 
858
    }
-
 
859
    Message ("Commercial software packages:", @Commercial);
-
 
860
    my $data;
-
 
861
    $data->{COTS} = \@Commercial;
-
 
862
    WriteJsonFile ("$opt_rootdir/$BOMFILE", $data);
755
}
863
}
756
 
864
 
757
#-------------------------------------------------------------------------------
865
#-------------------------------------------------------------------------------
758
#   Documentation
866
#   Documentation
759
#
867
#