Skip to contentSkip to conversation

spdx30: identity and purls of dependency downloads

PATCH Superseded Stefano Tondo 2 participants 9 messages Nov 25 – Nov 26

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover spdx30: identity and purls of dependency downloads

Hi,

This series implements the parts of the RFC "spdx30: name, version and purl for dependency downloads" [1] that we agreed on. It needs package_identity() from the bitbake series "fetch: package identity of crate, gomod and npm URLs" [2], which is in bitbake master now.

1. The SPDX of a crate, gomod or npm download gets the name, the version and the purl from the fetcher.
2. A class can give the downloads of a recipe a lifecycle scope with a function in the new variable SPDX_DEPENDENCY_SCOPE_FUNCS. The build links to each download with a runtime, build or test scope. A download that is not used on the target gets an annotation. For Cargo recipes, a new do_cargo_metadata task writes the crate dependency graph for the target with all features, and oe.rust.cargo_dependency_scopes() reads it.
3. Each output package gets the purls of its source downloads as external identifiers, as Joshua proposed: a statically linked dependency is part of the binary. A purl is left out only when a scope function shows that the download is not in the target. The software_packageUrl of the package does not change.
4. Selftests with python3-bcrypt.

For python3-bcrypt, the output package gets the purls of 25 of its 42 crates. The other 17 crates are not built into the target.

Three points for review:

- The cargo graph has all features, so a crate of a feature that the recipe does not enable counts as used on the target. rpm-sequoia selects one crypto backend, but its package gets the purls of the crates of the other backends too. A follow-up can make this more precise, for example with the crates that cargo really compiled.
- All output packages of a recipe get the purls, also -dbg and -src. I have no proof per package, so I followed the rule "keep the purl unless there is proof".
- Go recipes have no scope function yet. go version -m can give the proof per binary, and a follow-up can add it to SPDX_DEPENDENCY_SCOPE_FUNCS.

Changes in v4:

- Patch 2/4: the SPDX code does not read the cargo graph anymore, as Joshua asked [5]. create_spdx calls the functions in SPDX_DEPENDENCY_SCOPE_FUNCS. cargo.bbclass adds oe.rust.cargo_dependency_scopes(), and the walk over the cargo graph moves to oe/rust.py.
- Patch 2/4: do_cargo_metadata writes the graph with all features. v3 used the default features. rpm-sequoia builds with the feature crypto-openssl, so v3 annotated openssl-sys as not built and left its purl out of the package.
- Patch 2/4: do_cargo_metadata does not fail when cargo cannot give the graph. In v3 it failed for mozjs-140 in meta-oe, which configures the crate sources in its own way.
- Patch 3/4: uses the result of the scope functions, so it is not specific to Cargo anymore.
- Patch 4/4: add a test with rpm-sequoia.
- Patch 1/4: add the Reviewed-by of Joshua.
- Rebased on master.

Changes in v3:

- Patch 1/4: read the PackageIdentity dataclass that package_identity() returns in v2 of the bitbake series [2], as Paul proposed [4].
- Rebased on master, which has python3-uv-build 0.13.8.

Changes in v2:

- Patch 2/4: the walk over the cargo graph expands each workspace member only once. In v1 it did not end for python3-uv-build, where the member uv-preview is a dev dependency of itself. do_create_spdx used memory until the OOM killer stopped it. Thanks to Mathieu for the report [3].
- Patch 2/4: add unit tests for the scopes, with member cycles.
- Rebased on master.

Tests: oe-selftest -r oelib.cargo_scopes spdx.SPDX30Check passes on master (24 tests). The new rpm-sequoia test fails without the feature fix. do_cargo_metadata succeeds for the 29 recipes in oe-core and meta-oe that inherit cargo: 27 get a graph, mozjs-140 gets none, and python3-setuptools-rust is not a Cargo project.

[1] https://lore.kernel.org/openembedded-core/[email protected]/
[2] https://lore.kernel.org/bitbake-devel/[email protected]/
[3] https://lore.kernel.org/openembedded-core/[email protected]/
[4] https://lore.kernel.org/bitbake-devel/[email protected]/
[5] https://lore.kernel.org/openembedded-core/CAJdd5GaVPXT8Af3qNPWRArPLRMupC875nHSw_jdqBs_563hjkw@mail.gmail.com/

