From patchwork Fri Apr 24 05:49:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11507131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A011814B4 for ; Fri, 24 Apr 2020 05:50:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 851CB20776 for ; Fri, 24 Apr 2020 05:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587707402; bh=nhxPzwWstza5Dv1YQUD5mM+6vfBRwgbdPXmTUb21+aA=; h=From:To:Cc:Subject:Date:List-ID:From; b=uSKCEglTEHck5stZ71iojkTrqGudpeMo9LAfxdlUYHgtcYf8dfkyXdShlTVfFmrq8 7N1tyzBwjfWd8ceaGYH8uKWzDvUDkolAkv5XMNf5dPrmERk/MQqKHgDqaiRRI1rRtO wsJ9SABEOC3xIOqWMo7l63ZVNg2yBtLIK69+qC58= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725769AbgDXFuC (ORCPT ); Fri, 24 Apr 2020 01:50:02 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:57904 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgDXFuB (ORCPT ); Fri, 24 Apr 2020 01:50:01 -0400 Received: from oscar.flets-west.jp (softbank126090202047.bbtec.net [126.90.202.47]) (authenticated) by conuserg-11.nifty.com with ESMTP id 03O5nYpZ003914; Fri, 24 Apr 2020 14:49:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com 03O5nYpZ003914 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1587707375; bh=6yprhtuJH0JAt/nBxuXAxrTcgJRW5wwX4SHpcjUSzvY=; h=From:To:Cc:Subject:Date:From; b=T7v+11aYsKt8WJBdz+nw9DIMku91mHdJZNOTBT1ZUAf07NfvNLEbhxtNDrd3zgzy/ mYt2+UMTf1OTOfMvYe+W0FrMzwR65xobk8yzm1ndwHe1dPepPTgYH8uV6QhajzWE2t 8WjLhu5OiWjgPhzW1T/jJhj8UQM3/rVvZldg8JbF0iPxXSH7l6vScNBOTjKZU6Sf++ 2aFPjilLdq1ZTrTDhc/KhmWKlVgNt7xqDMJF36gkqlIkxwf6idKbDpXGVKb5ZgpZBG gKJly+S4K0anq4Qq/FzJQCZX0UuHTNv6WZ70nH1AQrxW7J6zh4ihysazgr2sMJaSWT 9p925GXeuxxnw== X-Nifty-SrcIP: [126.90.202.47] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ulf Magnusson , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kconfig: tests: remove randconfig test for choice in choice Date: Fri, 24 Apr 2020 14:49:28 +0900 Message-Id: <20200424054929.502485-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Nesting choice statements does not make any sense. Commit df8df5e4bc37 ("usb: get rid of 'choice' for legacy gadget drivers") got rid of the only user. I will make it a syntax error. Remove the test in advance. Signed-off-by: Masahiro Yamada --- .../kconfig/tests/rand_nested_choice/Kconfig | 35 ------------------- .../tests/rand_nested_choice/__init__.py | 17 --------- .../tests/rand_nested_choice/expected_stdout0 | 2 -- .../tests/rand_nested_choice/expected_stdout1 | 4 --- .../tests/rand_nested_choice/expected_stdout2 | 5 --- 5 files changed, 63 deletions(-) delete mode 100644 scripts/kconfig/tests/rand_nested_choice/Kconfig delete mode 100644 scripts/kconfig/tests/rand_nested_choice/__init__.py delete mode 100644 scripts/kconfig/tests/rand_nested_choice/expected_stdout0 delete mode 100644 scripts/kconfig/tests/rand_nested_choice/expected_stdout1 delete mode 100644 scripts/kconfig/tests/rand_nested_choice/expected_stdout2 diff --git a/scripts/kconfig/tests/rand_nested_choice/Kconfig b/scripts/kconfig/tests/rand_nested_choice/Kconfig deleted file mode 100644 index 8350de7f732b..000000000000 --- a/scripts/kconfig/tests/rand_nested_choice/Kconfig +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -choice - prompt "choice" - -config A - bool "A" - -config B - bool "B" - -if B -choice - prompt "sub choice" - -config C - bool "C" - -config D - bool "D" - -if D -choice - prompt "subsub choice" - -config E - bool "E" - -endchoice -endif # D - -endchoice -endif # B - -endchoice diff --git a/scripts/kconfig/tests/rand_nested_choice/__init__.py b/scripts/kconfig/tests/rand_nested_choice/__init__.py deleted file mode 100644 index 9e4b2db53581..000000000000 --- a/scripts/kconfig/tests/rand_nested_choice/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -""" -Set random values recursively in nested choices. - -Kconfig can create a choice-in-choice structure by using 'if' statement. -randconfig should correctly set random choice values. - -Related Linux commit: 3b9a19e08960e5cdad5253998637653e592a3c29 -""" - - -def test(conf): - for i in range(20): - assert conf.randconfig() == 0 - assert (conf.config_contains('expected_stdout0') or - conf.config_contains('expected_stdout1') or - conf.config_contains('expected_stdout2')) diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 deleted file mode 100644 index 05450f3d4eb5..000000000000 --- a/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_A=y -# CONFIG_B is not set diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 deleted file mode 100644 index 37ab29584157..000000000000 --- a/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 +++ /dev/null @@ -1,4 +0,0 @@ -# CONFIG_A is not set -CONFIG_B=y -CONFIG_C=y -# CONFIG_D is not set diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 deleted file mode 100644 index 849ff47e9848..000000000000 --- a/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 +++ /dev/null @@ -1,5 +0,0 @@ -# CONFIG_A is not set -CONFIG_B=y -# CONFIG_C is not set -CONFIG_D=y -CONFIG_E=y From patchwork Fri Apr 24 05:49:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11507133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 461D7912 for ; Fri, 24 Apr 2020 05:50:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DF0420776 for ; Fri, 24 Apr 2020 05:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587707407; bh=LA1NnT5N/n+tshfSASRDN5MQHcTL1fL6TFxg8JbTf9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Y6vPwraS10EeSrRYv0RtfI+Nl52B+fGiLVPUzsGdWjFK4Bt9c0bDwzVu34mQpDjrs Rz+siKluC5+vS6r2UVYUahhA65QKtCnynDdQW3VCQ+nc6QDibAyRvkNWodoJ2jzugr vhcbnyraRMruNUKl4BgKwXul2O3svCrFW68QAVpM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726472AbgDXFuG (ORCPT ); Fri, 24 Apr 2020 01:50:06 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:58088 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgDXFuG (ORCPT ); Fri, 24 Apr 2020 01:50:06 -0400 Received: from oscar.flets-west.jp (softbank126090202047.bbtec.net [126.90.202.47]) (authenticated) by conuserg-11.nifty.com with ESMTP id 03O5nYpa003914; Fri, 24 Apr 2020 14:49:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com 03O5nYpa003914 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1587707375; bh=ly7ncAkOwNhudqWgq4kpvUp1J/j0jCzsqD3ZoL348ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SAvHAcEstDx8bpN+Crcf489pPo97faJQ/15vfJgbqdy4sD/kSRUDdpy8/IaijAsfc H8T8Vx/RXKduOrVKCoVFDCJQLZlfNKbt7VkTAxkCYcaUl2GKZt/DC1kVjMEiNZI3ce 6IuE6caDUrnuAglFmYAKhkeJ/m+CiF1xxDqz5dPfocHbsn9Ebl1cPYdzJPTLz2Zf1L XDNDjwnvHQ9gYeqq4h0waUu7jkAUhHeRHc4NUZ75XhMNGMYTD0Akz3aUgIkAfaKvtk UsF97tEJuRRnAJOBcNW1tY93jZyECpeJsB32jXLtszTOa71aX+vN9P+6jsBol5nfgQ H5I/dgCZUAhDQ== X-Nifty-SrcIP: [126.90.202.47] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ulf Magnusson , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kconfig: allow only 'config', 'comment', and 'if' statements inside choice Date: Fri, 24 Apr 2020 14:49:29 +0900 Message-Id: <20200424054929.502485-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200424054929.502485-1-masahiroy@kernel.org> References: <20200424054929.502485-1-masahiroy@kernel.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The statement block surrounded by 'if' ... 'endif' is reduced into if_stmt, which is accepted in the choice context. Therefore, you can do anything within a choice block by wrapping 'if y' ... 'end'. For example, you can create a menu inside a choice. [Test Code] ---------------->8---------------- choice prompt "choice" config A bool "A" config B bool "B" if y menu "strange menu" config C bool "C" endmenu endif endchoice ---------------->8---------------- I want to make such a weird structure a syntax error. In fact, the USB gadget Kconfig file used nested choice for no good reason until commit df8df5e4bc37 ("usb: get rid of 'choice' for legacy gadget drivers") killed it. I think the 'source' statement inside choice is on the fence. It is at least gramatically sensible as long as the included file contains only bool/tristate config statements. However, it makes the code unreadable, and in the end, people forget the fact that the file is included from the choice block. Commit 10e5e6c24963 ("usb: gadget: move choice ... endchoice to legacy/Kconfig") got rid of the only user. Going forward, you can only use 'config', 'comment', and 'if' inside choice blocks. This also recursively applies to 'if' blocks inside choice blocks. Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 708b6c4b13ca..190f1117f35a 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -119,20 +119,24 @@ mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL stmt_list: /* empty */ - | stmt_list common_stmt + | stmt_list assignment_stmt | stmt_list choice_stmt + | stmt_list comment_stmt + | stmt_list config_stmt + | stmt_list if_stmt | stmt_list menu_stmt + | stmt_list menuconfig_stmt + | stmt_list source_stmt | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); } | stmt_list error T_EOL { zconf_error("invalid statement"); } ; -common_stmt: - if_stmt - | comment_stmt - | config_stmt - | menuconfig_stmt - | source_stmt - | assignment_stmt +stmt_list_in_choice: + /* empty */ + | stmt_list_in_choice comment_stmt + | stmt_list_in_choice config_stmt + | stmt_list_in_choice if_stmt_in_choice + | stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); } ; /* config/menuconfig entry */ @@ -254,7 +258,7 @@ choice_end: end } }; -choice_stmt: choice_entry choice_block choice_end +choice_stmt: choice_entry stmt_list_in_choice choice_end ; choice_option_list: @@ -305,11 +309,6 @@ default: | T_DEF_BOOL { $$ = S_BOOLEAN; } | T_DEF_TRISTATE { $$ = S_TRISTATE; } -choice_block: - /* empty */ - | choice_block common_stmt -; - /* if entry */ if_entry: T_IF expr T_EOL @@ -331,6 +330,9 @@ if_end: end if_stmt: if_entry stmt_list if_end ; +if_stmt_in_choice: if_entry stmt_list_in_choice if_end +; + /* menu entry */ menu: T_MENU T_WORD_QUOTE T_EOL