Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1921616ybz; Thu, 23 Apr 2020 08:22:49 -0700 (PDT) X-Google-Smtp-Source: APiQypIku1yjd5+0tkajFOds/dUUJZLr/9j5ee6XCcsZq2ky8FnmzhTkBNz92ckxiwmlqDZREtBq X-Received: by 2002:a50:c28a:: with SMTP id o10mr3161958edf.85.1587655368957; Thu, 23 Apr 2020 08:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587655368; cv=none; d=google.com; s=arc-20160816; b=YQKosDWACFNeUY0FipJTCQ7paBwa3ffge5zPZKIWbiMeYDotQzzjpe7tz707JFIq7Q EkCQ5nu4uOCD/YydUArbwId/aiQ798UqbVHaa2vtGOlKcXJmQ8cK0s3bWSn7G2x7iKaM +UnnciH6ZkctEk6WOuY534tguPehKNgqKnVPC590X93KTrDbtKGBIK6s5KYE4ZPZMQmc 9txwGsGiqiDoJJTeJ75GNrklniUm83dfT2vERSZBMY7tYnCr9/KQNN8hbIQu8c8lYGXF PLHhjzVg9SaSVW4RRtFCFtbKRO+hqtzycbniD7sfNsrbzB5GctJGJjhzC4VIbnDWxCtG /IIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=ykhQ2hlbAZRh5FOblmpHkZAJ3N2BmFKMUz5RhT74fCk=; b=i5avpVn0Qz4OYUbmWs79hOD/BJQJddLNMihjZ0sMHJb2CJPk29u3TMsvwlG82lGZ55 1ZIVN1w1pO1v/gfmgiTk0LeUijuarlQZmQGHoxcLzpVUQJnybgnV44xMdCOIznCJfRXf 5R4lXUSQhHHXL5sgTrvC8Vn/OPrkC/LTRla7RHRMMyBwhoWhP+GR//9Jw6M8taTD9gLE zG43W24vbvvaDDQrUIezam3OXxs5Nrtw62b3RwMxs439xXpFngksqeGKXaICOp6LIb6B aC8gnsCIXOlQdqgts2SJIYDoevAmaBD6Iq2Dk3paHQEldZdX71c1TWqBwCrxqDoR16RN 9RKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=wUzFW2vL; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=tLDxNRjg; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si1264374edo.392.2020.04.23.08.22.22; Thu, 23 Apr 2020 08:22:48 -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; dkim=pass header.i=@pobox.com header.s=sasl header.b=wUzFW2vL; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=tLDxNRjg; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729117AbgDWPTX (ORCPT + 99 others); Thu, 23 Apr 2020 11:19:23 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:54994 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729014AbgDWPTW (ORCPT ); Thu, 23 Apr 2020 11:19:22 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id A8223C8475; Thu, 23 Apr 2020 11:19:20 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:mime-version:content-type; s=sasl; bh=vmQ JhYlZ0yHldJpYg27uGjUK04k=; b=wUzFW2vL0VC6xprf3iAhXRwWzESPCrPysPc eM1jp32i6MfUWwoTvdBhFUD4y0tPVNLfUC77jXvY+oqg/ZkY2aS73K3+I2rSvdqd uNnkG602PjCZpEPUno6zz8n8ee4dJPX1PhqhYNg0iIfhMZSVfKONU98BXpLHANAP vIJhShg4= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 9FDEEC8473; Thu, 23 Apr 2020 11:19:20 -0400 (EDT) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:message-id:mime-version:content-type; s=2016-12.pbsmtp; bh=ZQvOj/WbQX9wG6kaUe0GIpQk4CeGncvX7dWU4OJgYjU=; b=tLDxNRjgg156rpKhGo8X63HdaMXd9GGqa/nZFjcufcxAeOOxwzNxDBB/ZNOL5DCu77L2iz4dQUflMROVcHt+KcEFqIJnukY2lG7+gPzL7SVPiHUqxUxcdss5anYWxeajCNZihR+TTiUs7LrdONKZQel9GMtvYhw/nec9qEmFvgA= Received: from yoda.home (unknown [24.203.50.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 91729C8472; Thu, 23 Apr 2020 11:19:17 -0400 (EDT) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTPSA id C18342DA0CA0; Thu, 23 Apr 2020 11:19:15 -0400 (EDT) Date: Thu, 23 Apr 2020 11:19:15 -0400 (EDT) From: Nicolas Pitre To: Masahiro Yamada , linux-kbuild@vger.kernel.org cc: Randy Dunlap , Jani Nikula , Saeed Mahameed , Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH] kconfig: allow for conditional dependencies Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: CC7594EC-8575-11EA-B959-8D86F504CC47-78420484!pb-smtp21.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 + + 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()); };