From 6066ab43b380e0d0b39a75eb5dbeb8a1471b3c3b Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 15 Jul 2022 12:05:04 +0200 Subject: [PATCH] kconfig: add support for warnings when enabling deprecated features This adds two new Kconfig settings. The first setting `DEPRECATED` which is a promptless symbol. This symbol must be selected by any deprecated setting when enabled. The second setting is `WARN_DEPRECATED` which is a user controlled setting that configures the build system to print a warning when a deprecated feature is enabled. Signed-off-by: Torsten Rasmussen --- Kconfig.zephyr | 14 ++++++++++++++ scripts/kconfig/kconfig.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index e0a8804589e..c9aeab2e20f 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -600,6 +600,20 @@ config BUILD_OUTPUT_META_STATE_PROPAGATE endmenu +config DEPRECATED + bool + help + Symbol that must be selected by a feature or module if it is + considered to be deprecated. + +config WARN_DEPRECATED + bool + default y + prompt "Warn on deprecated usage" + help + Print a warning when the Kconfig tree is parsed if any deprecated + features are enabled. + config EXPERIMENTAL bool help diff --git a/scripts/kconfig/kconfig.py b/scripts/kconfig/kconfig.py index e6cd75e12e5..b9a139d4bb4 100755 --- a/scripts/kconfig/kconfig.py +++ b/scripts/kconfig/kconfig.py @@ -62,6 +62,9 @@ def main(): check_assigned_sym_values(kconf) check_assigned_choice_values(kconf) + if kconf.syms['WARN_DEPRECATED'].tri_value == 2: + check_deprecated(kconf) + if kconf.syms['WARN_EXPERIMENTAL'].tri_value == 2: check_experimental(kconf) @@ -205,6 +208,17 @@ Practices sections of the manual might be helpful too.\ """ +def check_deprecated(kconf): + deprecated = kconf.syms['DEPRECATED'] + dep_expr = deprecated.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'Deprecated symbol {selector_name} is enabled.') + + def check_experimental(kconf): experimental = kconf.syms['EXPERIMENTAL'] dep_expr = experimental.rev_dep