Subversion Repositories DevTools

Rev

Rev 279 | Rev 285 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 279 Rev 281
Line 1... Line 1...
1
########################################################################
1
########################################################################
2
# Copyright ( C ) 2007 ERG Limited, All rights reserved
2
# Copyright ( C ) 2009 ERG Limited, All rights reserved
3
#
3
#
4
# Module name   : jats.sh
4
# Module name   : escrow.pl
5
# Module type   : Makefile system
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
6
# Compiler(s)   : Perl
7
# Environment(s): jats
7
# Environment(s): jats build system
8
#
8
#
9
# Description   : Determine packages from an SBOM for escrow purposes
9
# Description   : Determine packages from an SBOM for escrow purposes
10
#                 For a given bom_id determine all used packages
10
#                 For a given bom_id determine all used packages
11
#                 Create various bits of useful information
11
#                 Create various bits of useful information
12
#                   Extract commands
12
#                   Extract commands
13
#                   Build Order
13
#                   Build Order
14
#                   Depenendency Info
14
#                   Depenendency Info
15
#                   Bad Packages
15
#                   Bad Packages
16
#
16
#
17
#
-
 
18
#......................................................................#
17
#......................................................................#
19
 
18
 
20
require 5.006_001;
19
require 5.006_001;
21
use strict;
20
use strict;
22
use warnings;
21
use warnings;
Line 27... Line 26...
27
use DBI;
26
use DBI;
28
use Getopt::Long;
27
use Getopt::Long;
29
use Pod::Usage;                             # required for help support
28
use Pod::Usage;                             # required for help support
30
use Storable qw (dclone);
29
use Storable qw (dclone);
31
 
30
 
32
 
-
 
33
#
31
#
34
#   Config Options
32
#   Config Options
35
#
33
#
36
my $VERSION = "1.0.0";              # Update this
34
my $VERSION = "1.0.0";              # Update this
37
my $opt_help = 0;
35
my $opt_help = 0;
38
my $opt_manual;
-
 
39
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
36
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
40
my $opt_sbom_id;
37
my $opt_sbom_id;
41
my $opt_rtag_id;
38
my $opt_rtag_id;
42
my $opt_test = 0;
39
my $opt_test = 0;
43
my $opt_patch = 1;
40
my $opt_patch = 1;
Line 107... Line 104...
107
#
104
#
108
# Returns         :
105
# Returns         :
109
#
106
#
110
 
107
 
