[PATCH 2/5] moveconfig: Read the database in a separate function

Simon Glass sjg at chromium.org
Sat Dec 18 16:09:43 CET 2021


Move this code out into a function so it can be used elsewhere.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/moveconfig.py | 78 ++++++++++++++++++++++++++++-----------------
 1 file changed, 49 insertions(+), 29 deletions(-)

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 8d059be039d..4ad892e2c0c 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -1339,6 +1339,54 @@ IMPLY_FLAGS = {
         'Allow Kconfig options outside arch/ and /board/ to imply'],
 };
 
+
+def read_database():
+    """Read in the config database
+
+    Returns:
+        tuple:
+            set of all config options seen (each a str)
+            set of all defconfigs seen (each a str)
+            dict of configs for each defconfig:
+                key: defconfig name, e.g. "MPC8548CDS_legacy_defconfig"
+                value: dict:
+                    key: CONFIG option
+                    value: Value of option
+            dict of defconfigs for each config:
+                key: CONFIG option
+                value: set of boards using that option
+
+    """
+    configs = {}
+
+    # key is defconfig name, value is dict of (CONFIG_xxx, value)
+    config_db = {}
+
+    # Set of all config options we have seen
+    all_configs = set()
+
+    # Set of all defconfigs we have seen
+    all_defconfigs = set()
+
+    defconfig_db = collections.defaultdict(set)
+    with open(CONFIG_DATABASE) as fd:
+        for line in fd.readlines():
+            line = line.rstrip()
+            if not line:  # Separator between defconfigs
+                config_db[defconfig] = configs
+                all_defconfigs.add(defconfig)
+                configs = {}
+            elif line[0] == ' ':  # CONFIG line
+                config, value = line.strip().split('=', 1)
+                configs[config] = value
+                defconfig_db[config].add(defconfig)
+                all_configs.add(config)
+            else:  # New defconfig
+                defconfig = line
+
+    return all_configs, all_defconfigs, config_db, defconfig_db
+
+
 def do_imply_config(config_list, add_imply, imply_flags, skip_added,
                     check_kconfig=True, find_superset=False):
     """Find CONFIG options which imply those in the list
@@ -1385,35 +1433,7 @@ def do_imply_config(config_list, add_imply, imply_flags, skip_added,
     if add_imply and add_imply != 'all':
         add_imply = add_imply.split(',')
 
-    # key is defconfig name, value is dict of (CONFIG_xxx, value)
-    config_db = {}
-
-    # Holds a dict containing the set of defconfigs that contain each config
-    # key is config, value is set of defconfigs using that config
-    defconfig_db = collections.defaultdict(set)
-
-    # Set of all config options we have seen
-    all_configs = set()
-
-    # Set of all defconfigs we have seen
-    all_defconfigs = set()
-
-    # Read in the database
-    configs = {}
-    with open(CONFIG_DATABASE) as fd:
-        for line in fd.readlines():
-            line = line.rstrip()
-            if not line:  # Separator between defconfigs
-                config_db[defconfig] = configs
-                all_defconfigs.add(defconfig)
-                configs = {}
-            elif line[0] == ' ':  # CONFIG line
-                config, value = line.strip().split('=', 1)
-                configs[config] = value
-                defconfig_db[config].add(defconfig)
-                all_configs.add(config)
-            else:  # New defconfig
-                defconfig = line
+    all_configs, all_defconfigs, config_db, defconfig_db = read_database()
 
     # Work through each target config option in turn, independently
     for config in config_list:
-- 
2.34.1.173.g76aa8bc2d0-goog



More information about the U-Boot mailing list