Skip to content

Commit

Permalink
Encode the current $dist as a package in the SPDX report
Browse files Browse the repository at this point in the history
  • Loading branch information
josegomezr committed Nov 18, 2024
1 parent 61a2c24 commit c304ab0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions generate_sbom
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,13 @@ sub spdx_encode_pkg {
}
$spdx->{'copyrightText'} = $p->{'COPYRIGHTTEXT'} ? $p->{'COPYRIGHTTEXT'} : 'NOASSERTION';
$spdx->{'homepage'} = $p->{'URL'} if $p->{'URL'};
my $purlurl = gen_purl($p, $distro, $pkgtype);
push @{$spdx->{'externalRefs'}}, { 'referenceCategory' => 'PACKAGE-MANAGER', 'referenceType' => 'purl', 'referenceLocator', $purlurl } if $purlurl;

# Let the caller control the presence of external refs
if($p->{'external_refs'} // 1) {
my $purlurl = gen_purl($p, $distro, $pkgtype);
push @{$spdx->{'externalRefs'}}, { 'referenceCategory' => 'PACKAGE-MANAGER', 'referenceType' => 'purl', 'referenceLocator', $purlurl } if $purlurl;
}

if (!$p->{'spdx_id'}) {
my $spdxtype = "Package-$pkgtype";
$spdxtype = "Package-go-module" if $pkgtype eq 'golang';
Expand Down Expand Up @@ -935,6 +940,17 @@ sub spdx_encode_header {
return $spdx;
}

sub spdx_encode_dist {
my ($dist) = @_;

return spdx_encode_pkg({
NAME => $dist->{id},
VERSION => $dist->{version_id},
spdx_id => sprintf('SPDXRef-OperatingSystem-%s', gen_pkg_id($dist)),
external_refs => 0
}, undef, undef, {});

}

##################################################################################################
#
Expand Down Expand Up @@ -1170,6 +1186,9 @@ if ($format eq 'spdx') {
push @{$doc->{'files'}}, spdx_encode_file($f);
}
}

push @{$doc->{'packages'}}, spdx_encode_dist($dist);

for (sort keys %unknown_spdx_licenses) {
push @{$doc->{'hasExtractedLicensingInfos'}}, spdx_encode_extracted_license($unknown_spdx_licenses{$_});
}
Expand Down

0 comments on commit c304ab0

Please sign in to comment.