From: Stefano Tondo <stondo@gmail.com>
To: bitbake-devel@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 1/2] fetch: Add package_identity() to the fetchers
Date: Wed, 18 Nov 2026 10:28:30 +0100 [thread overview]
Message-ID: <20261118092831.201831-2-stondo@gmail.com> (raw)
In-Reply-To: <20261118092831.201831-1-stondo@gmail.com>
From: Stefano Tondo <stefano.tondo.ext@siemens.com>
Fetchers of package registries know which package a URL downloads:
its name and its version are part of the URL. SBOM generation needs
this data, but it can only get it today by parsing fetcher internals.
Add FetchMethod.package_identity(). It returns the name, the version
and the Package URL (purl) of the downloaded package as a dict, or
None when the URL does not name a package. It uses only the URL and
the datastore, so it works before the fetch and without network
access. Add bb.fetch.package_url() to build the purl with the correct
encoding.
Signed-off-by: Stefano Tondo <stefano.tondo.ext@siemens.com>
---
lib/bb/fetch/__init__.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
index ce2bd62ad..a4b5860c0 100644
--- a/lib/bb/fetch/__init__.py
+++ b/lib/bb/fetch/__init__.py
@@ -1765,6 +1765,33 @@ class FetchMethod(object):
"""
return []
+ def package_identity(self, ud, d):
+ """
+ Return the identity of the package that the URL downloads, for
+ fetchers of package registries that know it, as a dict with the
+ keys "name", "version" and "purl" (Package URL). Return None when
+ the URL does not name a package.
+
+ The result depends only on the URL and the datastore. It is
+ available as soon as the FetchData exists, before the fetch and
+ without network access. It is meant for SBOM generation.
+ """
+ return None
+
+
+def package_url(purl_type, name, version, qualifiers=None):
+ """
+ Return a Package URL (https://github.com/package-url/purl-spec) for a
+ package. name can contain "/": the segments before the last one are
+ the namespace. Each segment, the version and the qualifier values are
+ percent-encoded. qualifiers is a dict, written sorted by key.
+ """
+ quote = lambda s: urllib.parse.quote(s, safe="")
+ purl = "pkg:%s/%s@%s" % (purl_type, "/".join(quote(s) for s in name.split("/")), quote(version))
+ if qualifiers:
+ purl += "?" + "&".join("%s=%s" % (k, quote(v)) for k, v in sorted(qualifiers.items()))
+ return purl
+
class DummyUnpackTracer(object):
"""
--
2.56.1
next prev parent reply other threads:[~2026-11-18 9:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:28 [PATCH 0/2] fetch: package identity of crate, gomod and npm URLs Stefano Tondo
2026-11-18 9:28 ` Stefano Tondo [this message]
2026-11-18 9:28 ` [PATCH 2/2] fetch: Return the " Stefano Tondo
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=20261118092831.201831-2-stondo@gmail.com \
--to=stondo@gmail.com \
--cc=JPEWhacker@gmail.com \
--cc=alex.kanavin@gmail.com \
--cc=bitbake-devel@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.