kconfiglib: Unclutter symbol strings, avoid redundant writes, misc.

Update kconfiglib, menuconfig, and guiconfig to upstream revision
5c904f4549 to get various improvements and fixes in:

 - Marc Herbert found an issue involving symlinks, absolute paths,
   and rsource that could lead to files not being found. The root cause
   was relpath() assuming that symlink/../bar is the same as bar/, which
   isn't guaranteed.

   Fix it by handling paths in a simpler, more textual way.

 - Propagated dependencies from 'depends on' are now stripped from
   properties when symbols are printed (e.g. in information dialogs and
   generated documentation).

   The printed representation now also uses shorthands.

   Before:

     config A
             bool
             prompt "foo" if C && D
             default A if B && C && D
             depends on C && D

   After:

     config A
             bool "foo"
             default A if B
             depends on C && D

 - Before writing a configuration file or header, Kconfiglib now
   compares the previous contents of the file against the new contents,
   and skips the write if there's no change. This avoids updating the
   modification time, and can save work.

   A message like "No change to '.config'" is shown when there's no
   change.

 - .config now has '# end of <menu>' comments to make it easier to see
   where a menu ends. This was taken from a change to the C tools.

 - load_config() and write_(min_)config() now return a message that can
   be printed with print(kconf.load_config()). This allows messages to
   be reused in e.g. the configuration interfaces (nice now that there's
   also a "No change to..." string).

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
Ulf Magnusson 2019-06-03 19:57:27 +02:00 committed by Carles Cufí
parent 960041bfa5
commit cc14c40a2d
3 changed files with 675 additions and 367 deletions

View file

@ -175,12 +175,12 @@ def menuconfig(kconf):
_create_ui()
# Load existing configuration and check if it's outdated
_set_conf_changed(_load_config())
# Filename to save configuration to
_conf_filename = standard_config_filename()
# Load existing configuration and check if it's outdated
_set_conf_changed(_load_config())
# Filename to save minimal configuration to
_minconf_filename = "defconfig"
@ -238,7 +238,8 @@ def _load_config():
# Returns True if .config is missing or outdated. We always prompt for
# saving the configuration in that case.
if not _kconf.load_config():
print(_kconf.load_config())
if not os.path.exists(_conf_filename):
# No .config
return True
@ -639,7 +640,8 @@ def _set_conf_changed(changed):
global _conf_changed
_conf_changed = changed
_set_status("Modified" if changed else "")
if changed:
_set_status("Modified")
def _update_tree():
@ -1341,7 +1343,6 @@ def _save(_=None):
if _try_save(_kconf.write_config, _conf_filename, "configuration"):
_set_conf_changed(False)
_set_status("Configuration saved to " + _conf_filename)
_tree.focus_set()
@ -1363,7 +1364,6 @@ def _save_as():
break
if _try_save(_kconf.write_config, filename, "configuration"):
_set_status("Configuration saved to " + filename)
_conf_filename = filename
break
@ -1433,7 +1433,6 @@ def _open(_=None):
_update_tree()
_set_status("Configuration loaded from " + filename)
break
_tree.focus_set()
@ -1694,8 +1693,10 @@ def _try_save(save_fn, filename, description):
# String describing the thing being saved
try:
save_fn(filename)
print("{} saved to '{}'".format(description, filename))
# save_fn() returns a message to print
msg = save_fn(filename)
_set_status(msg)
print(msg)
return True
except (OSError, IOError) as e:
messagebox.showerror(
@ -1714,8 +1715,9 @@ def _try_load(filename):
# Configuration file to load
try:
_kconf.load_config(filename)
print("configuration loaded from " + filename)
msg = _kconf.load_config(filename)
_set_status(msg)
print(msg)
return True
except (OSError, IOError) as e:
messagebox.showerror(
@ -2222,7 +2224,7 @@ def _kconfig_def_info(item):
nodes = [item] if isinstance(item, MenuNode) else item.nodes
s = "Kconfig definition{}, with propagated dependencies\n" \
s = "Kconfig definition{}, with parent deps. propagated to 'depends on'\n" \
.format("s" if len(nodes) > 1 else "")
s += (len(s) - 1)*"="

File diff suppressed because it is too large Load diff

View file

@ -650,12 +650,12 @@ def menuconfig(kconf):
_kconf = kconf
# Load existing configuration and set _conf_changed True if it is outdated
_conf_changed = _load_config()
# Filename to save configuration to
_conf_filename = standard_config_filename()
# Load existing configuration and set _conf_changed True if it is outdated
_conf_changed = _load_config()
# Filename to save minimal configuration to
_minconf_filename = "defconfig"
@ -673,7 +673,7 @@ def menuconfig(kconf):
# Disable warnings. They get mangled in curses mode, and we deal with
# errors ourselves.
kconf.disable_warnings()
kconf.warn = False
# Make curses use the locale settings specified in the environment
locale.setlocale(locale.LC_ALL, "")
@ -710,7 +710,8 @@ def _load_config():
# Returns True if .config is missing or outdated. We always prompt for
# saving the configuration in that case.
if not _kconf.load_config():
print(_kconf.load_config())
if not os.path.exists(_conf_filename):
# No .config
return True
@ -922,8 +923,10 @@ def _quit_dialog():
return None
if c == "y":
if _try_save(_kconf.write_config, _conf_filename, "configuration"):
return "Configuration saved to '{}'".format(_conf_filename)
# Returns a message to print
msg = _try_save(_kconf.write_config, _conf_filename, "configuration")
if msg:
return msg
elif c == "n":
return "Configuration ({}) was not saved".format(_conf_filename)
@ -1858,29 +1861,33 @@ def _save_dialog(save_fn, default_filename, description):
filename = os.path.expanduser(filename)
if _try_save(save_fn, filename, description):
_msg("Success", "{} saved to {}".format(description, filename))
msg = _try_save(save_fn, filename, description)
if msg:
_msg("Success", msg)
return filename
def _try_save(save_fn, filename, description):
# Tries to save a configuration file. Pops up an error and returns False on
# failure.
# Tries to save a configuration file. Returns a message to print on
# success.
#
# save_fn:
# Function to call with 'filename' to save the file
#
# description:
# String describing the thing being saved
#
# Return value:
# A message to print on success, and None on failure
try:
save_fn(filename)
return True
# save_fn() returns a message to print
return save_fn(filename)
except OSError as e:
_error("Error saving {} to '{}'\n\n{} (errno: {})"
.format(description, e.filename, e.strerror,
errno.errorcode[e.errno]))
return False
return None
def _key_dialog(title, text, keys):
@ -2739,7 +2746,7 @@ def _kconfig_def_info(item):
nodes = [item] if isinstance(item, MenuNode) else item.nodes
s = "Kconfig definition{}, with propagated dependencies\n" \
s = "Kconfig definition{}, with parent deps. propagated to 'depends on'\n" \
.format("s" if len(nodes) > 1 else "")
s += (len(s) - 1)*"="