Stefano Tondo (4):
spdx30: Take name, version and PURL of downloads from the fetcher
spdx30: Record the lifecycle scope of dependencies
spdx30: Add the PURLs of the source downloads to the output packages oeqa/selftest: spdx: Test crate identity, scope and output PURLs

 meta/classes-recipe/cargo.bbclass             |  27 ++++
 meta/classes/create-spdx-3.0.bbclass          |  12 ++
 meta/lib/oe/rust.py                           |  74 +++++++++
 meta/lib/oe/spdx30_tasks.py                   |  83 +++++++++-
 .../oeqa/selftest/cases/oelib/cargo_scopes.py |  96 +++++++++++
 meta/lib/oeqa/selftest/cases/spdx.py          | 151 ++++++++++++++++++
 6 files changed, 442 insertions(+), 1 deletion(-)
 create mode 100644 meta/lib/oeqa/selftest/cases/oelib/cargo_scopes.py
Signature · 1 line
2.56.1
#1 lore raw

PATCH v4 1/4 spdx30: Take name, version and PURL of downloads from the fetcher

From: Stefano Tondo <[email protected]>

The fetchers of package registries (crate, gomod, npm) know the name and the version of each package they download. Today the SPDX of such a download only has the file name, so an SBOM scanner cannot match the dependency.

Ask the fetcher with package_identity() and set the name, the version and the PURL of the download. This needs package_identity() in bitbake.

---
 meta/lib/oe/spdx30_tasks.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
meta/lib/oe/spdx30_tasks.py +14 -0
index 6eaa74ce3d..eded315819 100644
@@ -463,6 +463,19 @@ def enrich_source_package(d, dl, fd, file_name, primary_purpose):
             )
 
 
+def set_package_identity(d, dl, fd):
+    """Set name, version and PURL of a download that names a package.
+
+    Fetchers of package registries (crate, gomod, npm) know which package
+    a URL downloads, see FetchMethod.package_identity() in bitbake.
+    """
+    identity = fd.method.package_identity(fd, d)
+    if identity:
+        dl.name = identity.name
+        dl.software_packageVersion = identity.version
+        dl.software_packageUrl = identity.purl
+
+
 def add_download_files(d, objset):
     inputs = set()
     release_date = get_release_date(d)
@@ -528,6 +541,7 @@ def add_download_files(d, objset):
             )
 
             enrich_source_package(d, dl, fd, file_name, primary_purpose)
+            set_package_identity(d, dl, fd)
 
             if release_date is not None:
                 dl.releaseTime = release_date
Signature · 1 line
2.56.1
#2 lore raw

PATCH v4 2/4 spdx30: Record the lifecycle scope of dependencies

In reply to Stefano Tondo

From: Stefano Tondo <[email protected]>

A Cargo.lock file lists the crates for all targets, and some crates only run at build time (build scripts, proc-macros and the crates they use). The fetcher downloads all of them, but only some end up in the binary.

Add the variable SPDX_DEPENDENCY_SCOPE_FUNCS. A class adds a function to it that gives the downloads of a recipe a lifecycle scope. The create_spdx task links the build to each download with a scoped dependsOn relationship: runtime, build or test. A download that is fetched but not used on the target gets an annotation instead. The SPDX code does not read the files of a package manager.

For Cargo, add a do_cargo_metadata task that writes the dependency graph for the target with cargo metadata --filter-platform, and the scope function oe.rust.cargo_dependency_scopes() that reads it. The graph has all features, because a recipe can enable features in several places (CARGO_BUILD_FLAGS, PACKAGECONFIG, pyproject.toml). So a crate counts as not used on the target only when no feature uses it. If cargo cannot give the graph, the task does not fail, and the crate downloads get no scope.

The walk expands each workspace member only once. Members can depend on each other in a cycle, and a member can be a dev dependency of itself, as uv-preview is in python3-uv-build.

Add unit tests for the scopes, with member cycles.