111
my $result = GetOptions (
108
my $result = GetOptions (
112
                "help+"         => \$opt_help,              # flag, multiple use allowed
109
                "help:+"        => \$opt_help,              # flag, multiple use allowed
113
                "manual"        => \$opt_manual,            # flag
110
                "manual:3"      => \$opt_help,              # flag, multiple use allowed
114
                "verbose+"      => \$opt_verbose,           # flag
111
                "verbose:+"     => \$opt_verbose,           # flag
115
                "sbomid=s"      => \$opt_sbom_id,           # string
112
                "sbomid=s"      => \$opt_sbom_id,           # string
116
                "sbom_id=s"     => \$opt_sbom_id,           # string
113
                "sbom_id=s"     => \$opt_sbom_id,           # string
117
                "rtagid=s"      => \$opt_rtag_id,           # string
114
                "rtagid=s"      => \$opt_rtag_id,           # string
118
                "rtag_id=s"     => \$opt_rtag_id,           # string
115
                "rtag_id=s"     => \$opt_rtag_id,           # string
119
                "rootpackage=s" => \$opt_rootpkg,           # String
116
                "rootpackage=s" => \$opt_rootpkg,           # String
Line 126... Line 123...
126
#
123
#
127
#   Process help and manual options
124
#   Process help and manual options
128
#
125
#
129
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
126
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
130
pod2usage(-verbose => 1)  if ($opt_help == 2 );
127
pod2usage(-verbose => 1)  if ($opt_help == 2 );
131
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
128
pod2usage(-verbose => 2)  if ($opt_help > 2);
132
 
129
 
133
ErrorConfig( 'name'    => 'ESCROW',
130
ErrorConfig( 'name'    => 'ESCROW',
134
             'verbose' => $opt_verbose );
131
             'verbose' => $opt_verbose );
135
 
132
 
136
#
133
#
137
#   Sanity test
134
#   Sanity test
138
#
135
#
139
unless ( $opt_rtag_id || $opt_sbom_id || $opt_extract)
136
unless ( $opt_rtag_id || $opt_sbom_id || $opt_extract || $#ARGV >= 1)
140
{
137
{
141
    Error ("Need sbomid and/or rtagid, or -extract",
138
    Error ("Need sbomid and/or rtagid, or -extract",
142
           "Example: -sbomid=13543, for NZS Phase-1",
139
           "Example: -sbomid=13543, for NZS Phase-1",
143
           "Example: -sbomid=13543 -rtagid=xxxx, for NZS Phase-1, comapred against given release",
140
           "Example: -sbomid=13543 -rtagid=xxxx, for NZS Phase-1, comapred against given release",
144
           "Example: -rtagid=2362, for Sydney R1/R2",
141
           "Example: -rtagid=2362, for Sydney R1/R2",
145
           "Example: -rtagid=8843 -root=StockholmSBOM",
142
           "Example: -rtagid=8843 -root=StockholmSBOM",
-
 
143
           "Example: PackageName PackageVersion, for extracting a single package",
146
    )
144
    )
147
}
145
}
148
 
146
 
149
#
147
#
150
#   The extract option is special
148
#   The extract option is special
151
#   It places the progam in a different mode
149
#   It places the progam in a different mode
152
#
150
#
153
if ( $opt_extract )
151
if ( $opt_extract )
154
{
152
{
155
    Error ("Cannot mix -extract with sbomid or rtagid" )
153
    Error ("Cannot mix -extract with sbomid or rtagid" )
156
        if ( $opt_rtag_id || $opt_sbom_id );
154
        if ( $opt_rtag_id || $opt_sbom_id || $#ARGV >= 0 );
157
 
155
 
158
    extract_files();
156
    extract_files();
159
    exit (0);
157
    exit (0);
160
 
-
 
161
}
158
}
162
 
159
 
163
Warning ("No sbomid provided. Output based an a Release") unless ( $opt_sbom_id );
160
Warning ("No sbomid provided. Output based an a Release") unless ( $opt_sbom_id );
164
$dm_base =~ s~BOMID~$opt_sbom_id~ if ($opt_sbom_id);
161
$dm_base =~ s~BOMID~$opt_sbom_id~ if ($opt_sbom_id);
165
$fpref = "release" unless ( $opt_sbom_id );
162
$fpref = "release" unless ( $opt_sbom_id );
Line 197... Line 194...
197
    }
194
    }
198
 
195
 
199
    #
196
    #
200
    #   For each Top Level Package determine the dependent packages
197
    #   For each Top Level Package determine the dependent packages
201
    #
198
    #
202
    foreach my $pv_id ( keys %pv_id )
-
 
203
    {
-
 
204
        getPkgDetailsByPV_ID( $pv_id);
199
    getPkgDetailsForPVIDs (keys %pv_id);
205
    }
-
 
206
    LocateStrays();
200
    LocateStrays();
207
 
201
 
208
    #
202
    #
209
    #   Determine packages in a given Release
203
    #   Determine packages in a given Release
210
    #
204
    #
211
    if ( $opt_rtag_id )
205
    if ( $opt_rtag_id )
212
    {
206
    {
213
        getPkgDetailsByRTAG_ID( $opt_rtag_id );
207
        getPkgDetailsByRTAG_ID( $opt_rtag_id );
214
    }
208
    }
215
}
209
}
216
else
210
elsif ( $opt_rtag_id )
217
{
211
{
218
    getPkgDetailsByRTAG_ID( $opt_rtag_id );
212
    getPkgDetailsByRTAG_ID( $opt_rtag_id );
219
    if ( $opt_rootpkg )
213
    if ( $opt_rootpkg )
220
    {
214
    {
221
        #
215
        #
Line 229... Line 223...
229
 
223
 
230
        getPkgDetailsByPV_ID( $Release{$opt_rootpkg}{$root_vers[0]}{pv_id} );
224
        getPkgDetailsByPV_ID( $Release{$opt_rootpkg}{$root_vers[0]}{pv_id} );
231
    }
225
    }
232
    else
226
    else
233
    {
227
    {
234
my $count = 0;
-
 
235
        foreach my $pv_id ( keys %Release_pvid )
228
        getPkgDetailsForPVIDs (keys %Release_pvid);
236
        {
-
 
237
            next if ( $opt_test && ++$count > 2 );
-
 
238
            getPkgDetailsByPV_ID( $pv_id);
-
 
239
        }
-
 
240
    }
229
    }
241
    LocateStrays(1);
230
    LocateStrays(1);
242
}
231
}
-
 
