From patchwork Tue Apr 7 12:26:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2152 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=1775564841; bh=WWvqbUiEjaAJeDVynKI84GP+KgialskbGPwRewwIqvY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=wh7zY9ROW6J2ia7aHSuZPkDTw/2WJT/uIVeeArWWrzz/ZdBZNd5QcavU22EcBa/HG ptbYTiXg/sHK8P4z+o3Oz4k8ugAORV+gwUlPqpNJK3Dka1wVy3xx7S1DQT8IRJ5mp6 tLmB3wdzSy3VrgJZcdSVyA3p0QdclYQJcSHsZaU2d3VKvIXCC1uzbGffZ9DT4jT2x2 H/zn2f540OJOIAtXIqctq294NpAo+YLaobdurbbyJLYwbr7D1cPw18MeeL/fQpRyOw CeWY7a+bd36XjNet7UlhFPpIlPpLJ1oeyZi+6xA4G9JzSJjyg/hARD3xFs0VXu/rPm GQXjRHBaKojXQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 87BB06A39B for ; Tue, 7 Apr 2026 06:27:21 -0600 (MDT) 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 EbvnNpouXItS for ; Tue, 7 Apr 2026 06:27:21 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775564840; bh=WWvqbUiEjaAJeDVynKI84GP+KgialskbGPwRewwIqvY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=rNs/uX0xW0q+lFNuhgfDt2Ywsnjxu4wT3TMmG0gsOCDJ6ZW3hdpsX2dhXwDh41Hkg ZA+J1YCjxv0IZD0gIyKvHl7kjGBbq81iqSaBPlaYp4sSjCDA/HhZA3tWK/7tfF0Znq 18ZJQi5kGV5btFzBZMaDQGXGsjlTKMioqMwT4ES23iHvUiVc05wcWsrAfh5d3IM5yu yiUZAIAgViGBDtoUcFonsMLNbYFM855yYj65luzWJWXJ/uSp4o1j30STvJFuLafhqz oTKoabd/EYhmATyAQdO6CjE6i4B053tGYrn2aWxCVCx3nMG5FfqCxkOZPlhqJ9xRaS tW+9o8b8kWfFw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3FE0F6A39E for ; Tue, 7 Apr 2026 06:27:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775564838; bh=J8U8OEA1RAq3CmlW4XC8R/7K3yri1fvx0og615zyu8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HeffMdIFeOKBIkboE8i8TqM2iNJGqHHG2rDO17uAtDgpfIRmMnPYLjLH+fhLuDW1E 6og5VJv5eaw7BjL5ptpCxrHmlGcSvWeZUcpXMUSuwiSrQeNcuKwelxr6USILKGitfW b6743SBXFS7YJej0wsOHkoyFQxV/3DDEF1aIDdeEn4eG9t6G7PMq1eLsQWFT5wB0pL 8/eX2mClx0Eo8qZPpWIwyL/Wdf7FlxjNsI2hTb3/NjeL50A17Ksh+JSELvbc/5yESy fNiErPY5Paf43iuFTDApaxvJnkjXHbPm5nH3liAtSFxjdWc4V2z2pfI3FuwlzKGuAc MIkQeUuqdPPVA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5D34C6A39B; Tue, 7 Apr 2026 06:27:18 -0600 (MDT) 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 OgbrQjr_esOh; Tue, 7 Apr 2026 06:27:18 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775564838; bh=NMmEVoT9XXuo4GwJauiyshDLTUhhnP9y0Xwg+GVHzos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sLWOo1rHildf6s1MzP9zdiPtoLcmTVA/Gj/zF9xIZ/hNMdmwMYtNxVOEW3Mq37OcI fu46wz++Q7pcsZ2m4xNoetDhaTwevX/i8bU2zeqrGkzlfMbRG/vvd/WKTFFH8sw0zS dV0+cpa5b3pzkB93TrvorHE29o2314bsP18pq+jWYpH+hbtFxu9vCA8+4yutogsFHY YWstZRCXdtuHvTbwt1wi0Y53r19jzZbJ8HSOfz76LGBGSJa25OjzwJ5cYck4v+BDMR Wu+zzA1LC2bkZLjW1C+72kkCPZ8OdwM3oUxcMRYVUTkwmoVOlGfdmiZaD3FR04Z0sw eEudm4qICV8Ww== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C960C6A386; Tue, 7 Apr 2026 06:27:17 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Apr 2026 06:26:48 -0600 Message-ID: <20260407122656.3462730-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260407122656.3462730-1-sjg@u-boot.org> References: <20260407122656.3462730-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: AFRHTOQ4T5R43YVK2N4ZODGZWHRMGCAW X-Message-ID-Hash: AFRHTOQ4T5R43YVK2N4ZODGZWHRMGCAW 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 1/4] qconfig: Add helper functions for #include defconfig sync 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 three helper functions in preparation for fixing the #include defconfig sync: - _get_defconfig_entries(): parses a preprocessed defconfig to get a dict of config entries by name, for textual comparison against include file content - _build_include_defconfig(): assembles defconfig content from include lines and an overlay delta - _format_sym_value(): formats a kconfiglib symbol's current value as a defconfig line, handling bool/tristate/string/int/hex types No functional change. Signed-off-by: Simon Glass --- tools/qconfig.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tools/qconfig.py b/tools/qconfig.py index 86b2bed9283..8976b863dab 100755 --- a/tools/qconfig.py +++ b/tools/qconfig.py @@ -423,6 +423,43 @@ def _get_min_config_lines(kconf, fname): return lines +def _config_name(line): + """Extract config name (e.g. 'CONFIG_ARM') from a defconfig line + + Args: + line (str): A defconfig line + + Returns: + str or None: The config name, or None if not a config line + """ + stripped = line.strip() + if stripped.startswith('CONFIG_'): + return stripped.split('=', 1)[0] + if stripped.startswith('# CONFIG_'): + return stripped.split()[1] + return None + + +def _get_defconfig_entries(fname): + """Parse a preprocessed defconfig file to get config entries by name + + Args: + fname (str): Path to the preprocessed defconfig file + + Returns: + dict: Mapping of config name (e.g. 'CONFIG_ARM') to the full line + including the value (e.g. 'CONFIG_ARM=y') + """ + entries = {} + with open(fname, encoding='utf-8') as inf: + for line in inf: + line = line.strip() + name = _config_name(line) + if name: + entries[name] = line + return entries + + def _sync_plain_defconfig(kconf, orig, dry_run): """Sync a plain defconfig (no #include) @@ -450,6 +487,53 @@ def _sync_plain_defconfig(kconf, orig, dry_run): return updated +def _build_include_defconfig(include_lines, delta, sep): + """Build defconfig content from include lines and overlay delta + + Assembles a defconfig that uses #include directives by concatenating + the original #include lines with the overlay delta (the CONFIG lines + that are needed on top of what the includes provide). The separator + preserves the blank-line convention from the original file. + + Args: + include_lines (list of bytes): The #include lines + delta (list of str): Sorted overlay config lines + sep (bytes): Separator between includes and delta (b'\\n' or b'') + + Returns: + bytes: The defconfig content + """ + out = b'' + for line in include_lines: + out += line + if delta: + out += sep + for line in delta: + out += line.encode() if isinstance(line, str) else line + return out + + +def _format_sym_value(sym, value=None): + """Format a symbol value as a defconfig line + + Args: + sym (kconfiglib.Symbol): The symbol + value (str or None): Value to format; uses sym.str_value if None + + Returns: + str: The defconfig line + """ + if value is None: + value = sym.str_value + if sym.orig_type in (kconfiglib.BOOL, kconfiglib.TRISTATE): + if value == 'n': + return f'# CONFIG_{sym.name} is not set' + return f'CONFIG_{sym.name}={value}' + if sym.orig_type == kconfiglib.STRING: + return f'CONFIG_{sym.name}="{kconfiglib.escape(value)}"' + return f'CONFIG_{sym.name}={value}' + + def _sync_include_defconfig(kconf, srcdir, orig, dry_run): """Sync a defconfig that uses #include directives