Skip to content

Commit

Permalink
kconfig: add warn-unknown-symbols sanity check
Browse files Browse the repository at this point in the history
Introduce KCONFIG_WARN_UNKNOWN_SYMBOLS environment variable,
which makes Kconfig warn about unknown config symbols.

This is especially useful for continuous kernel uprevs when
some symbols can be either removed or renamed between kernel
releases (which can go unnoticed otherwise).

By default KCONFIG_WARN_UNKNOWN_SYMBOLS generates warnings,
which are non-terminal. There is an additional environment
variable KCONFIG_WERROR that overrides this behaviour and
turns warnings into errors.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
Sergey Senozhatsky authored and Masahiro Yamada committed Sep 1, 2023
1 parent bfb41e4 commit 7cd3430
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Documentation/kbuild/kconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ KCONFIG_OVERWRITECONFIG
If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not
break symlinks when .config is a symlink to somewhere else.

KCONFIG_WARN_UNKNOWN_SYMBOLS
----------------------------
This environment variable makes Kconfig warn about all unrecognized
symbols in the config input.

KCONFIG_WERROR
--------------
If set, Kconfig treats warnings as errors.

`CONFIG_`
---------
If you set `CONFIG_` in the environment, Kconfig will prefix all symbols
Expand Down
21 changes: 19 additions & 2 deletions scripts/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ int conf_read_simple(const char *name, int def)
char *p, *p2;
struct symbol *sym;
int i, def_flags;
const char *warn_unknown;
const char *werror;

warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
werror = getenv("KCONFIG_WERROR");
if (name) {
in = zconf_fopen(name);
} else {
Expand Down Expand Up @@ -437,6 +441,10 @@ int conf_read_simple(const char *name, int def)
if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) {
if (warn_unknown)
conf_warning("unknown symbol: %s",
line + 2 + strlen(CONFIG_));

conf_set_changed(true);
continue;
}
Expand Down Expand Up @@ -471,16 +479,21 @@ int conf_read_simple(const char *name, int def)

sym = sym_find(line + strlen(CONFIG_));
if (!sym) {
if (def == S_DEF_AUTO)
if (def == S_DEF_AUTO) {
/*
* Reading from include/config/auto.conf
* If CONFIG_FOO previously existed in
* auto.conf but it is missing now,
* include/config/FOO must be touched.
*/
conf_touch_dep(line + strlen(CONFIG_));
else
} else {
if (warn_unknown)
conf_warning("unknown symbol: %s",
line + strlen(CONFIG_));

conf_set_changed(true);
}
continue;
}

Expand Down Expand Up @@ -519,6 +532,10 @@ int conf_read_simple(const char *name, int def)
}
free(line);
fclose(in);

if (conf_warnings && werror)
exit(1);

return 0;
}

Expand Down

0 comments on commit 7cd3430

Please sign in to comment.