mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-08-21 17:38:51 +09:00
![Eugeniu Rosca](/assets/img/avatar_default.png)
Align Kconfig to Linux 4.17-rc4 with minimal impact on non-kconfig files. Previous Kconfig sync was done by commitbf7ab1e70f
("kconfig: re-sync with Linux 4.10") and it achieved almost perfect alignment with a few (intended) exceptions, caused by below U-boot commits: [A] v2015.045f9eb22075
("kbuild: remove scripts/multiconfig.sh") [B] v2015.0720c20826ef
("Kconfig: Enable usage of escape char '\' in string values") [C] v2016.01da58dec866
("Various Makefiles: Add SPDX-License-Identifier tags") [D] v2016.035b8031ccb4
("Add more SPDX-License-Identifier tags") [E] v2016.03192bc6948b
("Fix GCC format-security errors and convert sprintfs.") Here is the list of Kconfig commits which followed the v4.10 alignment: [F] v2018.010931ed3c0d
("kconfig/symbol.c: use correct pointer type argument for sizeof") [G] v2018.031414e09b4f
("kconfig: revert change that was not needed for -Wformat-security") [H] v2018.0583d290c56f
("SPDX: Convert all of our single license tags to Linux Kernel style") Commit [F] was subsequently applied to Linux kernel as commit [I] with the same patch id, so it won't contribute to further misalignment. [I] v4.15-rc1 88127dae6ed9 ("kconfig/symbol.c: use correct pointer type argument for sizeof") Commit [G] is a Kconfig-specific revert of commit [E]. Commit [H] relocated and reformatted the license doing no functional change. In summary, the only functional change that makes U-boot Kconfig diverge from Linux Kconfig is commit [B]. After a brief analysis, the purpose of [B] seems to be placing "\n" literals in string symbols like CONFIG_AUTOBOOT_PROMPT="autoboot in %d seconds\n" in order to pass them directly to printf and expect correct output at runtime. Currently, Linux doesn't seem to have this requirement, so for the moment [B] looks like a U-boot specific feature/fix. From point of view of further Kconfig alignment and backporting efforts, it is highly desired that commits like [B] are propagated to Linux and any Kconfig fixes/features are contributed to Linux kernel first. This specific Kconfig re-sync just keeps [B] in place. Contrary to 4.10 Kconfig re-sync (which achieves zero non-kconfig changes), 4.17-rc4 re-sync does some amount of updates in Kbuild (striving to keep them at minimum), due to a number of reasons: * Kbuild is affected by the removal of Kconfig "*shipped" files and now requires flex and bison pre-installed on the host. * PYTHON{2,3} variables are defined in top-level Makefile as prerequisite for running the newly developed Kconfig unit tests. * silentoldconfig becomes an "internal implementation detail" deprecated for external use, being renamed to syncconfig. The exact non-kconfig files touched by this commit are: $ git show --format="" --stat -- ':!scripts/kconfig' .gitignore | 2 ++ Makefile | 9 +++++++-- scripts/Makefile.build | 11 +++++++++++ scripts/Makefile.lib | 41 ++++++++++++----------------------------- The imported Linux commits touching the above files are: c054be10ffdbd5 ("remove gperf left-overs from build system") 73a4f6dbe70a1b ("kbuild: add LEX and YACC variables") 033dba2ec06c47 ("kbuild: prepare to remove C files pre-generated by flex and bison") eea199b445f64c ("kbuild: remove unnecessary LEX_PREFIX and YACC_PREFIX") e71de5ee08dcb0 ("kbuild: remove remaining use of undefined YACC_PREFIX") d59fbbd09d5d6b ("kbuild: replace hardcoded bison in cmd_bison_h with $(YACC)") 911a91c39cabcb H ("kconfig: rename silentoldconfig to syncconfig") 59889300274569 (".gitignore: move *.lex.c *.tab.[ch] patterns to the top-level .gitignore") 9a8dfb394c0467 ("kbuild: clean up *.lex.c and *.tab.[ch] patterns from top-level Makefile") 833e622459432e H ("genksyms: generate lexer and parser during build instead of shipping") b23d1a241f4eb4 H ("kbuild: add %.lex.c and %.tab.[ch] to 'targets' automatically") e9781b52d4e0e3 H ("kbuild: add PYTHON2 and PYTHON3 variables") The commits marked with 'H' are assessed as "hard" (build will fail) prerequisites and the rest of them are assessed as "soft" prerequisites for the re-sync. In spite of relatively high number of non-H commits, they belong to this Kconfig update topic-wise and decrease the number of cherry pick conflicts for many commits in this series. Additional effort can be put in eliminating the soft prerequisites, if really needed. The commits which contributed to this Kconfig re-sync are listed below. Whenever a conflict resolution has been performed (mostly by hand, but sometimes automatically by git), it is revealed by the '!' sign in the second column, which means a patch id mismatch between Linux and U-boot commits: 9be3213b14d44f ("gconfig: remove misleading parentheses around a condition") ff85a1a80e0034 ("kconfig: Check for libncurses before menuconfig") ad8181060788c8 ("kconfig: fix sparse warnings in nconfig") cb77f0d623ff33 ! ("scripts: Switch to more portable Perl shebang") bb3290d91695bb ! ("Remove gperf usage from toolchain") c054be10ffdbd5 ("remove gperf left-overs from build system") b24413180f5600 ! ("License cleanup: add SPDX GPL-2.0 license identifier to files with no license") 9059a3493efea6 ! ("kconfig: fix relational operators for bool and tristate symbols") 2c37e08464a850 ("kconfig: Warn if choice default is not in choice") 33ca1a24866373 ("kconfig: Document the 'menu' struct") 52aede4ba5efd1 ("kconfig: Document the 'symbol' struct") c873443430ebd1 ("kconfig: Sync zconf.y with zconf.tab.c_shipped") 9a826842ff2fbd ("kconfig: Rename menu_check_dep() to rewrite_m()") fa8cedaef814ce ("kconfig: Clarify expression rewriting") f77850d3fe0c96 ("kconfig: Clean up modules handling and fix crash") e3b03bf29d6b99 ("kconfig: display recursive dependency resolution hint just once") 73a4f6dbe70a1b ! ("kbuild: add LEX and YACC variables") 033dba2ec06c47 ! ("kbuild: prepare to remove C files pre-generated by flex and bison") 29c833061c1d8c ("kconfig: generate lexer and parser during build instead of shipping") 26e47a3c11a25c ("kconfig: Don't leak symbol names during parsing") 24161a6711c945 ("kconfig: Don't leak 'source' filenames during parsing") bc28fe1d5ede88 ("kconfig: Don't leak 'option' arguments during parsing") 0724a7c32a54e3 ("kconfig: Don't leak main menus during parsing") ae7440ef0c8013 ("kconfig: Fix automatic menu creation mem leak") 5b1374b3b3c2fc ("kconfig: Fix expr_free() E_NOT leak") 7cf33f88e29410 ("kconfig: Fix choice symbol expression leak") 05cccce580456d ("kconfig: Document automatic submenu creation code") 0735f7e5def2ab ("kconfig: Document important expression functions") df60f4b92d3d0b ("kconfig: Remove menu_end_entry()") b92d804a51796b ("kconfig: drop 'boolean' keyword") 6479f327dea60d ("kconfig: Warn if there is more than one help text") 52e58a3caeba5d ("kconfig: make input_mode static") 5a3dc717b3c785 ("kconfig: make xfgets() really static") 84dd95d4f87a0d ("kconfig: make conf_unsaved a local variable of conf_read()") 765f4cdef6f80d ("kconfig: use default 'yy' prefix for lexer and parser") eea199b445f64c ("kbuild: remove unnecessary LEX_PREFIX and YACC_PREFIX") e71de5ee08dcb0 ("kbuild: remove remaining use of undefined YACC_PREFIX") d59fbbd09d5d6b ! ("kbuild: replace hardcoded bison in cmd_bison_h with $(YACC)") 3e41ba05b6d60c ("kconfig: Document SYMBOL_OPTIONAL logic") d3465af60f4471 ("kconfig: Clarify choice dependency propagation") 9d1a9e8bc18bea ("kconfig: Document 'if' flattening logic") b53688014e3325 ("kconfig: Clarify menu and 'if' dependency propagation") d0fd0428ecf04b ("kconfig: fix make xconfig when gettext is missing") 312ee68752faaa ("kconfig: announce removal of oldnoconfig if used") 1ccb27143360bd ("kconfig: make "Selected by:" and "Implied by:" readable") cedd55d49dee94 ! ("kconfig: Remove silentoldconfig from help and docs; fix kconfig/conf's help") 1b9eda2e4892cb ("kconfig: Warn if help text is blank") cb67ab2cd2b8ab ("kconfig: do not write choice values when their dependency becomes n") 4f208f392103e8 ("kconfig: show '?' prompt even if no help text is available") cd58a91def2acc ("kconfig: remove 'config*' pattern from .gitignnore") d2a04648a5dbc3 ("kconfig: remove check_stdin()") f3ff6fb5db68bc ("kconfig: echo stdin to stdout if either is redirected") 9e3e10c725360b ("kconfig: send error messages to stderr") d717f24d8c6808 ("kconfig: add xrealloc() helper") 523ca58b7db2e3 ("kconfig: remove const qualifier from sym_expand_string_value()") cd81fc82b93fa4 ("kconfig: add xstrdup() helper") f4bc1eefc1608e ("kconfig: set SYMBOL_AUTO to the symbol marked with defconfig_list") bf0bbdcf100322 ("kconfig: Don't leak choice names during parsing") 1a90ce36c6eff6 ("kconfig: Update ncurses package names for menuconfig") 5ae6fcc4bb82bd ("kconfig: fix line number in recursive inclusion error message") 07a422bb213adb ! ("kbuild: restore autoksyms.h touch to the top Makefile") 9a47ceec543bfb ("kconfig: clean-up reverse dependency help implementation") d9119b5925a03b ("kconfig: Print reverse dependencies in groups") f467c5640c29ad ("kconfig: only write '# CONFIG_FOO is not set' for visible symbols") 59a80b5e892dde ("kconfig: do not call check_conf() for olddefconfig") 4bb3a5b085cd6f ("kconfig: remove unneeded input_mode test in conf()") 99f0b6578bab44 ("kconfig: remove redundant input_mode test for check_conf() loop") 2aad9b89621386 ("kconfig: hide irrelevant sub-menus for oldconfig") 81d2bc2273052e ("kconfig: invoke oldconfig instead of silentoldconfig from local*config") 911a91c39cabcb ! ("kconfig: rename silentoldconfig to syncconfig") 2a61625835c7c8 ! ("kconfig: remove redundant streamline_config.pl prerequisite") 022a4bf6b59dfd ("kconfig: tests: add framework for Kconfig unit testing") 1903c511905984 ("kconfig: tests: add basic choice tests") 49ac3c0c3aa3b7 ("kconfig: tests: test automatic submenu creation") b76960c0f6b25d ("kconfig: tests: test if new symbols in choice are asked") 930c429a656fdb ("kconfig: tests: check unneeded "is not set" with unmet dependency") ee236610653ede ("kconfig: tests: check visibility of tristate choice values in y choice") beaaddb625400e ("kconfig: tests: test defconfig when two choices interact") 3e4888c2e3d77d ("kconfig: tests: test randconfig for choice in choice") 29c434f367ea7b ("kconfig: tests: test if recursive dependencies are detected") e2c75e7667c737 ("kconfig: tests: test if recursive inclusion is detected") f622f827958162 ("kconfig: warn unmet direct dependency of tristate symbols selected by y") f8f69dc0b4e070 ("kconfig: make unmet dependency warnings readable") 26561514cc9def ("kconfig: do not include both curses.h and ncurses.h for nconfig") 32a94b8b0c3e5a ("kconfig: remove duplicated file name and lineno of recursive inclusion") 379a8eb8eb1a55 ("kconfig: detect recursive inclusion earlier") 18492685e479fd ("kconfig: use yylineno option instead of manual lineno increments") 59889300274569 ! (".gitignore: move *.lex.c *.tab.[ch] patterns to the top-level .gitignore") 9a8dfb394c0467 ! ("kbuild: clean up *.lex.c and *.tab.[ch] patterns from top-level Makefile") 833e622459432e ! ("genksyms: generate lexer and parser during build instead of shipping") b23d1a241f4eb4 ! ("kbuild: add %.lex.c and %.tab.[ch] to 'targets' automatically") 17baab68d337a0 ("kconfig: extend output of 'listnewconfig'") e9781b52d4e0e3 ! ("kbuild: add PYTHON2 and PYTHON3 variables") The current Kconfig update generates below build-time warnings: YACC scripts/dtc/dtc-parser.tab.h scripts/dtc/dtc-parser.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] YACC scripts/dtc/dtc-parser.tab.c scripts/dtc/dtc-parser.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] This seems to happen because the Kbuild updates apparently didn't make room for both "*shipped"-based builds and flex/bison-based builds. A similar problem has been reported for genksyms parser in v4.17-rc1 commit 833e622459432e ("genksyms: generate lexer and parser during build instead of shipping"). I have figured out empirically that the warnings are healed after updating the in-tree U-boot DTC to upstream v1.4.6-9, same as done by Linux v4.17-rc1 commit 9130ba88464032 ("scripts/dtc: Update to upstream version v1.4.6-9-gaadd0b65c987"). Whether fixing the DTC-related yacc warnings should be done together with the Kconfig re-sync, I would like to hear from community. My testing was limited to: - make defconfig all - make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- r8a7795_ulcb_defconfig all - comparing .config before and after the re-sync - running the newly imported Kconfig unit tests as seen below: $ make testconfig Tested-by: Petr Vorel <petr.vorel@gmail.com> ============================= test session starts ============================= scripts/kconfig/tests/auto_submenu/__init__.py::test PASSED [ 7%] scripts/kconfig/tests/choice/__init__.py::test_oldask0 PASSED [ 14%] scripts/kconfig/tests/choice/__init__.py::test_oldask1 PASSED [ 21%] scripts/kconfig/tests/choice/__init__.py::test_allyes PASSED [ 28%] scripts/kconfig/tests/choice/__init__.py::test_allmod PASSED [ 35%] scripts/kconfig/tests/choice/__init__.py::test_allno PASSED [ 42%] scripts/kconfig/tests/choice/__init__.py::test_alldef PASSED [ 50%] scripts/kconfig/tests/choice_value_with_m_dep/__init__.py::test PASSED [ 57%] scripts/kconfig/tests/err_recursive_inc/__init__.py::test PASSED [ 64%] scripts/kconfig/tests/inter_choice/__init__.py::test PASSED [ 71%] scripts/kconfig/tests/new_choice_with_dep/__init__.py::test PASSED [ 78%] scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py::test PASSED [ 85%] scripts/kconfig/tests/rand_nested_choice/__init__.py::test PASSED [ 92%] scripts/kconfig/tests/warn_recursive_dep/__init__.py::test PASSED [100%] ========================== 14 passed in 0.34 seconds ========================== Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com> Reviewed-by: Masahiro Yamada <yamada.masahiro@socionext.com> Tested-by: Petr Vorel <petr.vorel@gmail.com>
874 lines
22 KiB
C
874 lines
22 KiB
C
/*
|
|
* Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
|
|
* Released under the terms of the GNU GPL v2.0.
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "lkc.h"
|
|
|
|
static const char nohelp_text[] = "There is no help available for this option.";
|
|
|
|
struct menu rootmenu;
|
|
static struct menu **last_entry_ptr;
|
|
|
|
struct file *file_list;
|
|
struct file *current_file;
|
|
|
|
void menu_warn(struct menu *menu, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno);
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
}
|
|
|
|
static void prop_warn(struct property *prop, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno);
|
|
vfprintf(stderr, fmt, ap);
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
}
|
|
|
|
void _menu_init(void)
|
|
{
|
|
current_entry = current_menu = &rootmenu;
|
|
last_entry_ptr = &rootmenu.list;
|
|
}
|
|
|
|
void menu_add_entry(struct symbol *sym)
|
|
{
|
|
struct menu *menu;
|
|
|
|
menu = xmalloc(sizeof(*menu));
|
|
memset(menu, 0, sizeof(*menu));
|
|
menu->sym = sym;
|
|
menu->parent = current_menu;
|
|
menu->file = current_file;
|
|
menu->lineno = zconf_lineno();
|
|
|
|
*last_entry_ptr = menu;
|
|
last_entry_ptr = &menu->next;
|
|
current_entry = menu;
|
|
if (sym)
|
|
menu_add_symbol(P_SYMBOL, sym, NULL);
|
|
}
|
|
|
|
struct menu *menu_add_menu(void)
|
|
{
|
|
last_entry_ptr = ¤t_entry->list;
|
|
return current_menu = current_entry;
|
|
}
|
|
|
|
void menu_end_menu(void)
|
|
{
|
|
last_entry_ptr = ¤t_menu->next;
|
|
current_menu = current_menu->parent;
|
|
}
|
|
|
|
/*
|
|
* Rewrites 'm' to 'm' && MODULES, so that it evaluates to 'n' when running
|
|
* without modules
|
|
*/
|
|
static struct expr *rewrite_m(struct expr *e)
|
|
{
|
|
if (!e)
|
|
return e;
|
|
|
|
switch (e->type) {
|
|
case E_NOT:
|
|
e->left.expr = rewrite_m(e->left.expr);
|
|
break;
|
|
case E_OR:
|
|
case E_AND:
|
|
e->left.expr = rewrite_m(e->left.expr);
|
|
e->right.expr = rewrite_m(e->right.expr);
|
|
break;
|
|
case E_SYMBOL:
|
|
/* change 'm' into 'm' && MODULES */
|
|
if (e->left.sym == &symbol_mod)
|
|
return expr_alloc_and(e, expr_alloc_symbol(modules_sym));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return e;
|
|
}
|
|
|
|
void menu_add_dep(struct expr *dep)
|
|
{
|
|
current_entry->dep = expr_alloc_and(current_entry->dep, dep);
|
|
}
|
|
|
|
void menu_set_type(int type)
|
|
{
|
|
struct symbol *sym = current_entry->sym;
|
|
|
|
if (sym->type == type)
|
|
return;
|
|
if (sym->type == S_UNKNOWN) {
|
|
sym->type = type;
|
|
return;
|
|
}
|
|
menu_warn(current_entry,
|
|
"ignoring type redefinition of '%s' from '%s' to '%s'",
|
|
sym->name ? sym->name : "<choice>",
|
|
sym_type_name(sym->type), sym_type_name(type));
|
|
}
|
|
|
|
static struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep)
|
|
{
|
|
struct property *prop = prop_alloc(type, current_entry->sym);
|
|
|
|
prop->menu = current_entry;
|
|
prop->expr = expr;
|
|
prop->visible.expr = dep;
|
|
|
|
if (prompt) {
|
|
if (isspace(*prompt)) {
|
|
prop_warn(prop, "leading whitespace ignored");
|
|
while (isspace(*prompt))
|
|
prompt++;
|
|
}
|
|
if (current_entry->prompt && current_entry != &rootmenu)
|
|
prop_warn(prop, "prompt redefined");
|
|
|
|
/* Apply all upper menus' visibilities to actual prompts. */
|
|
if(type == P_PROMPT) {
|
|
struct menu *menu = current_entry;
|
|
|
|
while ((menu = menu->parent) != NULL) {
|
|
struct expr *dup_expr;
|
|
|
|
if (!menu->visibility)
|
|
continue;
|
|
/*
|
|
* Do not add a reference to the
|
|
* menu's visibility expression but
|
|
* use a copy of it. Otherwise the
|
|
* expression reduction functions
|
|
* will modify expressions that have
|
|
* multiple references which can
|
|
* cause unwanted side effects.
|
|
*/
|
|
dup_expr = expr_copy(menu->visibility);
|
|
|
|
prop->visible.expr
|
|
= expr_alloc_and(prop->visible.expr,
|
|
dup_expr);
|
|
}
|
|
}
|
|
|
|
current_entry->prompt = prop;
|
|
}
|
|
prop->text = prompt;
|
|
|
|
return prop;
|
|
}
|
|
|
|
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep)
|
|
{
|
|
return menu_add_prop(type, prompt, NULL, dep);
|
|
}
|
|
|
|
void menu_add_visibility(struct expr *expr)
|
|
{
|
|
current_entry->visibility = expr_alloc_and(current_entry->visibility,
|
|
expr);
|
|
}
|
|
|
|
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
|
|
{
|
|
menu_add_prop(type, NULL, expr, dep);
|
|
}
|
|
|
|
void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
|
|
{
|
|
menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
|
|
}
|
|
|
|
void menu_add_option(int token, char *arg)
|
|
{
|
|
switch (token) {
|
|
case T_OPT_MODULES:
|
|
if (modules_sym)
|
|
zconf_error("symbol '%s' redefines option 'modules'"
|
|
" already defined by symbol '%s'",
|
|
current_entry->sym->name,
|
|
modules_sym->name
|
|
);
|
|
modules_sym = current_entry->sym;
|
|
break;
|
|
case T_OPT_DEFCONFIG_LIST:
|
|
if (!sym_defconfig_list)
|
|
sym_defconfig_list = current_entry->sym;
|
|
else if (sym_defconfig_list != current_entry->sym)
|
|
zconf_error("trying to redefine defconfig symbol");
|
|
sym_defconfig_list->flags |= SYMBOL_AUTO;
|
|
break;
|
|
case T_OPT_ENV:
|
|
prop_add_env(arg);
|
|
break;
|
|
case T_OPT_ALLNOCONFIG_Y:
|
|
current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
|
|
{
|
|
return sym2->type == S_INT || sym2->type == S_HEX ||
|
|
(sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
|
|
}
|
|
|
|
static void sym_check_prop(struct symbol *sym)
|
|
{
|
|
struct property *prop;
|
|
struct symbol *sym2;
|
|
char *use;
|
|
|
|
for (prop = sym->prop; prop; prop = prop->next) {
|
|
switch (prop->type) {
|
|
case P_DEFAULT:
|
|
if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
|
|
prop->expr->type != E_SYMBOL)
|
|
prop_warn(prop,
|
|
"default for config symbol '%s'"
|
|
" must be a single symbol", sym->name);
|
|
if (prop->expr->type != E_SYMBOL)
|
|
break;
|
|
sym2 = prop_get_symbol(prop);
|
|
if (sym->type == S_HEX || sym->type == S_INT) {
|
|
if (!menu_validate_number(sym, sym2))
|
|
prop_warn(prop,
|
|
"'%s': number is invalid",
|
|
sym->name);
|
|
}
|
|
if (sym_is_choice(sym)) {
|
|
struct property *choice_prop =
|
|
sym_get_choice_prop(sym2);
|
|
|
|
if (!choice_prop ||
|
|
prop_get_symbol(choice_prop) != sym)
|
|
prop_warn(prop,
|
|
"choice default symbol '%s' is not contained in the choice",
|
|
sym2->name);
|
|
}
|
|
break;
|
|
case P_SELECT:
|
|
case P_IMPLY:
|
|
use = prop->type == P_SELECT ? "select" : "imply";
|
|
sym2 = prop_get_symbol(prop);
|
|
if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
|
|
prop_warn(prop,
|
|
"config symbol '%s' uses %s, but is "
|
|
"not bool or tristate", sym->name, use);
|
|
else if (sym2->type != S_UNKNOWN &&
|
|
sym2->type != S_BOOLEAN &&
|
|
sym2->type != S_TRISTATE)
|
|
prop_warn(prop,
|
|
"'%s' has wrong type. '%s' only "
|
|
"accept arguments of bool and "
|
|
"tristate type", sym2->name, use);
|
|
break;
|
|
case P_RANGE:
|
|
if (sym->type != S_INT && sym->type != S_HEX)
|
|
prop_warn(prop, "range is only allowed "
|
|
"for int or hex symbols");
|
|
if (!menu_validate_number(sym, prop->expr->left.sym) ||
|
|
!menu_validate_number(sym, prop->expr->right.sym))
|
|
prop_warn(prop, "range is invalid");
|
|
break;
|
|
default:
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
void menu_finalize(struct menu *parent)
|
|
{
|
|
struct menu *menu, *last_menu;
|
|
struct symbol *sym;
|
|
struct property *prop;
|
|
struct expr *parentdep, *basedep, *dep, *dep2, **ep;
|
|
|
|
sym = parent->sym;
|
|
if (parent->list) {
|
|
/*
|
|
* This menu node has children. We (recursively) process them
|
|
* and propagate parent dependencies before moving on.
|
|
*/
|
|
|
|
if (sym && sym_is_choice(sym)) {
|
|
if (sym->type == S_UNKNOWN) {
|
|
/* find the first choice value to find out choice type */
|
|
current_entry = parent;
|
|
for (menu = parent->list; menu; menu = menu->next) {
|
|
if (menu->sym && menu->sym->type != S_UNKNOWN) {
|
|
menu_set_type(menu->sym->type);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
/* set the type of the remaining choice values */
|
|
for (menu = parent->list; menu; menu = menu->next) {
|
|
current_entry = menu;
|
|
if (menu->sym && menu->sym->type == S_UNKNOWN)
|
|
menu_set_type(sym->type);
|
|
}
|
|
|
|
/*
|
|
* Use the choice itself as the parent dependency of
|
|
* the contained items. This turns the mode of the
|
|
* choice into an upper bound on the visibility of the
|
|
* choice value symbols.
|
|
*/
|
|
parentdep = expr_alloc_symbol(sym);
|
|
} else if (parent->prompt)
|
|
/* Menu node for 'menu' */
|
|
parentdep = parent->prompt->visible.expr;
|
|
else
|
|
/* Menu node for 'if' */
|
|
parentdep = parent->dep;
|
|
|
|
/* For each child menu node... */
|
|
for (menu = parent->list; menu; menu = menu->next) {
|
|
/*
|
|
* Propagate parent dependencies to the child menu
|
|
* node, also rewriting and simplifying expressions
|
|
*/
|
|
basedep = rewrite_m(menu->dep);
|
|
basedep = expr_transform(basedep);
|
|
basedep = expr_alloc_and(expr_copy(parentdep), basedep);
|
|
basedep = expr_eliminate_dups(basedep);
|
|
menu->dep = basedep;
|
|
|
|
if (menu->sym)
|
|
/*
|
|
* Note: For symbols, all prompts are included
|
|
* too in the symbol's own property list
|
|
*/
|
|
prop = menu->sym->prop;
|
|
else
|
|
/*
|
|
* For non-symbol menu nodes, we just need to
|
|
* handle the prompt
|
|
*/
|
|
prop = menu->prompt;
|
|
|
|
/* For each property... */
|
|
for (; prop; prop = prop->next) {
|
|
if (prop->menu != menu)
|
|
/*
|
|
* Two possibilities:
|
|
*
|
|
* 1. The property lacks dependencies
|
|
* and so isn't location-specific,
|
|
* e.g. an 'option'
|
|
*
|
|
* 2. The property belongs to a symbol
|
|
* defined in multiple locations and
|
|
* is from some other location. It
|
|
* will be handled there in that
|
|
* case.
|
|
*
|
|
* Skip the property.
|
|
*/
|
|
continue;
|
|
|
|
/*
|
|
* Propagate parent dependencies to the
|
|
* property's condition, rewriting and
|
|
* simplifying expressions at the same time
|
|
*/
|
|
dep = rewrite_m(prop->visible.expr);
|
|
dep = expr_transform(dep);
|
|
dep = expr_alloc_and(expr_copy(basedep), dep);
|
|
dep = expr_eliminate_dups(dep);
|
|
if (menu->sym && menu->sym->type != S_TRISTATE)
|
|
dep = expr_trans_bool(dep);
|
|
prop->visible.expr = dep;
|
|
|
|
/*
|
|
* Handle selects and implies, which modify the
|
|
* dependencies of the selected/implied symbol
|
|
*/
|
|
if (prop->type == P_SELECT) {
|
|
struct symbol *es = prop_get_symbol(prop);
|
|
es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
|
|
expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
|
|
} else if (prop->type == P_IMPLY) {
|
|
struct symbol *es = prop_get_symbol(prop);
|
|
es->implied.expr = expr_alloc_or(es->implied.expr,
|
|
expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sym && sym_is_choice(sym))
|
|
expr_free(parentdep);
|
|
|
|
/*
|
|
* Recursively process children in the same fashion before
|
|
* moving on
|
|
*/
|
|
for (menu = parent->list; menu; menu = menu->next)
|
|
menu_finalize(menu);
|
|
} else if (sym) {
|
|
/*
|
|
* 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
|
|
* +-B
|
|
* +-C
|
|
* ...
|
|
*
|
|
* This also works recursively, giving the following structure
|
|
* if A is a symbol and B depends on A:
|
|
*
|
|
* sym
|
|
* +-A
|
|
* | +-B
|
|
* +-C
|
|
* ...
|
|
*/
|
|
|
|
basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
|
|
basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
|
|
basedep = expr_eliminate_dups(expr_transform(basedep));
|
|
|
|
/* Examine consecutive elements after sym */
|
|
last_menu = NULL;
|
|
for (menu = parent->next; menu; menu = menu->next) {
|
|
dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
|
|
if (!expr_contains_symbol(dep, sym))
|
|
/* No dependency, quit */
|
|
break;
|
|
if (expr_depends_symbol(dep, sym))
|
|
/* Absolute dependency, put in submenu */
|
|
goto next;
|
|
|
|
/*
|
|
* Also consider it a dependency on sym if our
|
|
* dependencies contain sym and are a "superset" of
|
|
* sym's dependencies, e.g. '(sym || Q) && R' when sym
|
|
* depends on R.
|
|
*
|
|
* Note that 'R' might be from an enclosing menu or if,
|
|
* making this a more common case than it might seem.
|
|
*/
|
|
dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
|
|
dep = expr_eliminate_dups(expr_transform(dep));
|
|
dep2 = expr_copy(basedep);
|
|
expr_eliminate_eq(&dep, &dep2);
|
|
expr_free(dep);
|
|
if (!expr_is_yes(dep2)) {
|
|
/* Not superset, quit */
|
|
expr_free(dep2);
|
|
break;
|
|
}
|
|
/* Superset, put in submenu */
|
|
expr_free(dep2);
|
|
next:
|
|
menu_finalize(menu);
|
|
menu->parent = parent;
|
|
last_menu = menu;
|
|
}
|
|
expr_free(basedep);
|
|
if (last_menu) {
|
|
parent->list = parent->next;
|
|
parent->next = last_menu->next;
|
|
last_menu->next = NULL;
|
|
}
|
|
|
|
sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep);
|
|
}
|
|
for (menu = parent->list; menu; menu = menu->next) {
|
|
if (sym && sym_is_choice(sym) &&
|
|
menu->sym && !sym_is_choice_value(menu->sym)) {
|
|
current_entry = menu;
|
|
menu->sym->flags |= SYMBOL_CHOICEVAL;
|
|
if (!menu->prompt)
|
|
menu_warn(menu, "choice value must have a prompt");
|
|
for (prop = menu->sym->prop; prop; prop = prop->next) {
|
|
if (prop->type == P_DEFAULT)
|
|
prop_warn(prop, "defaults for choice "
|
|
"values not supported");
|
|
if (prop->menu == menu)
|
|
continue;
|
|
if (prop->type == P_PROMPT &&
|
|
prop->menu->parent->sym != sym)
|
|
prop_warn(prop, "choice value used outside its choice group");
|
|
}
|
|
/* Non-tristate choice values of tristate choices must
|
|
* depend on the choice being set to Y. The choice
|
|
* values' dependencies were propagated to their
|
|
* properties above, so the change here must be re-
|
|
* propagated.
|
|
*/
|
|
if (sym->type == S_TRISTATE && menu->sym->type != S_TRISTATE) {
|
|
basedep = expr_alloc_comp(E_EQUAL, sym, &symbol_yes);
|
|
menu->dep = expr_alloc_and(basedep, menu->dep);
|
|
for (prop = menu->sym->prop; prop; prop = prop->next) {
|
|
if (prop->menu != menu)
|
|
continue;
|
|
prop->visible.expr = expr_alloc_and(expr_copy(basedep),
|
|
prop->visible.expr);
|
|
}
|
|
}
|
|
menu_add_symbol(P_CHOICE, sym, NULL);
|
|
prop = sym_get_choice_prop(sym);
|
|
for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr)
|
|
;
|
|
*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;
|
|
if (!last_menu->next)
|
|
break;
|
|
}
|
|
last_menu->next = menu->next;
|
|
menu->next = menu->list;
|
|
menu->list = NULL;
|
|
}
|
|
}
|
|
|
|
if (sym && !(sym->flags & SYMBOL_WARNED)) {
|
|
if (sym->type == S_UNKNOWN)
|
|
menu_warn(parent, "config symbol defined without type");
|
|
|
|
if (sym_is_choice(sym) && !parent->prompt)
|
|
menu_warn(parent, "choice must have a prompt");
|
|
|
|
/* Check properties connected to this symbol */
|
|
sym_check_prop(sym);
|
|
sym->flags |= SYMBOL_WARNED;
|
|
}
|
|
|
|
/*
|
|
* For non-optional choices, add a reverse dependency (corresponding to
|
|
* a select) of '<visibility> && m'. This prevents the user from
|
|
* setting the choice mode to 'n' when the choice is visible.
|
|
*
|
|
* This would also work for non-choice symbols, but only non-optional
|
|
* choices clear SYMBOL_OPTIONAL as of writing. Choices are implemented
|
|
* as a type of symbol.
|
|
*/
|
|
if (sym && !sym_is_optional(sym) && parent->prompt) {
|
|
sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
|
|
expr_alloc_and(parent->prompt->visible.expr,
|
|
expr_alloc_symbol(&symbol_mod)));
|
|
}
|
|
}
|
|
|
|
bool menu_has_prompt(struct menu *menu)
|
|
{
|
|
if (!menu->prompt)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Determine if a menu is empty.
|
|
* A menu is considered empty if it contains no or only
|
|
* invisible entries.
|
|
*/
|
|
bool menu_is_empty(struct menu *menu)
|
|
{
|
|
struct menu *child;
|
|
|
|
for (child = menu->list; child; child = child->next) {
|
|
if (menu_is_visible(child))
|
|
return(false);
|
|
}
|
|
return(true);
|
|
}
|
|
|
|
bool menu_is_visible(struct menu *menu)
|
|
{
|
|
struct menu *child;
|
|
struct symbol *sym;
|
|
tristate visible;
|
|
|
|
if (!menu->prompt)
|
|
return false;
|
|
|
|
if (menu->visibility) {
|
|
if (expr_calc_value(menu->visibility) == no)
|
|
return false;
|
|
}
|
|
|
|
sym = menu->sym;
|
|
if (sym) {
|
|
sym_calc_value(sym);
|
|
visible = menu->prompt->visible.tri;
|
|
} else
|
|
visible = menu->prompt->visible.tri = expr_calc_value(menu->prompt->visible.expr);
|
|
|
|
if (visible != no)
|
|
return true;
|
|
|
|
if (!sym || sym_get_tristate_value(menu->sym) == no)
|
|
return false;
|
|
|
|
for (child = menu->list; child; child = child->next) {
|
|
if (menu_is_visible(child)) {
|
|
if (sym)
|
|
sym->flags |= SYMBOL_DEF_USER;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
const char *menu_get_prompt(struct menu *menu)
|
|
{
|
|
if (menu->prompt)
|
|
return menu->prompt->text;
|
|
else if (menu->sym)
|
|
return menu->sym->name;
|
|
return NULL;
|
|
}
|
|
|
|
struct menu *menu_get_root_menu(struct menu *menu)
|
|
{
|
|
return &rootmenu;
|
|
}
|
|
|
|
struct menu *menu_get_parent_menu(struct menu *menu)
|
|
{
|
|
enum prop_type type;
|
|
|
|
for (; menu != &rootmenu; menu = menu->parent) {
|
|
type = menu->prompt ? menu->prompt->type : 0;
|
|
if (type == P_MENU)
|
|
break;
|
|
}
|
|
return menu;
|
|
}
|
|
|
|
bool menu_has_help(struct menu *menu)
|
|
{
|
|
return menu->help != NULL;
|
|
}
|
|
|
|
const char *menu_get_help(struct menu *menu)
|
|
{
|
|
if (menu->help)
|
|
return menu->help;
|
|
else
|
|
return "";
|
|
}
|
|
|
|
static void get_prompt_str(struct gstr *r, struct property *prop,
|
|
struct list_head *head)
|
|
{
|
|
int i, j;
|
|
struct menu *submenu[8], *menu, *location = NULL;
|
|
struct jump_key *jump = NULL;
|
|
|
|
str_printf(r, _("Prompt: %s\n"), _(prop->text));
|
|
menu = prop->menu->parent;
|
|
for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
|
|
bool accessible = menu_is_visible(menu);
|
|
|
|
submenu[i++] = menu;
|
|
if (location == NULL && accessible)
|
|
location = menu;
|
|
}
|
|
if (head && location) {
|
|
jump = xmalloc(sizeof(struct jump_key));
|
|
|
|
if (menu_is_visible(prop->menu)) {
|
|
/*
|
|
* There is not enough room to put the hint at the
|
|
* beginning of the "Prompt" line. Put the hint on the
|
|
* last "Location" line even when it would belong on
|
|
* the former.
|
|
*/
|
|
jump->target = prop->menu;
|
|
} else
|
|
jump->target = location;
|
|
|
|
if (list_empty(head))
|
|
jump->index = 0;
|
|
else
|
|
jump->index = list_entry(head->prev, struct jump_key,
|
|
entries)->index + 1;
|
|
|
|
list_add_tail(&jump->entries, head);
|
|
}
|
|
|
|
if (i > 0) {
|
|
str_printf(r, _(" Location:\n"));
|
|
for (j = 4; --i >= 0; j += 2) {
|
|
menu = submenu[i];
|
|
if (jump && menu == location)
|
|
jump->offset = strlen(r->s);
|
|
str_printf(r, "%*c-> %s", j, ' ',
|
|
_(menu_get_prompt(menu)));
|
|
if (menu->sym) {
|
|
str_printf(r, " (%s [=%s])", menu->sym->name ?
|
|
menu->sym->name : _("<choice>"),
|
|
sym_get_string_value(menu->sym));
|
|
}
|
|
str_append(r, "\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* get property of type P_SYMBOL
|
|
*/
|
|
static struct property *get_symbol_prop(struct symbol *sym)
|
|
{
|
|
struct property *prop = NULL;
|
|
|
|
for_all_properties(sym, prop, P_SYMBOL)
|
|
break;
|
|
return prop;
|
|
}
|
|
|
|
static void get_symbol_props_str(struct gstr *r, struct symbol *sym,
|
|
enum prop_type tok, const char *prefix)
|
|
{
|
|
bool hit = false;
|
|
struct property *prop;
|
|
|
|
for_all_properties(sym, prop, tok) {
|
|
if (!hit) {
|
|
str_append(r, prefix);
|
|
hit = true;
|
|
} else
|
|
str_printf(r, " && ");
|
|
expr_gstr_print(prop->expr, r);
|
|
}
|
|
if (hit)
|
|
str_append(r, "\n");
|
|
}
|
|
|
|
/*
|
|
* head is optional and may be NULL
|
|
*/
|
|
static void get_symbol_str(struct gstr *r, struct symbol *sym,
|
|
struct list_head *head)
|
|
{
|
|
struct property *prop;
|
|
|
|
if (sym && sym->name) {
|
|
str_printf(r, "Symbol: %s [=%s]\n", sym->name,
|
|
sym_get_string_value(sym));
|
|
str_printf(r, "Type : %s\n", sym_type_name(sym->type));
|
|
if (sym->type == S_INT || sym->type == S_HEX) {
|
|
prop = sym_get_range_prop(sym);
|
|
if (prop) {
|
|
str_printf(r, "Range : ");
|
|
expr_gstr_print(prop->expr, r);
|
|
str_append(r, "\n");
|
|
}
|
|
}
|
|
}
|
|
for_all_prompts(sym, prop)
|
|
get_prompt_str(r, prop, head);
|
|
|
|
prop = get_symbol_prop(sym);
|
|
if (prop) {
|
|
str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name,
|
|
prop->menu->lineno);
|
|
if (!expr_is_yes(prop->visible.expr)) {
|
|
str_append(r, _(" Depends on: "));
|
|
expr_gstr_print(prop->visible.expr, r);
|
|
str_append(r, "\n");
|
|
}
|
|
}
|
|
|
|
get_symbol_props_str(r, sym, P_SELECT, _(" Selects: "));
|
|
if (sym->rev_dep.expr) {
|
|
expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, " Selected by [y]:\n");
|
|
expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, " Selected by [m]:\n");
|
|
expr_gstr_print_revdep(sym->rev_dep.expr, r, no, " Selected by [n]:\n");
|
|
}
|
|
|
|
get_symbol_props_str(r, sym, P_IMPLY, _(" Implies: "));
|
|
if (sym->implied.expr) {
|
|
expr_gstr_print_revdep(sym->implied.expr, r, yes, " Implied by [y]:\n");
|
|
expr_gstr_print_revdep(sym->implied.expr, r, mod, " Implied by [m]:\n");
|
|
expr_gstr_print_revdep(sym->implied.expr, r, no, " Implied by [n]:\n");
|
|
}
|
|
|
|
str_append(r, "\n\n");
|
|
}
|
|
|
|
struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head)
|
|
{
|
|
struct symbol *sym;
|
|
struct gstr res = str_new();
|
|
int i;
|
|
|
|
for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
|
|
get_symbol_str(&res, sym, head);
|
|
if (!i)
|
|
str_append(&res, _("No matches found.\n"));
|
|
return res;
|
|
}
|
|
|
|
|
|
void menu_get_ext_help(struct menu *menu, struct gstr *help)
|
|
{
|
|
struct symbol *sym = menu->sym;
|
|
const char *help_text = nohelp_text;
|
|
|
|
if (menu_has_help(menu)) {
|
|
if (sym->name)
|
|
str_printf(help, "%s%s:\n\n", CONFIG_, sym->name);
|
|
help_text = menu_get_help(menu);
|
|
}
|
|
str_printf(help, "%s\n", _(help_text));
|
|
if (sym)
|
|
get_symbol_str(help, sym, NULL);
|
|
}
|