Skip to contentSkip to conversation

kconfig: Fix menu/endmenu markers in zconfdump()

PATCH Superseded Eugeniu Rosca 1 participant 2 messages Jul 10, 2016 – Jul 31, 2016

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

PATCH 1/1 kconfig: Fix menu/endmenu markers in zconfdump()

Given a Kconfig.sample, implementing 2 empty and 2 non-empty menu entries:

menu EMPTY_MENU
endmenu

menu NONEMPTY_MENU
config DUMMY_1

    bool "desc-1"

endmenu

menuconfig EMPTY_MENUCONFIG

    bool "desc-2"

menuconfig NONEMPTY_MENUCONFIG

    bool "desc-3"

if NONEMPTY_MENUCONFIG
config DUMMY_2

    bool "desc-4"

endif

The following can be observed (prerequisite: uncomment zconfdump() in scripts/kconfig/conf.c):

Quoted 4 lines

make KBUILD_KCONFIG=Kconfig.sample allnoconfig | grep -cw menu 4
make KBUILD_KCONFIG=Kconfig.sample allnoconfig | grep -cw endmenu 3

It looks like zconfdump() has the following inconsistencies:
A. It prints the start marker 'menu' both for empty and non-empty menu
entries, while printing the end marker 'endmenu' only for non-empty menu entries.
B. At the end of every dump, it prints the end marker of the root
menu, while skipping its start marker, so that even if (A) is fixed, the number of start and end markers is still not equal.

Fix (A) and (B).

---
 scripts/kconfig/zconf.tab.c_shipped | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/kconfig/zconf.tab.c_shipped +5 -1
index 7a4d658..727b7dd 100644
@@ -2510,6 +2510,8 @@ static void print_symbol(FILE *out, struct menu *menu)
 			fputs( "  menu ", out);
 			print_quoted_string(out, prop->text);
 			fputc('\n', out);
+			if (!menu->list)
+				fputs("endmenu\n", out);
 			break;
 		default:
 			fprintf(out, "  unknown prop %d!\n", prop->type);
@@ -2530,7 +2532,7 @@ void zconfdump(FILE *out)
 	struct symbol *sym;
 	struct menu *menu;
 
-	menu = rootmenu.list;
+	menu = &rootmenu;
 	while (menu) {
 		if ((sym = menu->sym))
 			print_symbol(out, menu);
@@ -2545,6 +2547,8 @@ void zconfdump(FILE *out)
 				fputs("\nmenu ", out);
 				print_quoted_string(out, prop->text);
 				fputs("\n", out);
+				if (!menu->list)
+					fputs("endmenu\n", out);
 				break;
 			default:
 				;
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 kconfig: Fix menu/endmenu markers in zconfdump()

From 4af7b7801e2d7dffd8f943b03415659e42766610 Mon Sep 17 00:00:00 2001
From: Eugeniu Rosca <[email protected]>
Date: Sun, 10 Jul 2016 10:03:53 +0200
Subject: [PATCH v2] kconfig: Fix menu/endmenu markers in zconfdump()

Given a Kconfig.sample, implementing 2 empty and 2 non-empty menu entries:

menu EMPTY_MENU
endmenu

menu NONEMPTY_MENU
config C1

    prompt "C1"

endmenu

menuconfig EMPTY_MENUCONFIG

    prompt "M1"

menuconfig NONEMPTY_MENUCONFIG

    prompt "M2"

if NONEMPTY_MENUCONFIG
config C2

    prompt "C2"

endif

The following can be observed (prerequisite: uncomment zconfdump() in scripts/kconfig/conf.c):

$ make KBUILD_KCONFIG=Kconfig.sample allnoconfig | grep -cw menu
$ 4
$ make KBUILD_KCONFIG=Kconfig.sample allnoconfig | grep -cw endmenu
$ 3

It looks like zconfdump() has the following inconsistencies:
A. It prints the start marker 'menu' both for empty and non-empty menu
entries, while printing the end marker 'endmenu' only for non-empty menu entries.
B. At the end of every dump, it prints the end marker of the root
menu, while skipping its start marker, so that even if (A) is fixed, the number of start and end markers is still not equal.

Fix (A) and (B).

---

This is the second attempt to correct one of the zconfdump misbehaviors regarding "menu" and "endmenu" markers. Without this patch, it is practically impossible to import the kconfig symbol database into some 3rd party program or script, as the 3rd party tool would rely on the menu/endmenu keywords to identify the borders between menu entries. With wrong information about menu borders, no correct connection can be established between config symbols and their parent menu entries.

Changes from v1:
- Made sure "endmenu" is printed at the end of all menu properties.

 scripts/kconfig/zconf.tab.c_shipped | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
scripts/kconfig/zconf.tab.c_shipped +9 -1
index 7a4d658..c77a20a 100644
@@ -2446,6 +2446,7 @@ static void print_symbol(FILE *out, struct menu *menu)
 {
 	struct symbol *sym = menu->sym;
 	struct property *prop;
+	bool empty_menuconfig = false;
 
 	if (sym_is_choice(sym))
 		fprintf(out, "\nchoice\n");
@@ -2510,6 +2511,8 @@ static void print_symbol(FILE *out, struct menu *menu)
 			fputs( "  menu ", out);
 			print_quoted_string(out, prop->text);
 			fputc('\n', out);
+			if (!menu->list)
+				empty_menuconfig = true;
 			break;
 		default:
 			fprintf(out, "  unknown prop %d!\n", prop->type);
@@ -2522,6 +2525,9 @@ static void print_symbol(FILE *out, struct menu *menu)
 			menu->help[len] = 0;
 		fprintf(out, "  help\n%s\n", menu->help);
 	}
+	if (empty_menuconfig)
+		fputs("\nendmenu\n", out);
+
 }
 
 void zconfdump(FILE *out)
@@ -2530,7 +2536,7 @@ void zconfdump(FILE *out)
 	struct symbol *sym;
 	struct menu *menu;
 
-	menu = rootmenu.list;
+	menu = &rootmenu;
 	while (menu) {
 		if ((sym = menu->sym))
 			print_symbol(out, menu);
@@ -2554,6 +2560,8 @@ void zconfdump(FILE *out)
 				expr_fprint(prop->visible.expr, out);
 				fputc('\n', out);
 			}
+			if ((prop->type == P_MENU) && !menu->list)
+				fputs("endmenu\n", out);
 		}
 
 		if (menu->list)
Signature · 1 line
2.9.2