Received: by 2002:a17:90a:c08a:0:0:0:0 with SMTP id o10csp4081333pjs; Mon, 9 Dec 2019 00:20:06 -0800 (PST) X-Google-Smtp-Source: APXvYqzJkxDs+ptm8yOavO+kUt4RVMq1nh2EU4Kn/QNwnzzkZErZMaiNN4WIwhZ38Ufeuk8a0QPV X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr21060906otr.128.1575879606427; Mon, 09 Dec 2019 00:20:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575879606; cv=none; d=google.com; s=arc-20160816; b=dcVmNDTRecGWk15tm+PjdqaZS4XsrRb/p/jq5Il+Vp0BMasUzFAN2lwz9UAX6WyUyK rZAp02K+EBb/NcnqMxIroeytwJMwo9BG2rdlzMxBr1v/GEKNjQWMQl4Ao7au3N9qIMa/ F5nRJk84wSIyAxvi/w6XL/pbmRIKUNrwVm/lCGULcQYkto13OjCzc7fThFTwJitx9UKt ElilGcKLlVAx8vV1Uk//Dks7ZFz7jTEc24L1mc7SBlwaEcE/M1FwKk9jlgMjlEDGvUwb df3zOm4x8HwCR9m4XIVLO4t9M2Qw0u3bcyupcFlXPzJVWuAMzapq+4TJQocazEdZPm5u eVdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jbpRGF95ZNnelw7MpvbO5/+qdOTsvxhQeZ2np0qSQ5Y=; b=oMDoJjse7vMJmvDhqT1Ki2Nk0mInCifngOilm1V9SopjBvq+5MwsQ7uc5Bpj+IcOcG K2I86895KJv3zmoBr5c1bBio+J0HQfgFHigB3NOCH0t9aLkmxvjbbthaEtsh/u22vkYm OgcU3FrszxGsNkXGf+fei+YiAYHoCrUUphHaE6cnhQcohpe5lxXGGicRDzpemhjWohM+ kWf+ATq6AB34Qf5GHt8kQIDtzLMBa4O8Xzp6zSTHCP/TY9u1B7jm4/CKGCvqN1c6pi1S Sq4HI1Ow3mXIfT7gsf8oiXieoKG1WeK1e2+qBCvMikftTWS63G6EQbBoyP+qXb+cLYHZ 4Reg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FlmtG5xK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x24si12597890otk.188.2019.12.09.00.19.54; Mon, 09 Dec 2019 00:20:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FlmtG5xK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfLIIT2 (ORCPT + 99 others); Mon, 9 Dec 2019 03:19:28 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:32924 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbfLIIT1 (ORCPT ); Mon, 9 Dec 2019 03:19:27 -0500 Received: by mail-pj1-f65.google.com with SMTP id r67so5551565pjb.0; Mon, 09 Dec 2019 00:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jbpRGF95ZNnelw7MpvbO5/+qdOTsvxhQeZ2np0qSQ5Y=; b=FlmtG5xKIB++/JaurZkU3J/C0+hF0iE6Pw/uZd/aZmCOXnMzMG94FETriFTeKS5RLm b3p1tIJhK/fvU8xI7/9ujaVkFjLqe39A5wqwsx6VQ50sD7QqkWDmy1Kr+PcIRBRGaS3C enuD8C/97wk0u3WZzWkKVZvk6k02RoHPq1lpqQqxbDw2SOM7IQz5KMvuSrW7bDcw4GMr BtjToNVnxNA5doLZ6tc9HGc94VrV62BkAMRGVgc9tAaN1LLj+lAO0eRT9RbiqfjCOiLf Fbyi11EbSvNUGK/nBVn8wBbjnsA+v8rrNhIAwwKVRcjBCQIekQGjEgv3JSIzHMPFGYKv noYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jbpRGF95ZNnelw7MpvbO5/+qdOTsvxhQeZ2np0qSQ5Y=; b=ThTwIAGxBgk7ak6eI9RZz9hYRuCytiWnPReNcy4dlqd1EHniF3gNc+K3s+aszZNVWz vQetVWKqu2PpIbpTKKU11Q8hexrEGgRtkfS2+J49Xs7+xgaaH27IFFBLBKoSG4eLtLU6 Fd71j+L+oYLpfBSz/MpXI/l+HY4KRdIsd0qOq63cE0q662NTfb73by6cqdmVDpl6d2LN vfbJaHSkOOMihpExrVjmXSewh813jmZmebga81/Mp5It8bIXNQrZC+GkogSE2gP6f4O7 kbsBIheVV1oZWr6fje2h3lhMzJxUoMAYO4lqujqn6zQ3kQaTeiZ448394p7UnX15Yxlr HB0w== X-Gm-Message-State: APjAAAVuMnKqGj0dwWpWtgw3wEsp26LWFRkgLblW3hTqsceMM6N4BrGf JyvjwzjO+P6R0nqBFV8V8oriG5/Ny2ckGA== X-Received: by 2002:a17:902:8504:: with SMTP id bj4mr27729232plb.171.1575879565721; Mon, 09 Dec 2019 00:19:25 -0800 (PST) Received: from glados.lan ([2601:647:4c01:6541:fa16:54ff:fed1:1bd6]) by smtp.gmail.com with ESMTPSA id u2sm23810375pgc.19.2019.12.09.00.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 00:19:25 -0800 (PST) From: Thomas Hebb To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Cc: Thomas Hebb , Masahiro Yamada , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org (open list:SIFIVE DRIVERS) Subject: [PATCH 1/4] kconfig: list all definitions of a symbol in help text Date: Mon, 9 Dec 2019 00:19:16 -0800 Message-Id: <1eaa4143fdb000563cde114bb7e0166b1fc229bf.1575879069.git.tommyhebb@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In Kconfig, each symbol (representing a config option) can be defined in multiple places. Each definition may or may not have a prompt, which allows the option to be set via an interface like menuconfig. Each definition has a set of dependencies, which determine whether its prompt is visible and whether other pieces of the definition, like a default value, take effect. Historically, a symbol's help text (i.e. what's shown when a user presses '?' in menuconfig) contained some symbol-wide information not tied to any particular definition (e.g. what other symbols it selects) as well as the location (file name and line number) and dependencies of each prompt. Notably, the help text did not show the location or dependencies of definitions without prompts. Because this made it hard to reason about symbols that had no prompts, bcdedcc1afd6 ("menuconfig: print more info for symbol without prompts") changed the help text so that, instead of containing the location and dependencies of each prompt, it contained the location and dependencies of the symbol's first definition, regardless of whether or not that definition had a prompt. For symbols with only one definition, that change makes sense. However, it breaks down for symbols with multiple definitions: each definition has its own set of dependencies (the `dep` field of `struct menu`), and those dependencies are ORed together to get the symbol's dependency list (the `dir_dep` field of `struct symbol`). By printing only the dependencies of the first definition, the help text misleads users into believing that an option is more narrowly-applicable than it actually is. For an extreme example of this, we can look at the SYS_TEXT_BASE symbol in the Das U-Boot project, which also uses Kconfig. (I could not find an illustrative example in the Linux source, unfortunately). This config option specifies the load address of the built binary and, as such, is applicable to basically every configuration possible. And yet, without this patch, its help text is as follows: Symbol: SYS_TEXT_BASE [=0x00200000] Type : hex Prompt: Text Base Location: -> Boot images Defined at arch/arm/mach-aspeed/Kconfig:9 Depends on: ARM [=y] && ARCH_ASPEED [=n] The help text indicates that the option only applicable for a specific unselected architecture (aspeed), because that architecture's promptless definition (which just sets a default value), happens to be the first one seen. Because source locations and dependencies are fundamentally properties of definitions and not of symbols, we should treat them as such. This patch brings back the pre-bcdedcc1afd6 behavior for definitions with prompts but also separately prints the location and dependencies of those without prompts, solving the original problem in a different way. With this change, our SYS_TEXT_BASE example becomes Symbol: SYS_TEXT_BASE [=0x00200000] Type : hex Defined with prompt at Kconfig:548 Prompt: Text Base Depends on: !NIOS2 [=n] && !XTENSA [=n] && !EFI_APP [=n] Location: -> Boot images Defined without prompt at arch/arm/mach-aspeed/Kconfig:9 Depends on: ARM [=y] && ARCH_ASPEED [=n] Defined without prompt at arch/arm/mach-socfpga/Kconfig:28 Depends on: ARM [=y] && ARCH_SOCFPGA [=n] Defined without prompt at board/sifive/fu540/Kconfig:15 Depends on: RISCV [=n] && TARGET_SIFIVE_FU540 [=n] which is a much more accurate representation. Signed-off-by: Thomas Hebb --- scripts/kconfig/menu.c | 49 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index d9d16469859a..59fead4b8823 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -698,6 +698,15 @@ const char *menu_get_help(struct menu *menu) return ""; } +static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) +{ + if (!expr_is_yes(expr)) { + str_append(r, prefix); + expr_gstr_print(expr, r); + str_append(r, "\n"); + } +} + static void get_prompt_str(struct gstr *r, struct property *prop, struct list_head *head) { @@ -705,7 +714,11 @@ static void get_prompt_str(struct gstr *r, struct property *prop, struct menu *submenu[8], *menu, *location = NULL; struct jump_key *jump = NULL; - str_printf(r, "Prompt: %s\n", prop->text); + str_printf(r, "Defined with prompt at %s:%d\n", + prop->menu->file->name, prop->menu->lineno); + str_printf(r, " Prompt: %s\n", prop->text); + + get_dep_str(r, prop->visible.expr, " Depends on: "); menu = prop->menu->parent; for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); @@ -755,18 +768,6 @@ static void get_prompt_str(struct gstr *r, struct property *prop, } } -/* - * get property of type P_SYMBOL - */ -static struct property *get_symbol_prop(struct symbol *sym) -{ - struct property *prop = NULL; - - for_all_properties(sym, prop, P_SYMBOL) - break; - return prop; -} - static void get_symbol_props_str(struct gstr *r, struct symbol *sym, enum prop_type tok, const char *prefix) { @@ -806,17 +807,17 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } } } - for_all_prompts(sym, prop) - get_prompt_str(r, prop, head); - - prop = get_symbol_prop(sym); - if (prop) { - str_printf(r, " Defined at %s:%d\n", prop->menu->file->name, - prop->menu->lineno); - if (!expr_is_yes(prop->visible.expr)) { - str_append(r, " Depends on: "); - expr_gstr_print(prop->visible.expr, r); - str_append(r, "\n"); + + /* Print the definitions with prompts before the ones without */ + for_all_properties(sym, prop, P_SYMBOL) + if (prop->menu->prompt) + get_prompt_str(r, prop->menu->prompt, head); + + for_all_properties(sym, prop, P_SYMBOL) { + if (!prop->menu->prompt) { + str_printf(r, "Defined without prompt at %s:%d\n", + prop->menu->file->name, prop->menu->lineno); + get_dep_str(r, prop->menu->dep, " Depends on: "); } } -- 2.24.0