From dbe13fa81220d62d6f5002d40948d5d4c0c98735 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 12 Mar 2023 16:13:08 +0100 Subject: [PATCH] pmb.parse.kconfig.check_option: refactor Deduplicate the code for printing warnings and tweak it slightly: * Shorten ".See <$url> for details." to ": $url". * Include the component in the detailed output too. Reviewed-by: Clayton Craft Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-2-ollieparanoid@postmarketos.org%3E --- pmb/parse/kconfig.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/pmb/parse/kconfig.py b/pmb/parse/kconfig.py index 3437b544..d84ed830 100644 --- a/pmb/parse/kconfig.py +++ b/pmb/parse/kconfig.py @@ -44,38 +44,28 @@ def is_in_array(config, option, string): def check_option(component, details, config, config_path_pretty, option, option_value): - link = (f"https://wiki.postmarketos.org/wiki/kconfig#CONFIG_{option}") - warning_no_details = (f"WARNING: {config_path_pretty} isn't" - f" configured properly for {component}, run" - f" 'pmbootstrap kconfig check' for details!") + + def warn_ret_false(should_str): + if details: + logging.warning(f"WARNING: {config_path_pretty}: CONFIG_{option}" + f" should {should_str} ({component}):" + f" https://wiki.postmarketos.org/wiki/kconfig#CONFIG_{option}") + else: + logging.warning(f"WARNING: {config_path_pretty} isn't" + f" configured properly ({component}), run" + f" 'pmbootstrap kconfig check' for details!") + return False + if isinstance(option_value, list): for string in option_value: if not is_in_array(config, option, string): - if details: - logging.info(f"WARNING: {config_path_pretty}:" - f' CONFIG_{option} should contain "{string}".' - f" See <{link}> for details.") - else: - logging.warning(warning_no_details) - return False + return warn_ret_false(f'contain "{string}"') elif isinstance(option_value, str): if not is_set_str(config, option, option_value): - if details: - logging.info(f"WARNING: {config_path_pretty}: CONFIG_{option}" - f' should be set to "{option_value}".' - f" See <{link}> for details.") - else: - logging.warning(warning_no_details) - return False + return warn_ret_false(f'be set to "{option_value}"') elif option_value in [True, False]: if option_value != is_set(config, option): - if details: - should = "should" if option_value else "should *not*" - logging.info(f"WARNING: {config_path_pretty}: CONFIG_{option}" - f" {should} be set. See <{link}> for details.") - else: - logging.warning(warning_no_details) - return False + return warn_ret_false("be set" if option_value else "*not* be set") else: raise RuntimeError("kconfig check code can only handle booleans," f" strings and arrays. Given value {option_value}"