Skip to contentSkip to conversation

kconfig: 'if' and automatic submenu creation documentation

PATCH Superseded Ulf Magnusson 3 participants 9 messages Jan 14, 2018 – Jan 21, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover kconfig: 'if' and automatic submenu creation documentation

These together should make the automatic submenu logic a lot clearer.

Ulf Magnusson (2):
kconfig: Document 'if' flattening logic
kconfig: Improve auto. menu documentation accuracy

 scripts/kconfig/menu.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/2 kconfig: Document 'if' flattening logic

It is not obvious that this refers to an 'if', making the code pretty cryptic:

	if (menu->list && (!menu->prompt || !menu->prompt->text)) {

Kconfig keeps the 'if' menu nodes even after flattening. Reflect that in the example to be accurate.

No functional changes. Only comments added.

---
 scripts/kconfig/menu.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
scripts/kconfig/menu.c +24 -0
index 372eb5d9fef3..1f7bcceacde3 100644
@@ -524,6 +524,30 @@ void menu_finalize(struct menu *parent)
 			*ep = expr_alloc_one(E_LIST, NULL);
 			(*ep)->right.sym = menu->sym;
 		}
+
+		/*
+		 * Flatten 'if' blocks, which do not specify a submenu and only
+		 * add dependencies.
+		 *
+		 * (Automatic submenu creation might still create a submenu from
+		 * an 'if' before this code runs.)
+		 *
+		 * Before:
+		 *
+		 *	A
+		 *	if ...
+		 *	 +-B
+		 *	 +-C
+		 *	D
+		 *
+		 * After:
+		 *
+		 *	A
+		 *	if ...
+		 *	B
+		 *	C
+		 *	D
+		 */
 		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
 			for (last_menu = menu->list; ; last_menu = last_menu->next) {
 				last_menu->parent = parent;
Signature · 1 line
2.14.1
#2 lore raw

PATCH 1/2 kconfig: Document 'if' flattening logic

In reply to Ulf Magnusson

It is not obvious that this refers to an 'if', making the code pretty cryptic:

	if (menu->list && (!menu->prompt || !menu->prompt->text)) {

Kconfig keeps the 'if' menu nodes even after flattening. Reflect that in the example to be accurate.

No functional changes. Only comments added.

---
 scripts/kconfig/menu.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
scripts/kconfig/menu.c +24 -0
index 372eb5d9fef3..1f7bcceacde3 100644
@@ -524,6 +524,30 @@ void menu_finalize(struct menu *parent)
 			*ep = expr_alloc_one(E_LIST, NULL);
 			(*ep)->right.sym = menu->sym;
 		}
+
+		/*
+		 * Flatten 'if' blocks, which do not specify a submenu and only
+		 * add dependencies.
+		 *
+		 * (Automatic submenu creation might still create a submenu from
+		 * an 'if' before this code runs.)
+		 *
+		 * Before:
+		 *
+		 *	A
+		 *	if ...
+		 *	 +-B
+		 *	 +-C
+		 *	D
+		 *
+		 * After:
+		 *
+		 *	A
+		 *	if ...
+		 *	B
+		 *	C
+		 *	D
+		 */
 		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
 			for (last_menu = menu->list; ; last_menu = last_menu->next) {
 				last_menu->parent = parent;
Signature · 1 line
2.14.1
#3 lore raw

PATCH 2/2 kconfig: Improve auto. menu documentation accuracy

An 'if', 'menu', or 'choice' that depends on a preceding symbol will also generate a submenu.

No functional changes. Only comments updated.

---
 scripts/kconfig/menu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/kconfig/menu.c +5 -4
index 1f7bcceacde3..86031dc36f7d 100644
@@ -414,9 +414,10 @@ void menu_finalize(struct menu *parent)
 			menu_finalize(menu);
 	} else if (sym) {
 		/*
-		 * Automatic submenu creation. If sym, A, B, C, ..., are
-		 * consecutive symbols and A, B, C, ... all depend on sym, the
-		 * following menu structure will be created:
+		 * Automatic submenu creation. If sym is a symbol and A, B, C,
+		 * ... are consecutive items (symbols, menus, ifs, etc.) that
+		 * all depend on sym, then the following menu structure is
+		 * created:
 		 *
 		 *	sym
 		 *	 +-A
@@ -425,7 +426,7 @@ void menu_finalize(struct menu *parent)
 		 *	 ...
 		 *
 		 * This also works recursively, giving the following structure
-		 * if B depends on A:
+		 * if A is a symbol and B depends on A:
 		 *
 		 *	sym
 		 *	 +-A
Signature · 1 line
2.14.1
#4 lore raw

Re: [PATCH 2/2] kconfig: Improve auto. menu documentation accuracy

2018-01-14 20:38 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 40 lines

An 'if', 'menu', or 'choice' that depends on a preceding symbol will also generate a submenu.

No functional changes. Only comments updated.

---
 scripts/kconfig/menu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/kconfig/menu.c +5 -5
index 1f7bcceacde3..86031dc36f7d 100644
@@ -414,9 +414,10 @@ void menu_finalize(struct menu *parent)
                        menu_finalize(menu);
        } else if (sym) {
                /*
-                * Automatic submenu creation. If sym, A, B, C, ..., are
-                * consecutive symbols and A, B, C, ... all depend on sym, the
-                * following menu structure will be created:
+                * Automatic submenu creation. If sym is a symbol and A, B, C,
+                * ... are consecutive items (symbols, menus, ifs, etc.) that
+                * all depend on sym, then the following menu structure is
+                * created:
                 *
                 *      sym
                 *       +-A
@@ -425,7 +426,7 @@ void menu_finalize(struct menu *parent)
                 *       ...
                 *
                 * This also works recursively, giving the following structure
-                * if B depends on A:
+                * if A is a symbol and B depends on A:
                 *
                 *      sym
                 *       +-A
--

2.14.1

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

I squashed this into the previous patch:
https://patchwork.kernel.org/patch/9991939/

Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada
#5 lore raw

PATCH v2 1/2 kconfig: Document 'if' flattening logic

In reply to Ulf Magnusson

It is not obvious that this might refer to an 'if', making the code pretty cryptic:

	if (menu->list && (!menu->prompt || !menu->prompt->text)) {

Kconfig keeps the 'if' menu nodes even after flattening. Reflect that in the example to be accurate.

No functional changes. Only comments added.

---
Changelog

v2:
I forgot to mention that this code also undoes automatic submenus created below promptless symbols.

 scripts/kconfig/menu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
scripts/kconfig/menu.c +29 -0
index 53964d911708..a8af08aabfd6 100644
@@ -531,6 +531,35 @@ void menu_finalize(struct menu *parent)
 			*ep = expr_alloc_one(E_LIST, NULL);
 			(*ep)->right.sym = menu->sym;
 		}
+
+		/*
+		 * This code serves two purposes:
+		 *
+		 * (1) Flattening 'if' blocks, which do not specify a submenu
+		 *     and only add dependencies.
+		 *
+		 *     (Automatic submenu creation might still create a submenu
+		 *     from an 'if' before this code runs.)
+		 *
+		 * (2) "Undoing" any automatic submenus created earlier below
+		 *     promptless symbols.
+		 *
+		 * Before:
+		 *
+		 *	A
+		 *	if ... (or promptless symbol)
+		 *	 +-B
+		 *	 +-C
+		 *	D
+		 *
+		 * After:
+		 *
+		 *	A
+		 *	if ... (or promptless symbol)
+		 *	B
+		 *	C
+		 *	D
+		 */
 		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
 			for (last_menu = menu->list; ; last_menu = last_menu->next) {
 				last_menu->parent = parent;
Signature · 1 line
2.14.1
#6 lore raw

Re: [PATCH v2 1/2] kconfig: Document 'if' flattening logic

2018-01-14 23:49 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 14 lines

It is not obvious that this might refer to an 'if', making the code pretty cryptic:

        if (menu->list && (!menu->prompt || !menu->prompt->text)) {

Kconfig keeps the 'if' menu nodes even after flattening. Reflect that in the example to be accurate.

No functional changes. Only comments added.

---
Changelog

Quoted 7 lines

v2:
I forgot to mention that this code also undoes automatic submenus created below promptless symbols.

 scripts/kconfig/menu.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Applied to linux-kbuild/kconfig. Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw
In reply to Ulf Magnusson

Hi Ulf.

Quoted 8 lines · Ulf Magnusson

These together should make the automatic submenu logic a lot clearer.

Ulf Magnusson (2):
kconfig: Document 'if' flattening logic
kconfig: Improve auto. menu documentation accuracy

 scripts/kconfig/menu.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

Very good with extra comments in menu_finalize. If you can mamage to explain the logic related to select then even better.

While on the subject on improving readability, then menu_finalize would benefit from a split in a number of well named and well documented helper functions.

It would be great if you could try this out.

Sam

#8 lore raw
Quoted 9 lines · Sam Ravnborg

Hi Ulf.

Quoted 6 lines · Ulf Magnusson

These together should make the automatic submenu logic a lot clearer.

Ulf Magnusson (2):
kconfig: Document 'if' flattening logic
kconfig: Improve auto. menu documentation accuracy

Quoted 6 lines
Quoted 2 lines
 scripts/kconfig/menu.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

Very good with extra comments in menu_finalize. If you can mamage to explain the logic related to select then even better.

I added a short comment in
https://patchwork.kernel.org/patch/9986947/, which is already in linux-next:

    /*
    * Handle selects and implies, which modify the
    * dependencies of the selected/implied symbol
    */
    if (prop->type == P_SELECT) {
    ...

There's also https://patchwork.kernel.org/patch/9983881/:

    /* Reverse dependencies through being selected by other symbols */
    struct expr_value rev_dep;

I guess it could be made more explicit. I don't want to heap on too many patches at once though.

Quoted 6 lines

While on the subject on improving readability, then menu_finalize would benefit from a split in a number of well named and well documented helper functions.

It would be great if you could try this out.

I had a stab at it earlier, but never got done. I think the high-level structure in Kconfiglib should work:
https://github.com/ulfalizer/Kconfiglib/blob/master/kconfiglib.py#L3990

Hopefully I'll get back to it later once the current batch of patches has been merged. I'm just happy to have to have less mystery code in there for now. Definitely one of the more opaque parts of Kconfig.

Cheers,
Ulf