From patchwork Mon Sep 14 19:05:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 7178031 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2CC7A9F314 for ; Mon, 14 Sep 2015 19:06:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 237E92053E for ; Mon, 14 Sep 2015 19:06:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00D9D2053C for ; Mon, 14 Sep 2015 19:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752118AbbINTGK (ORCPT ); Mon, 14 Sep 2015 15:06:10 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:35084 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751576AbbINTGJ (ORCPT ); Mon, 14 Sep 2015 15:06:09 -0400 Received: by wicge5 with SMTP id ge5so155721108wic.0 for ; Mon, 14 Sep 2015 12:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sPFjKhBuFdhUNVRiMUSb82pemjyk77vGhWa1HvuOdps=; b=aXwj2sFVJxPPnHfdagiv+0xr+HXcLOprjs35Ys0n38AbGILRLr8TVEV/AjY8IeZxaw ffrNuPxaYmThpIFYRXC68ZWagEEKFViHiiIrBJ9i//AANDEVZxAh813Rkw56qC6dHA4x rJ3lcKqc0gB6Y8ZqzL15Pla4y3MaoYDHm7/kdoxQt287O1PPn5WfZf2s1q2vvdfB0VKG J4GcMJSGoq5fvjYeiq3Zi6MXCX/h6rSXqdKIeJoLJJtG3/pUmbuX6CITmEImi2MWRq24 H4EC0HhPR00D7IlwdM9i8IlbFJ3ZeDsbH3YdpnsAgCAfLXOcTAqM4LgkFmyaEYDCW+eM H3Dw== X-Received: by 10.180.109.67 with SMTP id hq3mr28773327wib.40.1442257568601; Mon, 14 Sep 2015 12:06:08 -0700 (PDT) Received: from t61.jablocom.intra ([85.119.94.121]) by smtp.gmail.com with ESMTPSA id pg5sm17028173wjb.21.2015.09.14.12.06.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Sep 2015 12:06:07 -0700 (PDT) From: Petr Vorel To: linux-kbuild@vger.kernel.org Cc: Paul Bolle , Randy Dunlap , Petr Vorel Subject: [PATCH 1/1] [RFC] kconfig: menuconfig make "Selected by:" readable Date: Mon, 14 Sep 2015 21:05:43 +0200 Message-Id: <1442257543-6194-2-git-send-email-petr.vorel@gmail.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1442257543-6194-1-git-send-email-petr.vorel@gmail.com> References: <1442257543-6194-1-git-send-email-petr.vorel@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Bolle rev_dep expressions can get rather unwieldy, especially if a symbol is selected by more than a handful of other symbols. Ie, it's possible to have near endless expressions like: A && B && !C || D || F && (G || H) || [...] Chop these expressions into actually readable chunks: - A && B && !C - D - F && (G || H) - [...] Ie, transform the top level "||" tokens into newlines and prepend each line with a minus. This makes the "Selected by:" blurb much easier to read. --- Today I found myself wondering why a certain Kconfig was selected. Currently menuconfig's help is of no use in complicated cases. Please look at the help of USB or CRYPTO to see what I mean. This is a _hack_ to show what might be a better way to do this. It parses a stringified version of the reverse dependency, and not the actual reverse dependecy expression. But that was easier to cobble together. One cool improvement would be to change to minus in front of the subexpressions to Y or M for those that actually set the symbol. Anyhow, other suggestions and feedback is welcome. Not-yet-signed-off-by: Paul Bolle Tested-by: Petr Vorel Cc: Paul Bolle Cc: Randy Dunlap Cc: Petr Vorel --- scripts/kconfig/menu.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b05cc3d..a8b37a2 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -613,6 +613,86 @@ static struct property *get_symbol_prop(struct symbol *sym) } /* + * Assuming we're just past an opening parenthesis in a NUL terminated string, + * find it's closing parenthesis and return its postion. Die otherwise. + */ +static const char *matching_paren(const char *s) +{ + int lvl = 1; + + while (1) { + if (*s == '(') + lvl++; + else if (*s == ')') + lvl--; + if (lvl == 0) + break; + if (*s == '\0') + /* huh? */ + exit(1); + s++; + } + + return s; +} + +/* + * rev_dep expressions can get rather unwieldy, especially if a symbol is + * selected by more than a handful of other symbols. Ie, it's possible to + * have near endless expressions like: + * A && B && !C || D || F && (G || H) || [...] + * + * Chop these expressions into actually readable chunks: + * - A && B && !C + * - D + * - F && (G || H) + * - [...] + * + * Ie, transform the top level "||" tokens into newlines and prepend each line + * with a minus. This makes the "Selected by:" blurb much easier to read. + */ +static void rev_dep_gstr_print(struct expr *e, struct gstr *gs) +{ + struct gstr tmp = str_new(); + const char *prev, *start; + char *beam; + + expr_gstr_print(e, &tmp); + prev = start = str_get(&tmp); + + str_append(gs, "\n - "); + + while ((beam = index(start, '|'))) { + char *lparen = index(start, '('); + + /* don't split "(I || J)" */ + if (lparen && (lparen < beam)) { + const char *rparen = matching_paren(++lparen); + + /* skip the expression inside parentheses */ + start = ++rparen; + continue; + } + + /* we can assume we're fed a sane string, so the space before + * the beam gets turned into a NUL */ + *(beam - 1) = '\0'; + str_append(gs, prev); + str_append(gs, "\n - "); + /* assume sane string, so skip the second beam */ + beam++; + /* trim */ + while (*++beam == ' ') + ; + prev = start = beam; + } + + str_append(gs, prev); + + str_free(&tmp); +} + +/* * head is optional and may be NULL */ static void get_symbol_str(struct gstr *r, struct symbol *sym, @@ -661,8 +741,7 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, str_append(r, "\n"); if (sym->rev_dep.expr) { str_append(r, _(" Selected by: ")); - expr_gstr_print(sym->rev_dep.expr, r); - str_append(r, "\n"); + rev_dep_gstr_print(sym->rev_dep.expr, r); } str_append(r, "\n\n"); }