232
elsif ( $#ARGV >= 1 )
-
 
233
{
-
 
234
    #
-
 
235
    #   Locate package and dependents
-
 
236
    #   Convert package name into a PVID
-
 
237
    #
-
 
238
    my $pv_id = getPkgDetailsByName( @ARGV );
-
 
239
    Error ("Cannot locate package by name and version: @ARGV")
-
 
240
        unless ( $pv_id );
-
 
241
 
-
 
242
    #
-
 
243
    #   Set package as the root package
-
 
244
    $opt_rootpkg = $ARGV[0];
-
 
245
    getPkgDetailsByPV_ID( $pv_id  );
-
 
246
    LocateStrays(2);
-
 
247
}
-
 
248
else
-
 
249
{
-
 
250
    Error ("Don't know what to do with common line arguments provided");
-
 
251
}
243
 
252
 
244
 
253
 
245
#
254
#
246
#   Remove packages to be ignored
255
#   Remove packages to be ignored
247
#
256
#
Line 634... Line 643...
634
        Error("Prepare failure" );
643
        Error("Prepare failure" );
635
    }
644
    }
636
}
645
}
637
 
646
 
638
#-------------------------------------------------------------------------------
647
#-------------------------------------------------------------------------------
-
 
648
# Function        : getPkgDetailsByName
-
 
649
#
-
 
650
# Description     : Determine the PVID for a given package name and version
-
 
651
#
-
 
652
# Inputs          : $pname          - Package name
-
 
653
#                   $pver           - Package Version
-
 
654
#
-
 
655
# Returns         : 
-
 
656
#
-
 
657
 
-
 
658
sub getPkgDetailsByName
-
 
659
{
-
 
660
    my ($pname, $pver) = @_;
-
 
661
    my $pv_id;
-
 
662
    my (@row);
-
 
663
 
-
 
664
    connectRM(\$RM_DB) unless ($RM_DB);
-
 
665
 
-
 
666
    # First get details for a given package version
-
 
667
 
-
 
668
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
-
 
669
                    " FROM PACKAGE_VERSIONS pv, PACKAGES pkg" .
-
 
670
                    " WHERE pkg.PKG_NAME = \'$pname\' AND pv.PKG_VERSION = \'$pver\' AND pv.PKG_ID = pkg.PKG_ID";
-
 
671
    my $sth = $RM_DB->prepare($m_sqlstr);
-
 
672
    if ( defined($sth) )
-
 
673
    {
-
 
674
        if ( $sth->execute( ) )
-
 
675
        {
-
 
676
            if ( $sth->rows )
-
 
677
            {
-
 
678
                while ( @row = $sth->fetchrow_array )
-
 
679
                {
-
 
680
                    $pv_id = $row[0];
-
 
681
                    my $name = $row[1];
-
 
682
                    my $ver = $row[2];
-
 
683
                    Verbose( "getPkgDetailsByName :PV_ID= $pv_id");
-
 
684
                }
-
 
685
            }
-
 
686
            $sth->finish();
-
 
687
        }
-
 
688
    }
-
 
689
    else
-
 
690
    {
-
 
691
        Error("Prepare failure" );
-
 
692
    }
-
 
693
    return $pv_id;
-
 
694
}
-
 
695
 
-
 
696
#-------------------------------------------------------------------------------
-
 
697
# Function        : getPkgDetailsForPVIDs
-
 
698
#
-
 
699
# Description     : Get all package details by PVID, from a list of PVIDs
-
 
700
#
-
 
701
# Inputs          : List of PVID's to process
-
 
702
#
-
 
703
# Returns         : Nothing
-
 
704
#
-
 
705
sub getPkgDetailsForPVIDs
-
 
706
{
-
 
707
    
-
 
708
    my $count = 0;
-
 
709
    foreach my $pv_id ( @_ )
-
 
710
    {
-
 
711
        next if ( $opt_test && ++$count > 2 );
-
 
712
        getPkgDetailsByPV_ID( $pv_id);
-
 
713
    }
-
 
714
}
-
 
715
 
-
 
716
#-------------------------------------------------------------------------------
639
# Function        : GetDepends
717
# Function        : GetDepends
640
#
718
#
641
# Description     : Extract the dependancies for a given package version
719
# Description     : Extract the dependancies for a given package version
642
#
720
#
643
# Inputs          : $pvid
721
# Inputs          : $pvid
Line 748... Line 826...
748
#
826
#
749
# Description     : Locate stray packages
827
# Description     : Locate stray packages
750
#                   These are packages that have not been defined by the
828
#                   These are packages that have not been defined by the
751
#                   top level SBOM. These are not really stray
829
#                   top level SBOM. These are not really stray
752
#
830
#
753
# Inputs          :
831
# Inputs          : $mode           2: No stray tagging
754
#
-
 
