diff options
author | Simon Glass <sjg@chromium.org> | 2021-12-18 08:09:43 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-01-24 17:36:29 -0500 |
commit | 9d603391a7c3798cf733ad947efe61400fc1a44f (patch) | |
tree | 10e42479fab074cf30e8e608d825044c56bec4d0 | |
parent | a36270861b412049c4c4d1e6fd249af63bdfa3f5 (diff) |
moveconfig: Read the database in a separate function
Move this code out into a function so it can be used elsewhere.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rwxr-xr-x | tools/moveconfig.py | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 8d059be039..4ad892e2c0 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: |