summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-05-19 15:51:56 +0900
committerMasahiro Yamada <yamada.masahiro@socionext.com>2016-06-13 07:46:28 +0900
commitcc008299f8526dbbd2cb9485799218a67757c4e2 (patch)
tree12c451cfd1b82a89fb04d2b9e7bca928732aedff /tools
parentc5e60fd4954ccbeee4d7cd783b338c4783604547 (diff)
downloadblackbird-obmc-uboot-cc008299f8526dbbd2cb9485799218a67757c4e2.tar.gz
blackbird-obmc-uboot-cc008299f8526dbbd2cb9485799218a67757c4e2.zip
tools: moveconfig: do not rely on type and default value given by users
Commit 96464badc794 ("moveconfig: Always run savedefconfig on the moved config") changed the work flow of this tool a lot from the original intention when this tool was designed first. Since then, before running this tool, users must edit the Kconfig to add the menu entries for the configs they are moving. It means users had already specified the type and the default value for each CONFIG via its Kconfig entry. Nevertheless, users are still required to dictate the same type and the default value in the input file. This is tedious to use. So, my idea here is to deprecate the latter. Before moving forward with it, there is one issue worth mentioning; since the savedefconfig re-sync was introduced, this tool has not been able to move bool options with "default y". Joe sent a patch to solve this problem about a year ago, but it was not applied for some reasons. Now, he came back with an updated patch, so this problem will be fixed soon. For other use cases, I see no reason to require redundant dictation in the input file. Instead, the tool can know the types and default values by parsing the .config file. This commit changes the tool to use the CONFIG names, but ignore the types and default values given by the input file. This commit also fixes one bug. Prior to this commit, it could not move an integer-typed CONFIG with value 1. For example, assume we are moving CONFIG_CONS_INDEX. Please note this is an integer type option. Many board headers define this CONFIG as 1. #define CONFIG_CONS_INDEX 1 It will be converted to CONFIG_CONS_INDEX=y and moved to include/autoconf.mk, by the tools/scripts/define2mk.sed. It will cause "make savedefconfig" to fail due to the type conflict. This commit takes care of it by detecting the type and converting the CONFIG value correctly. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/moveconfig.py88
1 files changed, 43 insertions, 45 deletions
diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index caf2a82bf1..96834c4f77 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -70,13 +70,17 @@ It looks like one of the followings:
- Move 'CONFIG_... '
This config option was moved to the defconfig
- - Default value 'CONFIG_...'. Do nothing.
- The value of this option is the same as default.
- We do not have to add it to the defconfig.
-
- - 'CONFIG_...' already exists in Kconfig. Do nothing.
- This config option is already defined in Kconfig.
- We do not need/want to touch it.
+ - CONFIG_... is not defined in Kconfig. Do nothing.
+ The entry for this CONFIG was not found in Kconfig.
+ There are two common cases:
+ - You forgot to create an entry for the CONFIG before running
+ this tool, or made a typo in a CONFIG passed to this tool.
+ - The entry was hidden due to unmet 'depends on'.
+ This is correct behavior.
+
+ - 'CONFIG_...' is the same as the define in Kconfig. Do nothing.
+ The define in the config header matched the one in Kconfig.
+ We do not need to touch it.
- Undefined. Do nothing.
This config option was not found in the config header.
@@ -216,9 +220,8 @@ STATE_AUTOCONF = 2
STATE_SAVEDEFCONFIG = 3
ACTION_MOVE = 0
-ACTION_DEFAULT_VALUE = 1
-ACTION_ALREADY_EXIST = 2
-ACTION_UNDEFINED = 3
+ACTION_NO_ENTRY = 1
+ACTION_NO_CHANGE = 2
COLOR_BLACK = '0;30'
COLOR_RED = '0;31'
@@ -464,7 +467,7 @@ class KconfigParser:
return CROSS_COMPILE.get(arch, None)
- def parse_one_config(self, config_attr, defconfig_lines, autoconf_lines):
+ def parse_one_config(self, config_attr, dotconfig_lines, autoconf_lines):
"""Parse .config, defconfig, include/autoconf.mk for one config.
This function looks for the config options in the lines from
@@ -474,7 +477,7 @@ class KconfigParser:
Arguments:
config_attr: A dictionary including the name, the type,
and the default value of the target config.
- defconfig_lines: lines from the original defconfig file.
+ dotconfig_lines: lines from the .config file.
autoconf_lines: lines from the include/autoconf.mk file.
Returns:
@@ -484,42 +487,40 @@ class KconfigParser:
config = config_attr['config']
not_set = '# %s is not set' % config
- if config_attr['type'] in ('bool', 'tristate') and \
- config_attr['default'] == 'n':
- default = not_set
- else:
- default = config + '=' + config_attr['default']
-
- for line in defconfig_lines:
+ for line in dotconfig_lines:
line = line.rstrip()
if line.startswith(config + '=') or line == not_set:
- return (ACTION_ALREADY_EXIST, line)
-
- if config_attr['type'] in ('bool', 'tristate'):
- value = not_set
+ old_val = line
+ break
else:
- value = '(undefined)'
+ return (ACTION_NO_ENTRY, config)
for line in autoconf_lines:
line = line.rstrip()
if line.startswith(config + '='):
- value = line
+ new_val = line
break
-
- if value == default:
- action = ACTION_DEFAULT_VALUE
- elif value == '(undefined)':
- action = ACTION_UNDEFINED
else:
- action = ACTION_MOVE
+ new_val = not_set
+
+ if old_val == new_val:
+ return (ACTION_NO_CHANGE, new_val)
+
+ # If this CONFIG is neither bool nor trisate
+ if old_val[-2:] != '=y' and old_val[-2:] != '=m' and old_val != not_set:
+ # tools/scripts/define2mk.sed changes '1' to 'y'.
+ # This is a problem if the CONFIG is int type.
+ # Check the type in Kconfig and handle it correctly.
+ if new_val[-2:] == '=y':
+ new_val = new_val[:-1] + '1'
- return (action, value)
+ return (ACTION_MOVE, new_val)
def update_dotconfig(self, defconfig):
"""Parse files for the config options and update the .config.
- This function parses the given defconfig, the generated .config
- and include/autoconf.mk searching the target options.
+ This function parses the generated .config and include/autoconf.mk
+ searching the target options.
Move the config option(s) to the .config as needed.
Also, display the log to show what happened to the .config.
@@ -527,19 +528,18 @@ class KconfigParser:
defconfig: defconfig name.
"""
- defconfig_path = os.path.join('configs', defconfig)
dotconfig_path = os.path.join(self.build_dir, '.config')
autoconf_path = os.path.join(self.build_dir, 'include', 'autoconf.mk')
results = []
- with open(defconfig_path) as f:
- defconfig_lines = f.readlines()
+ with open(dotconfig_path) as f:
+ dotconfig_lines = f.readlines()
with open(autoconf_path) as f:
autoconf_lines = f.readlines()
for config_attr in self.config_attrs:
- result = self.parse_one_config(config_attr, defconfig_lines,
+ result = self.parse_one_config(config_attr, dotconfig_lines,
autoconf_lines)
results.append(result)
@@ -549,15 +549,13 @@ class KconfigParser:
if action == ACTION_MOVE:
actlog = "Move '%s'" % value
log_color = COLOR_LIGHT_GREEN
- elif action == ACTION_DEFAULT_VALUE:
- actlog = "Default value '%s'. Do nothing." % value
+ elif action == ACTION_NO_ENTRY:
+ actlog = "%s is not defined in Kconfig. Do nothing." % value
log_color = COLOR_LIGHT_BLUE
- elif action == ACTION_ALREADY_EXIST:
- actlog = "'%s' already defined in Kconfig. Do nothing." % value
+ elif action == ACTION_NO_CHANGE:
+ actlog = "'%s' is the same as the define in Kconfig. Do nothing." \
+ % value
log_color = COLOR_LIGHT_PURPLE
- elif action == ACTION_UNDEFINED:
- actlog = "Undefined. Do nothing."
- log_color = COLOR_DARK_GRAY
else:
sys.exit("Internal Error. This should not happen.")
OpenPOWER on IntegriCloud