From: Kamel Bouhara <kamel.bouhara@bootlin.com>
To: openembedded-core@lists.openembedded.org
Cc: JPEWhacker@gmail.com, thomas.petazzoni@bootlin.com,
mathieu.dubois-briand@bootlin.com, antonin.godard@bootlin.com,
Kamel Bouhara <kamel.bouhara@bootlin.com>
Subject: [PATCH 1/1] spdx3: Add optional kernel configuration export to build_parameter for virtual/kernel
Date: Wed, 16 Jul 2025 11:05:17 +0200 [thread overview]
Message-ID: <20250716090517.481832-2-kamel.bouhara@bootlin.com> (raw)
In-Reply-To: <20250716090517.481832-1-kamel.bouhara@bootlin.com>
Enhances SPDX Document by extracting kernel build-time configuration settings from '${B}/.config'.
Each CONFIG_* line is parsed and exported as a DictionaryEntry in the build_Build.build_parameter
section of the SPDX document. This provides better visibility into kernel build behavior and
configuration, in alignment with the SPDX3 metadata model.
The feature is gated by a new tunable variable:
SPDX_INCLUDE_KERNEL_CONFIG (default: "1")
Setting this to "0" disables exporting the kernel configuration, which may be useful to improve
performance or reduce the size of generated SPDX documents.
Example:
CONFIG_FOO=y → { key: "CONFIG_FOO", value: "y" }
This complements existing metadata export features and enables a more complete audit trail of how
the kernel is built within a given build.
Signed-off-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
---
meta/classes/create-spdx-3.0.bbclass | 6 ++++++
meta/lib/oe/spdx30_tasks.py | 32 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/meta/classes/create-spdx-3.0.bbclass b/meta/classes/create-spdx-3.0.bbclass
index c0a5436ad6..cdb9422f37 100644
--- a/meta/classes/create-spdx-3.0.bbclass
+++ b/meta/classes/create-spdx-3.0.bbclass
@@ -50,6 +50,12 @@ SPDX_INCLUDE_TIMESTAMPS[doc] = "Include time stamps in SPDX output. This is \
useful if you want to know when artifacts were produced and when builds \
occurred, but will result in non-reproducible SPDX output"
+SPDX_INCLUDE_KERNEL_CONFIG ??= "1"
+SPDX_INCLUDE_KERNEL_CONFIG[doc] = "If set to '1', the .config file for the kernel will be parsed \
+and each CONFIG_* value will be included in the Build.build_parameter list as DictionaryEntry \
+items. Set to '0' to disable exporting kernel configuration to improve performance or reduce \
+SPDX document size."
+
SPDX_IMPORTS ??= ""
SPDX_IMPORTS[doc] = "SPDX_IMPORTS is the base variable that describes how to \
reference external SPDX ids. Each import is defined as a key in this \
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index c352dab152..f87d079cb0 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -18,6 +18,28 @@ from contextlib import contextmanager
from datetime import datetime, timezone
from pathlib import Path
+def parse_kernel_config(config_path):
+ entries = []
+ if not os.path.exists(config_path):
+ bb.warn(f"Kernel config file not found at: {config_path}")
+ return entries
+
+ try:
+ with open(config_path, 'r') as f:
+ for line in f:
+ line = line.strip()
+ if not line or line.startswith("#"):
+ continue
+ if "=" in line:
+ key, value = line.split("=", 1)
+ entries.append(oe.spdx30.DictionaryEntry(
+ key=key,
+ value=value.strip('"')
+ ))
+ bb.note(f"Parsed {len(entries)} kernel config entries from {config_path}")
+ except Exception as e:
+ bb.error(f"Failed to parse kernel config file: {e}")
+ return entries
def walk_error(err):
bb.error(f"ERROR walking {err.filename}: {err}")
@@ -495,6 +517,8 @@ def create_spdx(d):
build_objset.doc.rootElement.append(build)
+ build.build_parameter = []
+
build_objset.set_is_native(is_native)
for var in (d.getVar("SPDX_CUSTOM_ANNOTATION_VARS") or "").split():
@@ -815,6 +839,14 @@ def create_spdx(d):
sorted(list(build_inputs)) + sorted(list(debug_source_ids)),
)
+ if d.getVar("SPDX_INCLUDE_KERNEL_CONFIG", True) != "0":
+ if "virtual/kernel" in (d.getVar("PROVIDES") or "").split():
+ bb.note("Detected virtual/kernel provider, extracting kernel configuration")
+ config_path = d.expand("${B}/.config")
+ kernel_params = parse_kernel_config(config_path)
+ if kernel_params:
+ build.build_parameter.extend(kernel_params)
+
oe.sbom30.write_recipe_jsonld_doc(d, build_objset, "recipes", deploydir)
--
2.43.0
next prev parent reply other threads:[~2025-07-16 9:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-16 9:05 [PATCH 0/1] spdx3: Export kernel configuration as build parameters in SPDX output Kamel Bouhara
2025-07-16 9:05 ` Kamel Bouhara [this message]
2025-07-16 9:28 ` [OE-core] [PATCH 1/1] spdx3: Add optional kernel configuration export to build_parameter for virtual/kernel Mikko Rapeli
2025-07-16 11:34 ` Kamel Bouhara
2025-07-16 13:30 ` Bruce Ashfield
2025-07-16 14:30 ` Kamel Bouhara
2025-07-16 14:51 ` Bruce Ashfield
2025-07-17 7:07 ` Kamel Bouhara
2025-07-18 22:10 ` Joshua Watt
2025-07-21 14:53 ` Kamel Bouhara
2025-07-21 16:45 ` Joshua Watt
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=20250716090517.481832-2-kamel.bouhara@bootlin.com \
--to=kamel.bouhara@bootlin.com \
--cc=JPEWhacker@gmail.com \
--cc=antonin.godard@bootlin.com \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=thomas.petazzoni@bootlin.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.