Skip to content

Commit 86e187f

Browse files
lacombarMauro Carvalho Chehab
authored andcommitted
kconfig: add an option to determine a menu's visibility
This option is aimed to add the possibility to control a menu's visibility without adding dependency to the expression to all the submenu. Signed-off-by: Arnaud Lacombe <lacombar@gmail.com> Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com> Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent e53beac commit 86e187f

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎scripts/kconfig/expr.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct menu {
164164
struct menu *list;
165165
struct symbol *sym;
166166
struct property *prompt;
167+
struct expr *visibility;
167168
struct expr *dep;
168169
unsigned int flags;
169170
char *help;

‎scripts/kconfig/lkc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void menu_end_menu(void);
107107
void menu_add_entry(struct symbol *sym);
108108
void menu_end_entry(void);
109109
void menu_add_dep(struct expr *dep);
110+
void menu_add_visibility(struct expr *dep);
110111
struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
111112
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
112113
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);

‎scripts/kconfig/menu.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr
152152
return menu_add_prop(type, prompt, NULL, dep);
153153
}
154154

155+
void menu_add_visibility(struct expr *expr)
156+
{
157+
current_entry->visibility = expr_alloc_and(current_entry->visibility,
158+
expr);
159+
}
160+
155161
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
156162
{
157163
menu_add_prop(type, NULL, expr, dep);
@@ -410,6 +416,11 @@ bool menu_is_visible(struct menu *menu)
410416
if (!menu->prompt)
411417
return false;
412418

419+
if (menu->visibility) {
420+
if (expr_calc_value(menu->visibility) == no)
421+
return no;
422+
}
423+
413424
sym = menu->sym;
414425
if (sym) {
415426
sym_calc_value(sym);

‎scripts/kconfig/zconf.gperf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX
3838
string, T_TYPE, TF_COMMAND, S_STRING
3939
select, T_SELECT, TF_COMMAND
4040
range, T_RANGE, TF_COMMAND
41+
visible, T_VISIBLE, TF_COMMAND
4142
option, T_OPTION, TF_COMMAND
4243
on, T_ON, TF_PARAM
4344
modules, T_OPT_MODULES, TF_OPTION

‎scripts/kconfig/zconf.y‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static struct menu *current_menu, *current_entry;
3636
#define YYERROR_VERBOSE
3737
#endif
3838
%}
39-
%expect 28
39+
%expect 30
4040

4141
%union
4242
{
@@ -68,6 +68,7 @@ static struct menu *current_menu, *current_entry;
6868
%token <id>T_DEFAULT
6969
%token <id>T_SELECT
7070
%token <id>T_RANGE
71+
%token <id>T_VISIBLE
7172
%token <id>T_OPTION
7273
%token <id>T_ON
7374
%token <string> T_WORD
@@ -123,7 +124,7 @@ stmt_list:
123124
;
124125

125126
option_name:
126-
T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
127+
T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
127128
;
128129

129130
common_stmt:
@@ -359,7 +360,7 @@ menu: T_MENU prompt T_EOL
359360
printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
360361
};
361362

362-
menu_entry: menu depends_list
363+
menu_entry: menu visibility_list depends_list
363364
{
364365
$$ = menu_add_menu();
365366
};
@@ -430,6 +431,19 @@ depends: T_DEPENDS T_ON expr T_EOL
430431
printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
431432
};
432433

434+
/* visibility option */
435+
436+
visibility_list:
437+
/* empty */
438+
| visibility_list visible
439+
| visibility_list T_EOL
440+
;
441+
442+
visible: T_VISIBLE if_expr
443+
{
444+
menu_add_visibility($2);
445+
};
446+
433447
/* prompt statement */
434448

435449
prompt_stmt_opt:
@@ -526,6 +540,7 @@ static const char *zconf_tokenname(int token)
526540
case T_IF: return "if";
527541
case T_ENDIF: return "endif";
528542
case T_DEPENDS: return "depends";
543+
case T_VISIBLE: return "visible";
529544
}
530545
return "<token>";
531546
}

0 commit comments

Comments
 (0)