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 <clayton@craftyguy.net> Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-2-ollieparanoid@postmarketos.org%3E
This commit is contained in:
parent
2f9bdb7a66
commit
dbe13fa812
|
@ -44,38 +44,28 @@ def is_in_array(config, option, string):
|
||||||
|
|
||||||
def check_option(component, details, config, config_path_pretty, option,
|
def check_option(component, details, config, config_path_pretty, option,
|
||||||
option_value):
|
option_value):
|
||||||
link = (f"https://wiki.postmarketos.org/wiki/kconfig#CONFIG_{option}")
|
|
||||||
warning_no_details = (f"WARNING: {config_path_pretty} isn't"
|
def warn_ret_false(should_str):
|
||||||
f" configured properly for {component}, run"
|
if details:
|
||||||
f" 'pmbootstrap kconfig check' for 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):
|
if isinstance(option_value, list):
|
||||||
for string in option_value:
|
for string in option_value:
|
||||||
if not is_in_array(config, option, string):
|
if not is_in_array(config, option, string):
|
||||||
if details:
|
return warn_ret_false(f'contain "{string}"')
|
||||||
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
|
|
||||||
elif isinstance(option_value, str):
|
elif isinstance(option_value, str):
|
||||||
if not is_set_str(config, option, option_value):
|
if not is_set_str(config, option, option_value):
|
||||||
if details:
|
return warn_ret_false(f'be set to "{option_value}"')
|
||||||
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
|
|
||||||
elif option_value in [True, False]:
|
elif option_value in [True, False]:
|
||||||
if option_value != is_set(config, option):
|
if option_value != is_set(config, option):
|
||||||
if details:
|
return warn_ret_false("be set" if option_value else "*not* be set")
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("kconfig check code can only handle booleans,"
|
raise RuntimeError("kconfig check code can only handle booleans,"
|
||||||
f" strings and arrays. Given value {option_value}"
|
f" strings and arrays. Given value {option_value}"
|
||||||
|
|
Loading…
Reference in New Issue