-
 
832
#                                   0: Mark all as stray
-
 
833
#                                   1: Don't mark packages as stray
-
 
834
#                                      if they are in releases hash
755
# Returns         :
835
# Returns         : Nothing
756
#
836
#
757
sub LocateStrays
837
sub LocateStrays
758
{
838
{
759
    my ($mode) = @_;
839
    my ($mode) = @_;
760
    while ( $#StrayPackages >= 0 )
840
    while ( $#StrayPackages >= 0 )
Line 764... Line 844...
764
        my $ver = $DATA->[1];
844
        my $ver = $DATA->[1];
765
        my $pv_id = $DATA->[2];
845
        my $pv_id = $DATA->[2];
766
 
846
 
767
        next if ( exists $Package{$name}{$ver}{done} );
847
        next if ( exists $Package{$name}{$ver}{done} );
768
        getPkgDetailsByPV_ID ( $pv_id );
848
        getPkgDetailsByPV_ID ( $pv_id );
-
 
849
        
-
 
850
        next if ( $mode > 1 );
769
        if ( $mode )
851
        if ( $mode )
770
        {
852
        {
771
            next if ( exists $Release{$name}{$ver} );
853
            next if ( exists $Release{$name}{$ver} );
772
        }
854
        }
773
        $Package{$name}{$ver}{stray} = 1;
855
        $Package{$name}{$ver}{stray} = 1;
Line 1648... Line 1730...
1648
 
1730
 
1649
escrow - Extract Escrow Build Information
1731
escrow - Extract Escrow Build Information
1650
 
1732
 
1651
=head1 SYNOPSIS
1733
=head1 SYNOPSIS
1652
 
1734
 
1653
  jats escrow [options]
1735
  jats escrow [options] [name version]
1654
 
1736
 
1655
 Options:
1737
 Options:
1656
    -help              - brief help message
1738
    -help              - brief help message
1657
    -help -help        - Detailed help message
1739
    -help -help        - Detailed help message
1658
    -man               - Full documentation
1740
    -man               - Full documentation
Line 1744... Line 1826...
1744
This program is a tool for extracting Escrow build information.
1826
This program is a tool for extracting Escrow build information.
1745
The program has two modes of operation:
1827
The program has two modes of operation:
1746
 
1828
 
1747
=over 8
1829
=over 8
1748
 
1830
 
1749
=item 1. Generation. Generate files describing packages within an SBOM/Release.
1831
=item 1. Generation. Generate files describing packages within an SBOM/Release/
-
 
1832
Package.
1750
 
1833
 
1751
=item 2. Extraction  Supervise extraction of source trees.
1834
=item 2. Extraction  Supervise extraction of source trees.
1752
 
1835
 
1753
=back
1836
=back
1754
 
1837
 
1755
=head2 Generation Operations
1838
=head2 Generation Operations
1756
 
1839
 
-
 
1840
This program has several modes of operation. The mode is determined from the
-
 
1841
command line arguments provided.
-
 
1842
 
-
 
1843
=over 8
-
 
1844
 
-
 
1845
=item   Full Escrow
-
 
1846
 
1757
Given an SBOM_ID and/or RTAG_ID this program will:
1847
This mode requires an SBOM_ID. If an RTAG_ID is also provided, then additional
-
 
1848
information will be generated.
-
 
1849
 
-
 
1850
=item   Release Escrow
-
 
1851
 
-
 
1852
If only an RTAG_ID is provided then the processing wil be limited to the
-
 
1853
packages involved in creating the specified release.
-
 
1854
 
-
 
1855
If a 'rootpackage' name is provided, then the processing is limited to
-
 
1856
packages that depend on the named package.
-
 
1857
 
-
 
1858
=item   Single Package
-
 
1859
 
-
 
1860
If a package name and a package version are specified on the command line,
-
 
1861
then the processing will be limited to the specified package and ist dependents.
-
 
1862
No release related information will be provided.
-
 
1863
 
-
 
1864
=back
-
 
1865
 
-
 
1866
The 'Full Escrow' extract is the complete operation. All others are sub-sets of
-
 
1867
this processing. The complete processing is:
1758
 
1868
 
1759
=over 8
1869
=over 8
1760
 
1870
 
1761
=item * Determine all the NODES in the SBOM
1871
=item * Determine all the NODES in the SBOM
1762
 
1872