From patchwork Mon Nov 24 13:49:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 53 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992196; bh=f79mHCuYgvzjk0PQwk89c7MZPGHSSUk2yiVZ5JGntQc=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=YgYqMz7E7oFZG93GXMH7CS8PtirGKm1oSvbFNwBGYTeZphIVsYF8gYZj+9r8+zPHB siFbPmQGiOs9MpWPtGG4pSsZDZhoZmSJNmbRPXF2udIYeU/5HnkN3Y6Em48VTGt7xT gVsumF2a6TDZoT7nz1gm9JtF7xj+wI66Tt73dCstsi8cfLT3yn7ZBss1sQ1E4YKi3T lOBM7jvGUhAoIi1SUb+1CBedkcBNh2aNB0rQ2MIoMX7N9XhDCwTBhQ7pj69neVPMJW ZGXI1p7DQm40ZkK1sJNKRESFcLtsw0gue7bCvFG0WBOsOc96toggjHRGD5ZeZKBTU2 w5w8MzsBwlQmQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC98A68752 for ; Mon, 24 Nov 2025 06:49:56 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id g_8oKuxOpLin for ; Mon, 24 Nov 2025 06:49:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992196; bh=f79mHCuYgvzjk0PQwk89c7MZPGHSSUk2yiVZ5JGntQc=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=YgYqMz7E7oFZG93GXMH7CS8PtirGKm1oSvbFNwBGYTeZphIVsYF8gYZj+9r8+zPHB siFbPmQGiOs9MpWPtGG4pSsZDZhoZmSJNmbRPXF2udIYeU/5HnkN3Y6Em48VTGt7xT gVsumF2a6TDZoT7nz1gm9JtF7xj+wI66Tt73dCstsi8cfLT3yn7ZBss1sQ1E4YKi3T lOBM7jvGUhAoIi1SUb+1CBedkcBNh2aNB0rQ2MIoMX7N9XhDCwTBhQ7pj69neVPMJW ZGXI1p7DQm40ZkK1sJNKRESFcLtsw0gue7bCvFG0WBOsOc96toggjHRGD5ZeZKBTU2 w5w8MzsBwlQmQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B7CBE68669 for ; Mon, 24 Nov 2025 06:49:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992195; bh=VLfVfUGR/AryGy6oT8ObXyufUxD9HdOWw/Ay/VQhgR8=; h=From:To:Cc:Subject:Date:From; b=gtM21KA5Yh1/9qK+rx6VMRUJC+3Q+Q+BHlrAug3ykLQW8gprwsxVbix/aBybXUiUe 7IlBuEOBc+xHqgWNA2MCyssGjGq8wtb3McfdKS0EgAIAwp5hpkvbVgY1CnkZkjEaTR xwiDutSp5Dvq1+B4+CK8qRkxc78YJKCQXBHWECb3ZgvQ9fZMBUhLJ/OR4vuTqwAfWh 6WXEIQ7FkK+CMP8z9fDXbv6iA84bT8Nzyk22OF986mNTcHzap9fvrQt1daLG12lhay qU2tgDc0q+CpJ7kSqy1CW4MjSyM2SqG5Z2bXCOS1lyI6DWhZdFab783MFQCRqu6+Cx iFwzxtFwhO1fg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 87A7968669; Mon, 24 Nov 2025 06:49:55 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id kBG8fkuIQ5he; Mon, 24 Nov 2025 06:49:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992191; bh=gsy6hE/LG+J3eMyAd+ellrpoBOResVNaduvyzc5/btQ=; h=From:To:Cc:Subject:Date:From; b=E9z5GGTJ7snJ5UlXwxCsbeKE3JVXMfwNEuGYfiLt0BqroRa7lGRMLOgPvN9IOXD1D BLMpku22qU6HtGKTGitPswCyHoBOthQE29W2WE/utpJUljo0qrNrdbrgMB1HiJCWWF yT15x3LSfRa0kwew7L1ct/pVmHlIfVV3xiGjsBQcTzkk+5DVRwNV60cl78qD7siXAW zmipqNYmvlvw/SQ2nkAugCd2F0DcCy3FPMyNvSUAYNFxrYNuGNpn1CtVL3jAFsC+Xb y5cOCqVL9lcE/0tvRVMBee61+QhMryiNBnRwf3Ro2m59i6/6ssrcVNV6Qg98zw0AaA cxv1ofnZPaS+w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 04FEF68688; Mon, 24 Nov 2025 06:49:50 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 24 Nov 2025 06:49:11 -0700 Message-ID: <20251124134932.1991031-1-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Message-ID-Hash: 4L452ABJISZJBQBVK7B4KBDEJWTC5MZN X-Message-ID-Hash: 4L452ABJISZJBQBVK7B4KBDEJWTC5MZN X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 0/9] codman: Add a new source-code analysis tool List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a new tool called 'codman' (code manager) for analysing source code usage in U-Boot builds. This tool determines which files and lines of code are actually compiled based on the build configuration. The tool provides three analysis methods: - unifdef: Static preprocessor analysis (default) - DWARF: Debug information from compiled code (-w) - (experimental) LSP: Language server analysis using clangd (-l) Codman supports: - File-level analysis: which files are compiled vs unused - Line-level analysis: which lines are active vs removed by preprocessor - Kconfig-impact analysis with -a/--adjust option - Various output formats: stats, directories, detail, summary Since there is quite a lot of processing involved, Codman uses parallel processing where possible. This tool is admittedly not quite up to my normal code quality, but it has been an interesting experiment in using Claude to create something from scratch. The unifdef part of the tool benefits from some patches I created for that tool: - O(1) algorithm for symbol lookup, instead of O(n) - faster! - support for IS_ENABLED(), CONFIG_IS_ENABLED() Please get in touch if you would like the patches. This series also includes a minor improvement to buildman and a tidy-up of the tout library to reduce code duplication. Simon Glass (9): u_boot_pylib: Add stderr parameter to tprint() u_boot_pylib: Use terminal.tprint() for output in tout buildman: Support comma-separated values in -a flag codman: Add a new source-code analysis tool codman: Provide an unifdef analyser codman: Provide an dwarf analyser codman: Begin an experimental lsp analyser codman: Add some basic tests codman: Add documentation doc/develop/codman.rst | 1 + doc/develop/index.rst | 1 + tools/buildman/buildman.rst | 13 + tools/buildman/cfgutil.py | 19 +- tools/buildman/cmdline.py | 3 +- tools/buildman/test.py | 12 + tools/codman/analyser.py | 76 ++++ tools/codman/codman | 1 + tools/codman/codman.py | 664 +++++++++++++++++++++++++++++++++ tools/codman/codman.rst | 426 +++++++++++++++++++++ tools/codman/dwarf.py | 200 ++++++++++ tools/codman/lsp.py | 319 ++++++++++++++++ tools/codman/lsp_client.py | 225 +++++++++++ tools/codman/output.py | 536 ++++++++++++++++++++++++++ tools/codman/test_codman.py | 470 +++++++++++++++++++++++ tools/codman/test_lsp.py | 153 ++++++++ tools/codman/unifdef.py | 429 +++++++++++++++++++++ tools/u_boot_pylib/terminal.py | 10 +- tools/u_boot_pylib/tout.py | 24 +- 19 files changed, 3554 insertions(+), 28 deletions(-) create mode 120000 doc/develop/codman.rst create mode 100644 tools/codman/analyser.py create mode 120000 tools/codman/codman create mode 100755 tools/codman/codman.py create mode 100644 tools/codman/codman.rst create mode 100644 tools/codman/dwarf.py create mode 100644 tools/codman/lsp.py create mode 100644 tools/codman/lsp_client.py create mode 100644 tools/codman/output.py create mode 100755 tools/codman/test_codman.py create mode 100755 tools/codman/test_lsp.py create mode 100644 tools/codman/unifdef.py