From: Thomas Perale via buildroot <buildroot@buildroot.org>
To: buildroot@buildroot.org
Cc: Thomas Perale <thomas.perale@mind.be>
Subject: [Buildroot] [PATCH v5 2/8] utils/generate-cyclonedx: move license download in a function
Date: Wed, 11 Mar 2026 15:04:51 +0100 [thread overview]
Message-ID: <20260311140457.140041-3-thomas.perale@mind.be> (raw)
In-Reply-To: <20260311140457.140041-1-thomas.perale@mind.be>
Move the code that retrieve the SPDX licenses into a function instead of
doing it top-level.
This allows to pass the CycloneDX version as a function argument instead
of defining it as a top-level constant.
In next commit, the CycloneDX spec version might not be known when the
top-level code is executed.
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
---
utils/generate-cyclonedx | 49 +++++++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 13 deletions(-)
diff --git a/utils/generate-cyclonedx b/utils/generate-cyclonedx
index eff55bf598..52fb8cc3e9 100755
--- a/utils/generate-cyclonedx
+++ b/utils/generate-cyclonedx
@@ -18,15 +18,14 @@ import urllib.request
import subprocess
import sys
import re
+from typing import Tuple
CYCLONEDX_VERSION = (1, 6)
-SPDX_SCHEMA_URL = "https://raw.githubusercontent.com/CycloneDX/specification/{}.{}/schema/spdx.schema.json".format(*CYCLONEDX_VERSION)
brpath = Path(__file__).parent.parent
cyclonedxpath = Path(os.getenv("BR2_DL_DIR", brpath / "dl")) / "cyclonedx"
-SPDX_SCHEMA_PATH = cyclonedxpath / "spdx-{}.{}.schema.json".format(*CYCLONEDX_VERSION)
BR2_VERSION_FULL = (
subprocess.check_output(
@@ -41,20 +40,42 @@ BR2_VERSION_FULL = (
# 'resolved_with_pedigree'.
VULN_WITH_PEDIGREE = set()
+# List of supported SPDX license expression.
SPDX_LICENSES = []
-if not SPDX_SCHEMA_PATH.exists():
- # Download the CycloneDX SPDX schema JSON, and cache it locally
- cyclonedxpath.mkdir(parents=True, exist_ok=True)
- urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH)
-try:
- with SPDX_SCHEMA_PATH.open() as f:
- SPDX_LICENSES = json.load(f).get("enum", [])
-except json.JSONDecodeError:
- # In case of error the license will just not be matched to the SPDX names
- # but the SBOM generation still work.
- print(f"Failed to load the SPDX licenses file: {SPDX_SCHEMA_PATH}", file=sys.stderr)
+def br2_retrieve_spdx_licenses(version: Tuple[int, int]):
+ """Populate the list of supported SPDX licenses for a given CycloneDX
+ version. If the list is not present locally it will be downloaded
+ externally.
+
+ Args:
+ version (str): CycloneDX version
+
+ Returns:
+ None
+ """
+ SPDX_SCHEMA_URL = "https://raw.githubusercontent.com/CycloneDX/specification/{}.{}/schema/spdx.schema.json".format(
+ *version
+ )
+
+ ret = []
+ path = cyclonedxpath / "spdx-{}.{}.schema.json".format(*version)
+
+ if not path.exists():
+ # Download the CycloneDX SPDX schema JSON, and cache it locally
+ cyclonedxpath.mkdir(parents=True, exist_ok=True)
+ urllib.request.urlretrieve(SPDX_SCHEMA_URL, path)
+
+ try:
+ with path.open() as f:
+ ret = json.load(f).get("enum", [])
+ except json.JSONDecodeError:
+ # In case of error the license will just not be matched to the SPDX names
+ # but the SBOM generation still work.
+ print(f"Failed to load the SPDX licenses file: {path}", file=sys.stderr)
+
+ return ret
def split_top_level_comma(subj):
@@ -404,6 +425,8 @@ def main():
parser.print_help()
sys.exit(1)
+ SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
+
show_info_dict = json.load(args.in_file)
# Remove rootfs and virtual packages if not explicitly included
--
2.53.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2026-03-11 14:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 14:04 [Buildroot] [PATCH v5 0/8] Support CycloneDX v1.7 Thomas Perale via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 1/8] utils/generate-cyclonedx: use tuple for version Thomas Perale via buildroot
2026-04-09 12:08 ` Quentin Schulz via buildroot
2026-04-09 20:27 ` Thomas Perale via buildroot
2026-03-11 14:04 ` Thomas Perale via buildroot [this message]
2026-04-09 12:12 ` [Buildroot] [PATCH v5 2/8] utils/generate-cyclonedx: move license download in a function Quentin Schulz via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 3/8] utils/generate-cyclonedx: move utility function Thomas Perale via buildroot
2026-04-09 12:27 ` Quentin Schulz via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 4/8] utils/generate-cyclonedx: encapsulate CycloneDX generation functions Thomas Perale via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 5/8] utils/generate-cyclonedx: optional bump to v1.7 Thomas Perale via buildroot
2026-04-09 12:40 ` Quentin Schulz via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 6/8] utils/generate-cyclonedx: mark host packages as external Thomas Perale via buildroot
2026-04-09 12:58 ` Quentin Schulz via buildroot
2026-04-09 20:42 ` Thomas Perale via buildroot
2026-04-09 20:43 ` Thomas Perale via buildroot
2026-04-10 9:12 ` Quentin Schulz via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 7/8] utils/generate-cyclonedx: add 'id' property to resolves Thomas Perale via buildroot
2026-04-09 13:22 ` Quentin Schulz via buildroot
2026-04-09 20:24 ` Thomas Perale via buildroot
2026-03-11 14:04 ` [Buildroot] [PATCH v5 8/8] utils/generate-cyclonedx: split vulnerabilities per state Thomas Perale via buildroot
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=20260311140457.140041-3-thomas.perale@mind.be \
--to=buildroot@buildroot.org \
--cc=thomas.perale@mind.be \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox