From 3a3559fd094567bac218e9478f1b7e48656d6f85 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 23 Dec 2018 20:40:48 +0100 Subject: menuconfig: Prompt for save if a different .config would be saved Previously, menuconfig.py only prompted for saving the configuration if .config didn't exist or the user changed symbol values within the interface. Also make it prompt for save if Kconfig symbols have been added, removed, or have had their defaults changed, provided it would make the saved .config differ from the loaded one. This usually won't matter for correctness, because loading an outdated configuration performs an implicit olddefconfig, but it's less confusing. Also add a Kconfig.missing_syms attribute that records all assignments to undefined symbols in the most recently loaded .config file. This is needed to implement the check for whether the saved .config would be different. As an unrelated change, always prompt for saving if a .config has been loaded from within the menuconfig interface. The intention is probably often to save the configuration somewhere else, even if it isn't modified. --- menuconfig.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index 4f3bef8..53221dc 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -192,7 +192,7 @@ import sys import textwrap from kconfiglib import Symbol, Choice, MENU, COMMENT, MenuNode, \ - BOOL, STRING, INT, HEX, UNKNOWN, \ + BOOL, TRISTATE, STRING, INT, HEX, UNKNOWN, \ AND, OR, \ expr_str, expr_value, split_expr, \ standard_sc_expr_str, \ @@ -631,8 +631,8 @@ def menuconfig(kconf): _kconf = kconf - # Always prompt for save if the configuration file doesn't exist - _conf_changed = not kconf.load_config() + # Load existing configuration and set _conf_changed True if it is outdated + _conf_changed = _load_config() # Any visible items in the top menu? _show_all = False @@ -678,6 +678,33 @@ def menuconfig(kconf): # curses has been de-initialized. print(curses.wrapper(_menuconfig)) +def _load_config(): + # Loads any existing .config file. See the Kconfig.load_config() docstring. + # + # Returns True if .config is missing or outdated. We always prompt for + # saving the configuration in that case. + + if not _kconf.load_config() or _kconf.missing_syms: + # Either no .config, or assignments to undefined symbols in the + # existing .config (which would get removed when saving) + return True + + for sym in _kconf.unique_defined_syms: + if sym.user_value is None: + if sym.config_string: + # Unwritten symbol + return True + elif sym.type in (BOOL, TRISTATE): + if sym.tri_value != sym.user_value: + # Written bool/tristate symbol, new value + return True + elif sym.str_value != sym.user_value: + # Written string/int/hex symbol, new value + return True + + # No need to prompt for save + return False + # Global variables used below: # # _stdscr: @@ -811,7 +838,7 @@ def _menuconfig(stdscr): continue if _load_dialog(): - _conf_changed = False + _conf_changed = True elif c in ("s", "S"): if _save_dialog(_kconf.write_config, standard_config_filename(), -- cgit v1.2.3