[U-Boot] [PATCH 08/21] tools: moveconfig: do not rely on type and default value given by users

Masahiro Yamada yamada.masahiro at socionext.com
Thu May 19 08:51:56 CEST 2016


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 the Kconfig entries.  Nevertheless, users are still required to
dictate the same type and the default value in each line of the input
file.  So, my idea here is to deprecate the latter.

Before moving forward with it, there is one thing worth mentioning;
since the savedefconfig re-sync was introduced, there is a case this
tool can not handle correctly.

Let's say we are moving CONFIG_FOO from board headers to Kconfig,
and we want to make it "default y" option.  First, we are supposed
to create an entry:

  config FOO
          bool "foo"
          default y

CONFIG_FOO=y will appear in the .config for every processed defconfig.
It will be duplicated to the include/autoconf.mk as well unless the
board explicitly #undef's it.  Therefore, the defconfig without
"#define CONFIG_FOO" or "#undef CONFIG_FOO" that should be converted
to "unset" would be misconverted to "=y".

Anyway, this has been a problem for a while.  Yet, I am not inclined
to revert that commit because the "create a Kconfig entry beforehand,
and sync with savedefconfig" approach has been successful in practical
use cases.  I will come back to this problem with a different solution
in a few commits later.

For other use cases, I see no reason to require redundant dictation
in the input file of this tool.  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.  Before this commit, the tool could
not move a integer-typed CONFIG with value 1.

For example, assume we are moving CONFIG_CONS_INDEX.  Please note
this is a 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 at socionext.com>
---

 tools/moveconfig.py | 88 ++++++++++++++++++++++++++---------------------------
 1 file changed, 43 insertions(+), 45 deletions(-)

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 5e78266..ee0afbd 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.")
 
-- 
1.9.1



More information about the U-Boot mailing list