summaryrefslogtreecommitdiff
path: root/util/kconfig_check.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-05-27 14:56:17 -0600
committerCommit Bot <commit-bot@chromium.org>2022-01-28 22:02:51 +0000
commit20b4cbfe1209d6657e9e2a5b15e75b9a47ea3fa0 (patch)
treeb764cb4dd483313fe6d1ea9e40cd255a525c9416 /util/kconfig_check.py
parentda38ba6b8abe06d2c67505b05fdce6b093cadd07 (diff)
downloadchrome-ec-20b4cbfe1209d6657e9e2a5b15e75b9a47ea3fa0.tar.gz
util: Support updating the list of allowed configs
When there are unneeded ad-hoc configs in the 'allowed configs' file, require the user to add their removal to the CL. This helps to ensure that config_allowed.txt reduces in size over time. BUG=b:181323955 BRANCH=none TEST=python3 util/test_kconfig_check.py Change-Id: I56784bd2a147637e2bf98f7e8353584292019f51 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2923232 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'util/kconfig_check.py')
-rwxr-xr-xutil/kconfig_check.py75
1 files changed, 70 insertions, 5 deletions
diff --git a/util/kconfig_check.py b/util/kconfig_check.py
index e61e604c5a..93f3afd53c 100755
--- a/util/kconfig_check.py
+++ b/util/kconfig_check.py
@@ -22,6 +22,7 @@ Use the -d flag to select the second format.
import argparse
import os
+import pathlib
import re
import sys
@@ -35,6 +36,9 @@ try:
except ImportError:
pass
+# Where we put the new config_allowed file
+NEW_ALLOWED_FNAME = pathlib.Path('/tmp/new_config_allowed.txt')
+
def parse_args(argv):
"""Parse the program arguments
@@ -112,6 +116,39 @@ class KconfigCheck:
return sorted(set(configs) - set(kconfigs) - set(allowed))
@classmethod
+ def find_unneeded_adhoc(cls, kconfigs, allowed):
+ """Get a list of ad-hoc CONFIG options that now have Kconfig options
+
+ Arguments and return value should omit the 'CONFIG_' prefix, so
+ CONFIG_LTO should be provided as 'LTO'.
+
+ Args:
+ kconfigs: List of existing Kconfig options
+ allowed: List of allowed CONFIG options
+
+ Returns:
+ List of new CONFIG options, with the CONFIG_ prefix removed
+ """
+ return sorted(set(allowed) & set(kconfigs))
+
+ @classmethod
+ def get_updated_adhoc(cls, unneeded_adhoc, allowed):
+ """Get a list of ad-hoc CONFIG options that are still needed
+
+ Arguments and return value should omit the 'CONFIG_' prefix, so
+ CONFIG_LTO should be provided as 'LTO'.
+
+ Args:
+ unneeded_adhoc: List of ad-hoc CONFIG options to remove
+ allowed: Current list of allowed CONFIG options
+
+ Returns:
+ New version of allowed CONFIG options, with the CONFIG_ prefix
+ removed
+ """
+ return sorted(set(allowed) - set(unneeded_adhoc))
+
+ @classmethod
def read_configs(cls, configs_file, use_defines=False):
"""Read CONFIG options from a file
@@ -208,9 +245,9 @@ class KconfigCheck:
kconfigs += [name for kctype, _, name in found]
return sorted(kconfigs)
- def find_new_adhoc_configs(self, configs_file, srcdir, allowed_file,
- prefix='', use_defines=False, search_paths=None):
- """Find new ad-hoc configs in the configs_file
+ def check_adhoc_configs(self, configs_file, srcdir, allowed_file,
+ prefix='', use_defines=False, search_paths=None):
+ """Find new and unneeded ad-hoc configs in the configs_file
Args:
configs_file: Filename containing CONFIG options to check
@@ -221,12 +258,23 @@ class KconfigCheck:
use_defines: True if each line of the file starts with #define
search_paths: List of project paths to search for Kconfig files, in
addition to the current directory
+
+ Returns:
+ Tuple:
+ List of new ad-hoc CONFIG options (without 'CONFIG_' prefix)
+ List of ad-hoc CONFIG options (without 'CONFIG_' prefix) that
+ are no-longer needed, since they now have an associated
+ Kconfig
+ List of ad-hoc CONFIG options that are still needed, given the
+ current state of the Kconfig options
"""
configs = self.read_configs(configs_file, use_defines)
kconfigs = self.scan_kconfigs(srcdir, prefix, search_paths)
allowed = self.read_allowed(allowed_file)
new_adhoc = self.find_new_adhoc(configs, kconfigs, allowed)
- return new_adhoc
+ unneeded_adhoc = self.find_unneeded_adhoc(kconfigs, allowed)
+ updated_adhoc = self.get_updated_adhoc(unneeded_adhoc, allowed)
+ return new_adhoc, unneeded_adhoc, updated_adhoc
def do_check(self, configs_file, srcdir, allowed_file, prefix, use_defines,
search_paths):
@@ -245,7 +293,7 @@ class KconfigCheck:
Returns:
Exit code: 0 if OK, 1 if a problem was found
"""
- new_adhoc = self.find_new_adhoc_configs(
+ new_adhoc, unneeded_adhoc, updated_adhoc = self.check_adhoc_configs(
configs_file, srcdir, allowed_file, prefix, use_defines,
search_paths)
if new_adhoc:
@@ -265,6 +313,23 @@ Also see details in http://issuetracker.google.com/181253613
To temporarily disable this, use: ALLOW_CONFIG=1 make ...
''', file=sys.stderr)
return 1
+
+ if unneeded_adhoc:
+ with open(NEW_ALLOWED_FNAME, 'w') as out:
+ for config in updated_adhoc:
+ print('CONFIG_%s' % config, file=out)
+ now_in_kconfig = '\n'.join(['CONFIG_%s' % name
+ for name in unneeded_adhoc])
+ print(f'''The following options are now in Kconfig:
+
+{now_in_kconfig}
+
+Please run this to update the list of allowed ad-hoc CONFIGs and include this
+update in your CL:
+
+ cp {NEW_ALLOWED_FNAME} util/config_allowed.txt
+''')
+ return 1
return 0