Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2154156ybz; Thu, 23 Apr 2020 12:33:17 -0700 (PDT) X-Google-Smtp-Source: APiQypK1+L5XvNqYE/LHPfQDLNls9WGunOTR1RBhY+D8L7ugGbnndPSW/z6774GzyRJ0JkoUNRNV X-Received: by 2002:a17:906:fcaf:: with SMTP id qw15mr4019308ejb.236.1587670396849; Thu, 23 Apr 2020 12:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587670396; cv=none; d=google.com; s=arc-20160816; b=rvBnSaarGNtYjXsAVFTRTEkq78cwG4UuWNFB/pQJpZXqeKCRmbo3h7jYAQiIbSE9PM YulMJKwmwJ+9eGSTc2kjH2ReyVGb/vYlWqrzRMAhFzVuqUzDv7vDu7+Ae9dUDKLjMWuE TuXTnGyzP7fJ1Z9uVvYl8UUugWyF1YLjywhjJ7sP8E7On5/QOtcOySJwMTb+oj5Ibf// qISJOqQ1Sjm26U4la4yIJxDBCCvs5/95K/YbudL6+Zlp2BW3mJHQQFw52p1izediMGkA 7h7DbuSgAVw1RdqKsRRhYMY+3bveYpGZhwWyJ2b2AG9IYtDKnd4oy6QTXYpTasFCGwnA idWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=ZaASqBD2dhUDl1rl9yS3VghJaSPI2u3NizQ9VKxse0g=; b=IY3xKoes9fBPPiO+owBQPd6jPoWhlSX9z9JxlAnFoYMxanzwobYaFukAfG3pGiBBdJ xYKvKtk0rxaRYdEtyw3Qr4o4MFC7+006bR1My1891GkqAn7wJLpYGC/V3CuJnCNSbfc8 7xNYopDCwPptmFJO3E0gXpJ3vpfW5xEojdtRj8+FVGYRs4nU2hQpOCvellS0FF/WuS5X gWy28nn9+0kUUd2zHL+qjczCOMoRaT6jFuALKg8ThWkk1lVe8seylgvMz+3KLMbf8IBD 2mDzTlYAZeJH7l51KAs0evn9xg0pk/GtKGiHcSjDKSZsirti4v2Yh4M7veBi3w4k2Uxa 1Www== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si1790036edg.149.2020.04.23.12.32.52; Thu, 23 Apr 2020 12:33:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729396AbgDWPyB (ORCPT + 99 others); Thu, 23 Apr 2020 11:54:01 -0400 Received: from mga02.intel.com ([134.134.136.20]:37548 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729230AbgDWPyB (ORCPT ); Thu, 23 Apr 2020 11:54:01 -0400 IronPort-SDR: fOP0iJpaEX3hun+GVvdcKCXGNRHj5D5Z+YETTz8NM/q9eGnk2H4ugJz6fOwZtQDtmqpLGCpR8s c1r2BlmiVJGg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2020 08:53:54 -0700 IronPort-SDR: eZG7X9iakdPLqS/UaZMvcJzOaH5uigcdpJhP+hd+Xx9MT8K3fpduLXKitGkWciK+m9xeNc/rtN s7qQr4ku0g5Q== X-IronPort-AV: E=Sophos;i="5.73,307,1583222400"; d="scan'208";a="430370525" Received: from kgonza4-mobl1.amr.corp.intel.com (HELO localhost) ([10.252.33.241]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2020 08:53:51 -0700 From: Jani Nikula To: Nicolas Pitre , Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: Randy Dunlap , Saeed Mahameed , Arnd Bergmann , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kconfig: allow for conditional dependencies In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: Date: Thu, 23 Apr 2020 18:53:49 +0300 Message-ID: <87imhqb3le.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Apr 2020, Nicolas Pitre wrote: > This might appear to be a strange concept, but sometimes we want > a dependency to be conditionally applied. One such case is currently > expressed with: > > depends on FOO || !FOO > > This pattern is strange enough to give one's pause. Given that it is > also frequent, let's make the intent more obvious with some syntaxic > sugar by effectively making dependencies optionally conditional. > > This also makes the kconfig language more uniform. Thanks, I prefer this over all the previous proposals. Versatile yet self-explanatory. > Signed-off-by: Nicolas Pitre > > diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst > index d0111dd264..0f841e0037 100644 > --- a/Documentation/kbuild/kconfig-language.rst > +++ b/Documentation/kbuild/kconfig-language.rst > @@ -114,7 +114,7 @@ applicable everywhere (see syntax). > This is a shorthand notation for a type definition plus a value. > Optionally dependencies for this default value can be added with "if". > > -- dependencies: "depends on" > +- dependencies: "depends on" ["if" ] > > This defines a dependency for this menu entry. If multiple > dependencies are defined, they are connected with '&&'. Dependencies > @@ -130,6 +130,16 @@ applicable everywhere (see syntax). > bool "foo" > default y > > + The dependency definition itself may be conditional by appending "if" > + followed by an expression. If such expression is false (n) then this > + dependency is ignored. One possible use case is: > + > + config FOO > + tristate > + depends on BAZ if BAZ != n I presume this is the same as depends on BAZ if BAZ which makes me wonder if that should be the example. At least current usage for select is predominantly select FOO if BAR without "!= n". BR, Jani. > + > + meaning that FOO is constrained by the value of BAZ only when it is set. > + > - reverse dependencies: "select" ["if" ] > > While normal dependencies reduce the upper limit of a symbol (see > diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h > index d4ca829736..1a9337d1b9 100644 > --- a/scripts/kconfig/lkc.h > +++ b/scripts/kconfig/lkc.h > @@ -72,7 +72,7 @@ void menu_warn(struct menu *menu, const char *fmt, ...); > struct menu *menu_add_menu(void); > void menu_end_menu(void); > void menu_add_entry(struct symbol *sym); > -void menu_add_dep(struct expr *dep); > +void menu_add_dep(struct expr *dep, struct expr *cond); > void menu_add_visibility(struct expr *dep); > struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); > void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); > diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c > index e436ba44c9..47928cdbc2 100644 > --- a/scripts/kconfig/menu.c > +++ b/scripts/kconfig/menu.c > @@ -103,8 +103,18 @@ static struct expr *rewrite_m(struct expr *e) > return e; > } > > -void menu_add_dep(struct expr *dep) > +void menu_add_dep(struct expr *dep, struct expr *cond) > { > + if (cond) { > + /* > + * We have "depends on X if Y" and we want: > + * Y != n --> X > + * Y == n --> y > + * That simplifies to: (X || (Y == n)) > + */ > + dep = expr_alloc_or(dep, > + expr_trans_compare(cond, E_EQUAL, &symbol_no)); > + } > current_entry->dep = expr_alloc_and(current_entry->dep, dep); > } > > diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y > index 708b6c4b13..4161207da2 100644 > --- a/scripts/kconfig/parser.y > +++ b/scripts/kconfig/parser.y > @@ -316,7 +316,7 @@ if_entry: T_IF expr T_EOL > { > printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); > menu_add_entry(NULL); > - menu_add_dep($2); > + menu_add_dep($2, NULL); > $$ = menu_add_menu(); > }; > > @@ -412,9 +412,9 @@ help: help_start T_HELPTEXT > > /* depends option */ > > -depends: T_DEPENDS T_ON expr T_EOL > +depends: T_DEPENDS T_ON expr if_expr T_EOL > { > - menu_add_dep($3); > + menu_add_dep($3, $4); > printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); > }; > -- Jani Nikula, Intel Open Source Graphics Center