Skip to content

Commit c401144

Browse files
committed
Adapt the documentDescribes behavior if multiple Project inputs
Signed-off-by: tdruez <[email protected]>
1 parent 25c02b5 commit c401144

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

scanpipe/pipes/output.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -734,30 +734,28 @@ def to_spdx(project, version=spdx.SPDX_SPEC_VERSION_2_3, include_files=False):
734734

735735
project_inputs_as_spdx_packages = get_inputs_as_spdx_packages(project)
736736

737-
# Use the Project's input(s) as the root element(s) that the SPDX document
738-
# describes.
737+
if project_inputs_as_spdx_packages:
738+
packages_as_spdx.extend(project_inputs_as_spdx_packages)
739+
740+
# Use the Project's input as the root element that the SPDX document describes.
739741
# This ensures "documentDescribes" points only to the main subject of the SBOM,
740742
# not to every dependency or file in the project.
741743
# See https://github.com/spdx/spdx-spec/issues/395 and
742744
# https://github.com/aboutcode-org/scancode.io/issues/564#issuecomment-3269296563
743745
# for detailed context.
744-
if project_inputs_as_spdx_packages:
745-
packages_as_spdx.extend(project_inputs_as_spdx_packages)
746-
describes = [
747-
input_as_spdx_package.spdx_id
748-
for input_as_spdx_package in project_inputs_as_spdx_packages
749-
]
746+
if len(project_inputs_as_spdx_packages) == 1:
747+
describe_spdx_id = project_inputs_as_spdx_packages[0].spdx_id
750748

751749
# Fallback to the Project as the SPDX root element for the "documentDescribes",
752-
# if not inputs are available.
750+
# if more than one input, or if no inputs, are available.
753751
else:
754752
project_as_root_package = spdx.Package(
755753
spdx_id=f"SPDXRef-scancodeio-project-{project.uuid}",
756754
name=project.name,
757755
files_analyzed=True,
758756
)
759757
packages_as_spdx.append(project_as_root_package)
760-
describes = [project_as_root_package.spdx_id]
758+
describe_spdx_id = project_as_root_package.spdx_id
761759

762760
for package in discoveredpackage_qs:
763761
spdx_package = package.as_spdx()
@@ -767,7 +765,7 @@ def to_spdx(project, version=spdx.SPDX_SPEC_VERSION_2_3, include_files=False):
767765
license_expressions.append(license_expression)
768766

769767
spdx_relationship = spdx.Relationship(
770-
spdx_id=describes[0],
768+
spdx_id=describe_spdx_id,
771769
related_spdx_id=spdx_package.spdx_id,
772770
relationship="DEPENDS_ON",
773771
)
@@ -793,7 +791,7 @@ def to_spdx(project, version=spdx.SPDX_SPEC_VERSION_2_3, include_files=False):
793791
spdx_id=document_spdx_id,
794792
name=f"scancodeio_{project.name}",
795793
namespace=f"https://scancode.io/spdxdocs/{project.uuid}",
796-
describes=describes,
794+
describes=[describe_spdx_id],
797795
creation_info=spdx.CreationInfo(tool=f"ScanCode.io-{scancodeio_version}"),
798796
packages=packages_as_spdx,
799797
files=files_as_spdx,

0 commit comments

Comments
 (0)