From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailgw01.zimbra-vnc.de (mailgw01.zimbra-vnc.de [148.251.101.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7BE73DA7C9; Fri, 10 Apr 2026 21:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.101.236 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775856714; cv=none; b=b5jXZsCVa/1pNklnioR5yGeaGW2FtTFlrEDFAxAFJXikdea8H7CH27j3sRoJcnIQrzeIIyQn366lO3QvHGUPDQtQM3diHmgocfC0/OisVZybBDq6VoytlUKfBeB1Epil79hXc7FL2x0IggOplGApjgXClmRLY5HdhbwIvTFYEos= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775856714; c=relaxed/simple; bh=U6eBdrFYfqZd2K299ZfqMAgesEAOqlWfIx3f0RYwrXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NmPHo8En10Eyv/zOGQ5FFBrJ3ONLUprcPjh3z1GC2Oh4HN9FrmNn4w6sE875lH3aymsVWsl4scLKY1Q+zIT5o3G4mU0dIBCXeWWeCSFnjRkcgQWbmSA61Li3LWGZEjCfcJbTIWRKVj8d5bS9OLv1tNaZqBIS99eTZnKAV52INjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tngtech.com; spf=pass smtp.mailfrom=tngtech.com; dkim=pass (2048-bit key) header.d=tngtech.com header.i=@tngtech.com header.b=bAqmmN7R; arc=none smtp.client-ip=148.251.101.236 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tngtech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tngtech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tngtech.com header.i=@tngtech.com header.b="bAqmmN7R" Received: from zmproxy.tng.vnc.biz (zimbra-vnc.tngtech.com [35.234.71.156]) by mailgw01.zimbra-vnc.de (Postfix) with ESMTPS id F0E8E3FAF0; Fri, 10 Apr 2026 23:23:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zmproxy.tng.vnc.biz (Postfix) with ESMTP id C18661F89B3; Fri, 10 Apr 2026 23:23:32 +0200 (CEST) Received: from zmproxy.tng.vnc.biz ([127.0.0.1]) by localhost (zmproxy.tng.vnc.biz [127.0.0.1]) (amavis, port 10032) with ESMTP id 9rixxFyU1Rvx; Fri, 10 Apr 2026 23:23:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zmproxy.tng.vnc.biz (Postfix) with ESMTP id 1AB251FAA6D; Fri, 10 Apr 2026 23:23:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zmproxy.tng.vnc.biz 1AB251FAA6D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tngtech.com; s=B14491C6-869D-11EB-BB6C-8DD33D883B31; t=1775856212; bh=ejNKFDQ7nGjhznwzaTa7ZqAhyjz2bzoAnSJezf6S4pg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bAqmmN7R0mGamyIDRKt2TdJywpM4xnVA2KZqXCXgynQh2KuezRZQP+J49PxSSPnvq NFlHV0oDic/l77x3tM/RJKgwOn8M1nGH43FmbwI4IqUOt7CtQxOsDcS8dHSJ/zT68A RWGoUGJ1gmgutCIL8sY+xgTzlyDuUjfUEOx1AUeNx790WUpenwXlJYn05VY/gAhXyI cgqnxdHrwauHhd9SQGaJQ8mrjbCmjydEWKU+5FxOu5TFLhmlEUPfBsfA85Pp25dXyW YOdcgeNjBRH2uJgGiTXP/MX9rrGD/9EQ+auKk5gI1Sm5IhkoYxSX1mg0EjyHUqj9/d tnvdtnrfRkGig== X-Virus-Scanned: amavis at zmproxy.tng.vnc.biz Received: from zmproxy.tng.vnc.biz ([127.0.0.1]) by localhost (zmproxy.tng.vnc.biz [127.0.0.1]) (amavis, port 10026) with ESMTP id rzYuBkj-gSui; Fri, 10 Apr 2026 23:23:32 +0200 (CEST) Received: from luis-Precision-5480.. (ipservice-092-209-239-167.092.209.pools.vodafone-ip.de [92.209.239.167]) by zmproxy.tng.vnc.biz (Postfix) with ESMTPSA id B92631FA89E; Fri, 10 Apr 2026 23:23:31 +0200 (CEST) From: Luis To: nathan@kernel.org, nsc@kernel.org Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, gregkh@linuxfoundation.org, kstewart@linuxfoundation.org, maximilian.huber@tngtech.com, Luis Augenstein Subject: [PATCH v5 03/15] scripts/sbom: setup sbom logging Date: Fri, 10 Apr 2026 23:22:43 +0200 Message-ID: <20260410212255.9883-4-luis.augenstein@tngtech.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260410212255.9883-1-luis.augenstein@tngtech.com> References: <20260410212255.9883-1-luis.augenstein@tngtech.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Luis Augenstein Add logging infrastructure for warnings and errors. Errors and warnings are accumulated and summarized in the end. Assisted-by: Cursor:claude-sonnet-4-5 Assisted-by: OpenCode:GLM-4-7 Co-developed-by: Maximilian Huber Signed-off-by: Maximilian Huber Signed-off-by: Luis Augenstein --- scripts/sbom/sbom.py | 24 ++++++++- scripts/sbom/sbom/__init__.py | 0 scripts/sbom/sbom/config.py | 47 +++++++++++++++++ scripts/sbom/sbom/sbom_logging.py | 88 +++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 scripts/sbom/sbom/__init__.py create mode 100644 scripts/sbom/sbom/config.py create mode 100644 scripts/sbom/sbom/sbom_logging.py diff --git a/scripts/sbom/sbom.py b/scripts/sbom/sbom.py index 9c2e4c7f17c..c7f23d6eb30 100644 --- a/scripts/sbom/sbom.py +++ b/scripts/sbom/sbom.py @@ -6,9 +6,31 @@ Compute software bill of materials in SPDX format describing a kernel bu= ild. """ =20 +import logging +import sys +import sbom.sbom_logging as sbom_logging +from sbom.config import get_config + =20 def main(): - pass + # Read config + config =3D get_config() + + # Configure logging + logging.basicConfig( + level=3Dlogging.DEBUG if config.debug else logging.INFO, + format=3D"[%(levelname)s] %(message)s", + ) + + # Report collected warnings and errors in case of failure + warning_summary =3D sbom_logging.summarize_warnings() + error_summary =3D sbom_logging.summarize_errors() + + if warning_summary: + logging.warning(warning_summary) + if error_summary: + logging.error(error_summary) + sys.exit(1) =20 =20 # Call main method diff --git a/scripts/sbom/sbom/__init__.py b/scripts/sbom/sbom/__init__.p= y new file mode 100644 index 00000000000..e69de29bb2d diff --git a/scripts/sbom/sbom/config.py b/scripts/sbom/sbom/config.py new file mode 100644 index 00000000000..3dc569ae0c4 --- /dev/null +++ b/scripts/sbom/sbom/config.py @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: GPL-2.0-only OR MIT +# Copyright (C) 2025 TNG Technology Consulting GmbH + +import argparse +from dataclasses import dataclass + + +@dataclass +class KernelSbomConfig: + debug: bool + """Whether to enable debug logging.""" + + +def _parse_cli_arguments() -> dict[str, bool]: + """ + Parse command-line arguments using argparse. + + Returns: + Dictionary of parsed arguments. + """ + parser =3D argparse.ArgumentParser( + description=3D"Generate SPDX SBOM documents for kernel builds", + ) + parser.add_argument( + "--debug", + action=3D"store_true", + default=3DFalse, + help=3D"Enable debug logs (default: False)", + ) + + args =3D vars(parser.parse_args()) + return args + + +def get_config() -> KernelSbomConfig: + """ + Parse command-line arguments and construct the configuration object. + + Returns: + KernelSbomConfig: Configuration object with all settings for SBO= M generation. + """ + # Parse cli arguments + args =3D _parse_cli_arguments() + + debug =3D args["debug"] + + return KernelSbomConfig(debug=3Ddebug) diff --git a/scripts/sbom/sbom/sbom_logging.py b/scripts/sbom/sbom/sbom_l= ogging.py new file mode 100644 index 00000000000..3460c4d8462 --- /dev/null +++ b/scripts/sbom/sbom/sbom_logging.py @@ -0,0 +1,88 @@ +# SPDX-License-Identifier: GPL-2.0-only OR MIT +# Copyright (C) 2025 TNG Technology Consulting GmbH + +import logging +import inspect +from typing import Any, Literal + + +class MessageLogger: + """Logger that prints the first occurrence of each message immediate= ly + and keeps track of repeated messages for a final summary.""" + + messages: dict[str, list[str]] + repeated_logs_limit: int + """Maximum number of repeated messages of the same type to log befor= e suppressing further output.""" + + def __init__(self, level: Literal["error", "warning"], repeated_logs= _limit: int =3D 3) -> None: + self._level =3D level + self.messages =3D {} + self.repeated_logs_limit =3D repeated_logs_limit + + def log(self, template: str, /, **kwargs: Any) -> None: + """Log a message based on a template and optional variables.""" + message =3D template.format(**kwargs) + if template not in self.messages: + self.messages[template] =3D [] + if len(self.messages[template]) < self.repeated_logs_limit: + if self._level =3D=3D "error": + logging.error(message) + elif self._level =3D=3D "warning": + logging.warning(message) + self.messages[template].append(message) + + def get_summary(self) -> str: + """Return summary of collected messages.""" + if len(self.messages) =3D=3D 0: + return "" + summary: list[str] =3D [f"Summarize {self._level}s:"] + for msgs in self.messages.values(): + for i, msg in enumerate(msgs): + if i < self.repeated_logs_limit: + summary.append(msg) + continue + summary.append( + f"... (Found {len(msgs) - i} more {'instances' if (l= en(msgs) - i) !=3D 1 else 'instance'} of this {self._level})" + ) + break + return "\n".join(summary) + + +_warning_logger: MessageLogger +_error_logger: MessageLogger + + +def warning(msg_template: str, /, **kwargs: Any) -> None: + """Log a warning message.""" + _warning_logger.log(msg_template, **kwargs) + + +def error(msg_template: str, /, **kwargs: Any) -> None: + """Log an error message including file, line, and function context."= "" + frame =3D inspect.currentframe() + caller_frame =3D frame.f_back if frame else None + info =3D inspect.getframeinfo(caller_frame) if caller_frame else Non= e + if info: + msg_template =3D f'File "{info.filename}", line {info.lineno}, i= n {info.function}\n{msg_template}' + _error_logger.log(msg_template, **kwargs) + + +def summarize_warnings() -> str: + return _warning_logger.get_summary() + + +def summarize_errors() -> str: + return _error_logger.get_summary() + + +def has_errors() -> bool: + return len(_error_logger.messages) > 0 + + +def init() -> None: + global _warning_logger, _error_logger + _warning_logger =3D MessageLogger("warning") + _error_logger =3D MessageLogger("error") + + +init() --=20 2.43.0