Skip to content

Commit

Permalink
kconfig: add support for warnings when using experimental features
Browse files Browse the repository at this point in the history
This adds two new Kconfig settings.

The first setting `EXPERIMENTAL` which is a promptless symbol.
This symbol must be selected by any setting which is used to enable
an experimental feature.

The second setting is `WARN_EXPERIMENTAL` which is a user controlled
setting that configures the build system to print a warning when
experimental features are enabled.

Signed-off-by: Torsten Rasmussen <[email protected]>
  • Loading branch information
tejlmand committed Oct 18, 2021
1 parent 79f8af0 commit 8807006
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ config MAKEFILE_EXPORTS
third party Makefile-based build systems.

endmenu

config EXPERIMENTAL
bool
help
Symbol that must be selected by a feature if it is considered to be
at an experimental implementation stage.

config WARN_EXPERIMENTAL
bool
prompt "Warn on experimental usage"
help
Print a warning when the Kconfig tree is parsed if any experimental
features are enabled.

endmenu


Expand Down
16 changes: 15 additions & 1 deletion scripts/kconfig/kconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Zephyr doesn't use tristate symbols. They're supported here just to make the
# script a bit more generic.
from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \
TRISTATE, TRI_TO_STR, AND
TRISTATE, TRI_TO_STR, AND, OR


def main():
Expand Down Expand Up @@ -62,6 +62,9 @@ def main():
check_assigned_sym_values(kconf)
check_assigned_choice_values(kconf)

if kconf.syms['WARN_EXPERIMENTAL'].tri_value == 2:
check_experimental(kconf)

# Hack: Force all symbols to be evaluated, to catch warnings generated
# during evaluation. Wait till the end to write the actual output files, so
# that we don't generate any output if there are warnings-turned-errors.
Expand Down Expand Up @@ -202,6 +205,17 @@ def check_assigned_choice_values(kconf):
"""


def check_experimental(kconf):
experimental = kconf.syms['EXPERIMENTAL']
dep_expr = experimental.rev_dep

if dep_expr is not kconf.n:
selectors = [s for s in split_expr(dep_expr, OR) if expr_value(s) == 2]
for selector in selectors:
selector_name = split_expr(selector, AND)[0].name
warn(f'Experimental symbol {selector_name} is enabled.')


def promptless(sym):
# Returns True if 'sym' has no prompt. Since the symbol might be defined in
# multiple locations, we need to check all locations.
Expand Down

0 comments on commit 8807006

Please sign in to comment.