From: Stefano Tondo <stondo@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Joshua Watt <JPEWhacker@gmail.com>,
Alexander Kanavin <alex.kanavin@gmail.com>,
Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>,
Stefano Tondo <stondo@gmail.com>,
Stefano Tondo <stefano.tondo.ext@siemens.com>
Subject: [PATCH 4/4] oeqa/selftest: spdx: Test crate identity, scope and output PURLs
Date: Wed, 18 Nov 2026 10:29:27 +0100 [thread overview]
Message-ID: <20261118092927.204959-5-stondo@gmail.com> (raw)
In-Reply-To: <20261118092927.204959-1-stondo@gmail.com>
From: Stefano Tondo <stefano.tondo.ext@siemens.com>
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.
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. The other checks do not use crate names.
Signed-off-by: Stefano Tondo <stefano.tondo.ext@siemens.com>
---
meta/lib/oeqa/selftest/cases/spdx.py | 122 +++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py
index ce9a8af4f6..d75c6146c7 100644
--- a/meta/lib/oeqa/selftest/cases/spdx.py
+++ b/meta/lib/oeqa/selftest/cases/spdx.py
@@ -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,124 @@ 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_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)
--
2.56.1
prev parent reply other threads:[~2026-11-18 9:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:29 [PATCH 0/4] spdx30: identity and purls of dependency downloads Stefano Tondo
2026-11-18 9:29 ` [PATCH 1/4] spdx30: Take name, version and PURL of downloads from the fetcher Stefano Tondo
2026-11-18 9:29 ` [PATCH 2/4] spdx30: Record the lifecycle scope of crate dependencies Stefano Tondo
2026-11-18 9:29 ` [PATCH 3/4] spdx30: Add the PURLs of the source downloads to the output packages Stefano Tondo
2026-11-18 9:29 ` Stefano Tondo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118092927.204959-5-stondo@gmail.com \
--to=stondo@gmail.com \
--cc=JPEWhacker@gmail.com \
--cc=alex.kanavin@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=stefan.herbrechtsmeier@weidmueller.com \
--cc=stefano.tondo.ext@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.