From patchwork Fri Oct 21 03:24:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 9387963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E84860762 for ; Fri, 21 Oct 2016 03:24:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C86B29DA4 for ; Fri, 21 Oct 2016 03:24:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F41E29DA5; Fri, 21 Oct 2016 03:24:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FCAF29DA2 for ; Fri, 21 Oct 2016 03:24:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754025AbcJUDYF (ORCPT ); Thu, 20 Oct 2016 23:24:05 -0400 Received: from mail-qk0-f180.google.com ([209.85.220.180]:32981 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbcJUDYE (ORCPT ); Thu, 20 Oct 2016 23:24:04 -0400 Received: by mail-qk0-f180.google.com with SMTP id n189so128772636qke.0 for ; Thu, 20 Oct 2016 20:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=7IK2Fn3fZmHOffVCg/Y65nPP0/BB5eAqTQ+GnaBwMs0=; b=VuHd4ckwAvLLWCoVbVseFy4Z+QgmsiGrzDE01Wv6Do0rfNNCviItt1UOdiH7VzP4jJ /iqOZomMm1FTFweVJVujaSHRI8KpwdXeBjxGd93Uz5sZ0zwzZMQSzk4GwpipHnIw7mRC vrr6GeOLrcvW+Y3KyFPPn0nu/fjceikenInPY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=7IK2Fn3fZmHOffVCg/Y65nPP0/BB5eAqTQ+GnaBwMs0=; b=QJlHCoz46rz+axCZP7F/4CncmGLtXOIepBE8XXQLnHUEJl0mu7YikGP2P6iVcPXwUU SLv0/eU/uUEogcyCd29r+fGWLB+dk5Ym4Dgc/t25Md5toHX0abp3O/pU6/8gAeOaW47f bc7tzm1MXyun7X7s9PpaNubSZjw4QcoSEVsu5bl3RDaOEh5rzshF9gAMxxE/hlhYhRrc kPZHcT5xrjAwkX4tg1UChjgWjqvkSWaGKMHX084rjDqtxFYWdmey9Par8YcR73j+yQSK IiYDgB1Xw9jVDAF18B9+whBwIxw4NVbrhjkPiI2WIj+zZ1ryw4C1CqTtrQC7QZ3ogCdH 4XaA== X-Gm-Message-State: ABUngvdY7+Se/7T/NdbbKSN8bnPNhCxkSGy6Ud98Rbe0x/JIbay/N84qZTRMGQepEYw1AL2a X-Received: by 10.55.148.3 with SMTP id w3mr3390601qkd.248.1477020242864; Thu, 20 Oct 2016 20:24:02 -0700 (PDT) Received: from xanadu.home ([2607:fa48:6e39:d410:feaa:14ff:fea7:ed77]) by smtp.gmail.com with ESMTPSA id v41sm306473qta.29.2016.10.20.20.24.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 20:24:02 -0700 (PDT) Date: Thu, 20 Oct 2016 23:24:01 -0400 (EDT) From: Nicolas Pitre To: Edward Cree cc: John Stultz , Richard Cochran , Yann E MORIN , Thomas Gleixner , Josh Triplett , netdev@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] kconfig: introduce the "imply" keyword In-Reply-To: Message-ID: References: <1476920573-14384-1-git-send-email-nicolas.pitre@linaro.org> <1476920573-14384-2-git-send-email-nicolas.pitre@linaro.org> <44f95579-6c35-7592-08e3-d8dbb13026b2@solarflare.com> <3c91236f-6795-fdcc-c8a2-6e7b2fd7da66@solarflare.com> User-Agent: Alpine 2.20 (LFD 67 2015-01-07) MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 20 Oct 2016, Nicolas Pitre wrote: > On Thu, 20 Oct 2016, Edward Cree wrote: > > > I'm interpreting "imply" as being more a way of saying "if you want FOO you > > probably want BAZ as well". But maybe that should be yet another new > > keyword if it's so different from what you want "imply" to be. "suggests", > > perhaps. > > Indeed. That's exactly the keyword that came to my mind after I sent my > previous reply. So what about the following on top of my previous series: From: Nicolas Pitre Date: Thu, 20 Oct 2016 23:04:46 -0400 Subject: [PATCH] kconfig: introduce the "suggest" keyword Similar to "imply" but with no added value restrictions on the target symbol. Useful for providing a default value to another symbol. Signed-off-by: Nicolas Pitre --- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index 5ee0dd3c85..b7f4f0ca1d 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt @@ -140,6 +140,12 @@ applicable everywhere (see syntax). ability to hook into a given subsystem while still being able to configure that subsystem out and keep those drivers selected. +- even weaker reverse dependencies: "suggest" ["if" ] + This is similar to "imply" except that this doesn't add any restrictions + on the value the suggested symbol may use. In other words this only + provides a default for the specified symbol based on the value for the + config entry where this is used. + - limiting menu display: "visible if" This attribute is only applicable to menu blocks, if the condition is false, the menu block is not displayed to the user (the symbols diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index a73f762c48..eea3aa3c7a 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -86,6 +86,7 @@ struct symbol { struct expr_value dir_dep; struct expr_value rev_dep; struct expr_value implied; + struct expr_value suggested; }; #define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER) @@ -138,6 +139,7 @@ enum prop_type { P_CHOICE, /* choice value */ P_SELECT, /* select BAR */ P_IMPLY, /* imply BAR */ + P_SUGGEST, /* suggest BAR */ P_RANGE, /* range 7..100 (for a symbol) */ P_ENV, /* value from environment variable */ P_SYMBOL, /* where a symbol is defined */ diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index e9357931b4..3abc5c85ac 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -255,7 +255,9 @@ static void sym_check_prop(struct symbol *sym) break; case P_SELECT: case P_IMPLY: - use = prop->type == P_SELECT ? "select" : "imply"; + case P_SUGGEST: + use = prop->type == P_SELECT ? "select" : + prop->type == P_IMPLY ? "imply" : "suggest"; sym2 = prop_get_symbol(prop); if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE) prop_warn(prop, @@ -341,6 +343,10 @@ void menu_finalize(struct menu *parent) struct symbol *es = prop_get_symbol(prop); es->implied.expr = expr_alloc_or(es->implied.expr, expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); + } else if (prop->type == P_SUGGEST) { + struct symbol *es = prop_get_symbol(prop); + es->suggested.expr = expr_alloc_or(es->suggested.expr, + expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); } } } @@ -687,6 +693,13 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, str_append(r, "\n"); } + get_symbol_props_str(r, sym, P_SUGGEST, _(" Suggests: ")); + if (sym->suggested.expr) { + str_append(r, _(" Suggested by: ")); + expr_gstr_print(sym->suggested.expr, r); + str_append(r, "\n"); + } + str_append(r, "\n\n"); } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 074fb66d9a..235f11e3f9 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -267,6 +267,16 @@ static void sym_calc_visibility(struct symbol *sym) sym->implied.tri = tri; sym_set_changed(sym); } + tri = no; + if (sym->suggested.expr) + tri = expr_calc_value(sym->suggested.expr); + tri = EXPR_AND(tri, sym->visible); + if (tri == mod && sym_get_type(sym) == S_BOOLEAN) + tri = yes; + if (sym->suggested.tri != tri) { + sym->suggested.tri = tri; + sym_set_changed(sym); + } } /* @@ -406,6 +416,10 @@ void sym_calc_value(struct symbol *sym) newval.tri = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri); } + if (sym->suggested.tri != no) { + sym->flags |= SYMBOL_WRITE; + newval.tri = EXPR_OR(newval.tri, sym->suggested.tri); + } if (sym->dir_dep.tri != no && sym->implied.tri != no) { /* implied symbols have implied defaults */ @@ -768,7 +782,9 @@ const char *sym_get_string_default(struct symbol *sym) if (sym->type == S_BOOLEAN && val == mod) val = yes; - /* adjust the default value if this symbol is implied by another */ + /* adjust the default value if this symbol is suggested/implied */ + if (val < sym->suggested.tri) + val = sym->suggested.tri; if (val < sym->implied.tri) val = sym->implied.tri; @@ -1376,6 +1392,8 @@ const char *prop_get_type_name(enum prop_type type) return "select"; case P_IMPLY: return "imply"; + case P_SUGGEST: + return "suggest"; case P_RANGE: return "range"; case P_SYMBOL: diff --git a/scripts/kconfig/zconf.gperf b/scripts/kconfig/zconf.gperf index ead02edec9..0c244a8e95 100644 --- a/scripts/kconfig/zconf.gperf +++ b/scripts/kconfig/zconf.gperf @@ -39,6 +39,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX string, T_TYPE, TF_COMMAND, S_STRING select, T_SELECT, TF_COMMAND imply, T_IMPLY, TF_COMMAND +suggest, T_SUGGEST, TF_COMMAND range, T_RANGE, TF_COMMAND visible, T_VISIBLE, TF_COMMAND option, T_OPTION, TF_COMMAND diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 001305fa08..277415540a 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -31,7 +31,7 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE]; static struct menu *current_menu, *current_entry; %} -%expect 32 +%expect 34 %union { @@ -63,6 +63,7 @@ static struct menu *current_menu, *current_entry; %token T_DEFAULT %token T_SELECT %token T_IMPLY +%token T_SUGGEST %token T_RANGE %token T_VISIBLE %token T_OPTION @@ -125,7 +126,7 @@ stmt_list: ; option_name: - T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE + T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_SUGGEST | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE ; common_stmt: @@ -223,6 +224,12 @@ config_option: T_IMPLY T_WORD if_expr T_EOL printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno()); }; +config_option: T_SUGGEST T_WORD if_expr T_EOL +{ + menu_add_symbol(P_SUGGEST, sym_lookup($2, 0), $3); + printd(DEBUG_PARSE, "%s:%d:suggest\n", zconf_curname(), zconf_lineno()); +}; + config_option: T_RANGE symbol symbol if_expr T_EOL { menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); @@ -676,6 +683,11 @@ static void print_symbol(FILE *out, struct menu *menu) expr_fprint(prop->expr, out); fputc('\n', out); break; + case P_SUGGEST: + fputs( " suggest ", out); + expr_fprint(prop->expr, out); + fputc('\n', out); + break; case P_RANGE: fputs( " range ", out); expr_fprint(prop->expr, out);