---
 meta/classes-recipe/cargo.bbclass             | 27 ++++++
 meta/classes/create-spdx-3.0.bbclass          | 12 +++
 meta/lib/oe/rust.py                           | 74 ++++++++++++++
 meta/lib/oe/spdx30_tasks.py                   | 48 ++++++++++
 .../oeqa/selftest/cases/oelib/cargo_scopes.py | 96 +++++++++++++++++++
 5 files changed, 257 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/oelib/cargo_scopes.py
meta/classes-recipe/cargo.bbclass +27 -0
index 586071988a..4bb685599a 100644
@@ -26,6 +26,33 @@ cargo_do_compile () {
 	"${CARGO}" build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} "$@"
 }
 
+# The crate dependency graph for the target, with the crates that are not
+# used on it removed. create-spdx uses it to give each crate download a
+# lifecycle scope. The graph has all features, as the features that a
+# recipe enables are not known here: a crate is left out only when no
+# feature uses it on the target.
+CARGO_METADATA_FILE = "${WORKDIR}/cargo-metadata.json"
+
+do_cargo_metadata () {
+	rm -f "${CARGO_METADATA_FILE}"
+	# Some recipes inherit cargo without being a cargo project
+	if [ ! -f "${CARGO_MANIFEST_PATH}" ]; then
+		return
+	fi
+	# Without the graph, create-spdx keeps the PURLs of all crates. So do
+	# not fail when cargo cannot give it, for example when the recipe
+	# configures the crate sources in its own way.
+	if ! "${CARGO}" metadata --format-version 1 --offline --locked \
+		--manifest-path "${CARGO_MANIFEST_PATH}" \
+		--filter-platform "${RUST_HOST_SYS}" --all-features \
+		> "${CARGO_METADATA_FILE}"; then
+		bbnote "cargo metadata failed: the crate downloads get no lifecycle scope"
+		rm -f "${CARGO_METADATA_FILE}"
+	fi
+}
+addtask cargo_metadata after do_configure before do_compile do_create_spdx
+SPDX_DEPENDENCY_SCOPE_FUNCS += "oe.rust.cargo_dependency_scopes"
+
 cargo_do_install () {
 	local have_installed=false
 	for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
meta/classes/create-spdx-3.0.bbclass +12 -0
index 3c37a50a69..3a69305127 100644
@@ -21,6 +21,15 @@ SPDX_INCLUDE_BITBAKE_PARENT_BUILD[doc] = "Report the parent invocation of bitbak
     for each Build object. This allows you to know who invoked bitbake to perform \
     a build, but will result in non-reproducible SPDX output."
 
+SPDX_DEPENDENCY_SCOPE_FUNCS ?= ""
+SPDX_DEPENDENCY_SCOPE_FUNCS[doc] = "Space-separated list of functions that give \
+    the downloads of a recipe a lifecycle scope. Each function is called as \
+    func(d, identities). identities is a list of bb.fetch.PackageIdentity, one \
+    for each PURL of the downloads. The function returns a dict that maps the \
+    PURL of each download that it knows to the name of a LifecycleScopeType, for \
+    example runtime, build or test, or to None for a download that is fetched \
+    but not used on the target."
+
 SPDX_PACKAGE_ADDITIONAL_PURPOSE ?= ""
 SPDX_PACKAGE_ADDITIONAL_PURPOSE[doc] = "The list of additional purposes to assign to \
     the generated packages for a recipe. The primary purpose is always `install`. \
@@ -283,6 +292,9 @@ do_create_spdx[depends] += " \
     ${@create_spdx_source_deps(d)} \
 "
 do_create_spdx[vardeps] += "${SPDX3_VAR_DEPS}"
+# The scope functions are called by name, so bitbake does not find them in
+# the code
+do_create_spdx[vardeps] += "${SPDX_DEPENDENCY_SCOPE_FUNCS}"
 
 python do_create_spdx_setscene () {
     sstate_setscene(d)
meta/lib/oe/rust.py +74 -0

82 lines not on this page · raw message

meta/lib/oe/spdx30_tasks.py +48 -0

60 lines not on this page · raw message

meta/lib/oeqa/selftest/cases/oelib/cargo_scopes.py new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.56.1
#3 lore raw

Re: [PATCH v4 2/4] spdx30: Record the lifecycle scope of dependencies

Quoted 23 lines · Stefano Tondo

From: Stefano Tondo <[email protected]>

A Cargo.lock file lists the crates for all targets, and some crates only run at build time (build scripts, proc-macros and the crates they use). The fetcher downloads all of them, but only some end up in the binary.

Add the variable SPDX_DEPENDENCY_SCOPE_FUNCS. A class adds a function to it that gives the downloads of a recipe a lifecycle scope. The create_spdx task links the build to each download with a scoped dependsOn relationship: runtime, build or test. A download that is fetched but not used on the target gets an annotation instead. The SPDX code does not read the files of a package manager.

For Cargo, add a do_cargo_metadata task that writes the dependency graph for the target with cargo metadata --filter-platform, and the scope function oe.rust.cargo_dependency_scopes() that reads it. The graph has all features, because a recipe can enable features in several places (CARGO_BUILD_FLAGS, PACKAGECONFIG, pyproject.toml). So a crate counts as not used on the target only when no feature uses it. If cargo cannot give the graph, the task does not fail, and the crate downloads get no scope.

Quoted 5 lines

The walk expands each workspace member only once. Members can depend on each other in a cycle, and a member can be a dev dependency of itself, as uv-preview is in python3-uv-build.

Add unit tests for the scopes, with member cycles.

Hi Stefano,

This is an interesting patch, and I can see the value in tracking the "lifecycle scope" for each dependency. That is a whole new concept to add to recipes though.

I think this needs a proposal on the openembedded-architecture mailing list [1], so that the design can be discussed.

[1]: https://lists.openembedded.org/g/openembedded-architecture

Best regards,

Signature · 1 line
Paul Barker
#4 lore raw

Re: [PATCH v4 2/4] spdx30: Record the lifecycle scope of dependencies

Quoted 8 lines · Paul Barker

This is an interesting patch, and I can see the value in tracking the "lifecycle scope" for each dependency. That is a whole new concept to add to recipes though.

I think this needs a proposal on the openembedded-architecture mailing list [1], so that the design can be discussed.

[1]: https://lists.openembedded.org/g/openembedded-architecture

Hi Paul,

Thanks for the review. I agree that the scope is a new concept, and that its design needs a discussion first. I will send a proposal to the openembedded-architecture list.

I will send a v5 without this patch. Then the next patch (3/4 in v4) adds the purls of all source downloads to the output packages, with no filter. In the
RFC thread, Joshua called the filter optional [2]. Without it, a package can list a crate that only runs at build time. But each crate download that is built into the binary is in the list.

Mathieu, please drop v4 from master-next. v5 replaces it.

Best regards,
Stefano

[2] https://lore.kernel.org/openembedded-core/CAJdd5GZTCwr9VE8OmOw7RAki+Xu+kokCgtOHG+9ghE3frWPbqg@mail.gmail.com/

#5 lore raw

PATCH v4 3/4 spdx30: Add the PURLs of the source downloads to the output packages

In reply to Stefano Tondo

From: Stefano Tondo <[email protected]>

Statically linked code, for example a Rust crate, is part of the binary, but the SPDX of the output package only names the recipe. A vulnerability scanner that checks the packages of an image does not find the dependency.

Add the PURLs of the source downloads to the external identifiers of each output package. Leave out the downloads that a function in SPDX_DEPENDENCY_SCOPE_FUNCS shows are not built into the target, for example crates that only run at build time. The software_packageUrl of the package stays the first PURL in SPDX_PACKAGE_URLS.

---
 meta/lib/oe/spdx30_tasks.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
meta/lib/oe/spdx30_tasks.py +21 -2
index 588be68e58..d613b4dad1 100644
@@ -482,6 +482,9 @@ def add_dependency_scopes(d, objset, build, source_files):
     The build gets a scoped dependsOn relationship to each download with a
     scope. A download that is fetched but not used on the target gets an
     annotation instead.
+
+    Returns the downloads that are not built into the target: downloads
+    that are not used on it, and downloads with a scope other than runtime.
     """
     downloads = {}
     for dl in source_files:
@@ -500,10 +503,13 @@ def add_dependency_scopes(d, objset, build, source_files):
         )
 
     by_scope = {}
+    not_in_target = set()
     for purl, scope in scopes.items():
         if scope is not None and scope not in oe.spdx30.LifecycleScopeType.NAMED_INDIVIDUALS:
             bb.fatal("SPDX_DEPENDENCY_SCOPE_FUNCS: %s is not a lifecycle scope" % scope)
         for dl in downloads.get(purl, []):
+            if scope != "runtime":
+                not_in_target.add(dl)
             if scope is None:
                 objset.new_annotation(
                     dl,
@@ -522,6 +528,8 @@ def add_dependency_scopes(d, objset, build, source_files):
             sorted(oe.sbom30.get_element_link_id(dl) for dl in dls),
         )
 
+    return not_in_target
+
 
 def add_download_files(d, objset):
     inputs = set()
@@ -1025,7 +1033,18 @@ def create_spdx(d):
 
     source_files = add_download_files(d, build_objset)
     build_inputs |= source_files
-    add_dependency_scopes(d, build_objset, build, source_files)
+
+    # The output packages inherit the PURLs of the downloads they are built
+    # from, as the code of statically linked dependencies is in them. Only
+    # the downloads known not to be built into the target are left out.
+    not_in_target = add_dependency_scopes(d, build_objset, build, source_files)
+    dependency_purls = sorted(
+        {
+            dl.software_packageUrl
+            for dl in source_files
+            if getattr(dl, "software_packageUrl", None) and dl not in not_in_target
+        }
+    )
 
     recipe_spdx_license = add_license_expression(
         d, build_objset, d.getVar("LICENSE"), license_data, [recipe_objset]
@@ -1138,7 +1157,7 @@ def create_spdx(d):
                 d.getVar("SPDX_PACKAGE_URLS:%s" % package)
                 or d.getVar("SPDX_PACKAGE_URLS")
                 or ""
-            ).split()
+            ).split() + dependency_purls
 
             set_purls(spdx_package, purls)
 
Signature · 1 line
2.56.1
#6 lore raw

PATCH v4 4/4 oeqa/selftest: spdx: Test crate identity, scope and output PURLs

In reply to Stefano Tondo

From: Stefano Tondo <[email protected]>

python3-bcrypt fetches 42 crates. The new tests check three things:

- Each crate download has its name, version and PURL.
- Each crate download has a lifecycle scope, or an annotation that it is not built.
- The output package gets the PURLs of the runtime crates only.

A fourth test checks rpm-sequoia, which builds with the feature crypto-openssl instead of its default features: the download of openssl-sys must have the runtime scope.

The tests name only crates that do not change on recipe upgrades. blowfish is the cipher of bcrypt. Only the pyo3 proc-macros use syn, at build time. openssl-sys is the OpenSSL binding of the crypto-openssl backend. The other checks do not use crate names.

---
 meta/lib/oeqa/selftest/cases/spdx.py | 151 +++++++++++++++++++++++++++
 1 file changed, 151 insertions(+)
meta/lib/oeqa/selftest/cases/spdx.py +151 -0
index ce9a8af4f6..4768081ec5 100644
@@ -9,6 +9,7 @@ import hashlib
 from datetime import datetime, timezone
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
+import oe.purl
 import oe.spdx30
 
 
@@ -543,3 +544,153 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
 
         # Document should be fully linked
         self.check_objset_missing_ids(objset)
+
+    def test_crate_package_identity(self):
+        """Test that crate downloads carry name, version and a cargo PURL."""
+        objset = self.check_recipe_spdx(
+            "python3-bcrypt",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json",
+        )
+
+        prefix = "https://static.crates.io/crates/"
+        crates = 0
+        for pkg in objset.foreach_type(oe.spdx30.software_Package):
+            location = pkg.software_downloadLocation or ""
+            if not location.startswith(prefix):
+                continue
+            name, version, _ = location[len(prefix):].split("/")
+            self.assertEqual(pkg.name, name)
+            self.assertEqual(pkg.software_packageVersion, version)
+            self.assertEqual(
+                pkg.software_packageUrl,
+                f"pkg:cargo/{oe.purl.quote(name)}@{oe.purl.quote(version)}",
+            )
+            crates += 1
+
+        self.assertGreater(crates, 0, "no crate downloads found")
+
+    def test_crate_dependency_scope(self):
+        """Test that crate downloads get a lifecycle scope for the target.
+
+        Every crate download is either the target of one scoped dependsOn
+        relationship or annotated as not built. python3-bcrypt fetches crates
+        for other platforms (WebAssembly, UEFI), which are never built for a
+        Linux target. blowfish is the cipher of bcrypt, and syn only runs at
+        build time in proc-macros, so these names do not change on upgrades.
+        """
+        objset = self.check_recipe_spdx(
+            "python3-bcrypt",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json",
+        )
+
+        crates = {
+            pkg._id: pkg.name
+            for pkg in objset.foreach_type(oe.spdx30.software_Package)
+            if (pkg.software_packageUrl or "").startswith("pkg:cargo/")
+            and (pkg.software_downloadLocation or "").startswith("https://static.crates.io/")
+        }
+
+        scope_of = {}
+        for rel in objset.foreach_type(oe.spdx30.LifecycleScopedRelationship):
+            if rel.relationshipType != oe.spdx30.RelationshipType.dependsOn:
+                continue
+            for to in rel.to:
+                to_id = to if isinstance(to, str) else to._id
+                if to_id in crates:
+                    self.assertNotIn(crates[to_id], scope_of)
+                    scope_of[crates[to_id]] = rel.scope
+
+        not_built = set()
+        for annotation in objset.foreach_type(oe.spdx30.Annotation):
+            subject = annotation.subject
+            subject_id = subject if isinstance(subject, str) else subject._id
+            if subject_id in crates and "not built" in annotation.statement:
+                not_built.add(crates[subject_id])
+
+        self.assertEqual(set(scope_of) | not_built, set(crates.values()))
+        self.assertFalse(set(scope_of) & not_built)
+        self.assertTrue(not_built, "no crate for another platform found")
+        self.assertEqual(scope_of["syn"], oe.spdx30.LifecycleScopeType.build)
+        self.assertEqual(scope_of["blowfish"], oe.spdx30.LifecycleScopeType.runtime)
+
+    def test_crate_scope_with_recipe_features(self):
+        """Test that a crate of a feature that the recipe enables is runtime.
+
+        rpm-sequoia builds with --no-default-features --features
+        crypto-openssl, so its library uses openssl-sys. The default
+        features of rpm-sequoia select another backend. The crate graph has
+        all features, so openssl-sys gets the runtime scope.
+        """
+        objset = self.check_recipe_spdx(
+            "rpm-sequoia",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-rpm-sequoia.spdx.json",
+        )
+
+        openssl_sys = {
+            pkg._id
+            for pkg in objset.foreach_type(oe.spdx30.software_Package)
+            if (pkg.software_packageUrl or "").startswith("pkg:cargo/openssl-sys@")
+        }
+        self.assertTrue(openssl_sys, "no download of openssl-sys found")
+
+        runtime = set()
+        for rel in objset.foreach_type(oe.spdx30.LifecycleScopedRelationship):
+            if (
+                rel.relationshipType == oe.spdx30.RelationshipType.dependsOn
+                and rel.scope == oe.spdx30.LifecycleScopeType.runtime
+            ):
+                runtime |= {to if isinstance(to, str) else to._id for to in rel.to}
+        self.assertTrue(openssl_sys <= runtime, "openssl-sys does not have the runtime scope")
+
+    def test_crate_purls_in_output_package(self):
+        """Test that the output package inherits the PURLs of its crates.
+
+        The package gets the PURLs of the crates with the runtime scope in
+        the build SPDX, and no other crate PURLs. syn only runs at build
+        time in proc-macros, so it is not in the binary.
+        """
+        objset = self.check_recipe_spdx(
+            "python3-bcrypt",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/packages/package-python3-bcrypt.spdx.json",
+        )
+
+        package = next(
+            pkg
+            for pkg in objset.foreach_type(oe.spdx30.software_Package)
+            if pkg.name == "python3-bcrypt"
+        )
+        purls = {
+            e.identifier
+            for e in package.externalIdentifier
+            if e.externalIdentifierType == oe.spdx30.ExternalIdentifierType.packageUrl
+        }
+        crates = {p[len("pkg:cargo/"):].split("@")[0] for p in purls if p.startswith("pkg:cargo/")}
+
+        # The package's own PURL stays first
+        own_purls = get_bb_var("SPDX_PACKAGE_URLS", "python3-bcrypt").split()
+        self.assertEqual(package.software_packageUrl, own_purls[0])
+        self.assertTrue(set(own_purls) <= purls)
+        self.assertIn("blowfish", crates)
+        self.assertNotIn("syn", crates)
+
+        spdx_vars = get_bb_vars(["DEPLOY_DIR_SPDX", "SSTATE_PKGARCH"], "python3-bcrypt")
+        build_objset = self.check_spdx_file(
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json".format(**spdx_vars)
+        )
+        downloads = {
+            pkg._id: pkg.software_packageUrl
+            for pkg in build_objset.foreach_type(oe.spdx30.software_Package)
+            if (pkg.software_packageUrl or "").startswith("pkg:cargo/")
+        }
+        runtime = set()
+        for rel in build_objset.foreach_type(oe.spdx30.LifecycleScopedRelationship):
+            if rel.scope != oe.spdx30.LifecycleScopeType.runtime:
+                continue
+            for to in rel.to:
+                to_id = to if isinstance(to, str) else to._id
+                if to_id in downloads:
+                    runtime.add(downloads[to_id])
+
+        self.assertTrue(runtime, "no crate with the runtime scope found")
+        cargo_purls = {p for p in purls if p.startswith("pkg:cargo/")}
+        self.assertEqual(cargo_purls - set(own_purls), runtime)
Signature · 1 line
2.56.1
#7 lore raw

Re: [PATCH v4 4/4] oeqa/selftest: spdx: Test crate identity, scope and output PURLs

Quoted 9 lines · Stefano Tondo

From: Stefano Tondo <[email protected]>

python3-bcrypt fetches 42 crates. The new tests check three things:

- Each crate download has its name, version and PURL.
- Each crate download has a lifecycle scope, or an annotation that it is not built.
- The output package gets the PURLs of the runtime crates only.

Quoted 8 lines

A fourth test checks rpm-sequoia, which builds with the feature crypto-openssl instead of its default features: the download of openssl-sys must have the runtime scope.

The tests name only crates that do not change on recipe upgrades. blowfish is the cipher of bcrypt. Only the pyo3 proc-macros use syn, at build time. openssl-sys is the OpenSSL binding of the crypto-openssl backend. The other checks do not use crate names.

Hi Stefano,

I think this needs to be a simpler test recipe, preferably one with a fixed version to avoid it failing due to future upgrades. I know you've already replied to my previous email, but I'm not so sure that the dependencies of python3-bcrypt will always remain as this test case expects.

Perhaps we should use an artificial test recipe here instead.

Best regards,

Signature · 1 line
Paul Barker
#8 lore raw

Re: [PATCH v4 4/4] oeqa/selftest: spdx: Test crate identity, scope and output PURLs

Quoted 7 lines · Paul Barker

I think this needs to be a simpler test recipe, preferably one with a fixed version to avoid it failing due to future upgrades. I know you've already replied to my previous email, but I'm not so sure that the dependencies of python3-bcrypt will always remain as this test case expects.

Perhaps we should use an artificial test recipe here instead.

Hi Paul,

OK, I will change it. In v5 the tests use hello-rs from meta-selftest, which the devtool tests also use. It has a fixed SRCREV and fetches one crate, figlet-rs 0.1.5. The tests compare the SPDX with these fixed values. The rpm-sequoia test goes away with the scope patch.

Best regards,
Stefano