diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2015-07-15 19:07:30 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-07-17 00:07:38 +0000 |
commit | 53a2bbace35a1c55f595b9f052b627a7339c74c5 (patch) | |
tree | 61a59ec057e5ad779977b7aa8883717806dfe5fa | |
parent | 79ff743aaa59b749b9ec741bc88a4fe88e5d4ed6 (diff) | |
download | chrome-ec-53a2bbace35a1c55f595b9f052b627a7339c74c5.tar.gz |
util: small config_option_check.py improvements
As of now this check results in false positives, for instance
'CONFIG_' found in the comments results in an error report.
This patch makes the script a bit more robust:
- consider only those options mentioned in include/config.h as
explicitly defined or undefined.
- do not scan include/config.h for new added CONFIG_ options
- ignore comments in .mk files
Ideally the script should be scanning only added lines of code and
much smarter about what should be considered a comment and what files
should be examined.
BRANCH=none
BUG=chromium:510672
TEST=the false positives triggered by comments in various build.mk
files are gone now. Adding an undescribed CONFIG_xxx text still
triggers the error.
Change-Id: Ib9858775bcd9899dec629682a1c7965e7c2fec96
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/285926
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rwxr-xr-x | util/config_option_check.py | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/util/config_option_check.py b/util/config_option_check.py index 149f256fb6..4ce6364d13 100755 --- a/util/config_option_check.py +++ b/util/config_option_check.py @@ -12,6 +12,9 @@ import re import os import argparse +# Master file which is supposed to include all CONFIG_xxxx descriptions. +CONFIG_FILE = 'include/config.h' + def find_files_to_check(args): """Returns a list of files to check.""" file_list = [] @@ -35,37 +38,55 @@ def find_files_to_check(args): def obtain_current_config_options(): """Obtains current config options from include/config.h""" config_options = [] - config_option_re = re.compile(r'\s+(CONFIG_[a-zA-Z0-9_]*)\s*') - with open('include/config.h', 'r') as config_file: + config_option_re = re.compile(r'^#(define|undef)\s+(CONFIG_[A-Z0-9_]+)') + with open(CONFIG_FILE, 'r') as config_file: for line in config_file: - match = re.search(config_option_re, line) - if match: - if match.group(1) not in config_options: - config_options.append(match.group(1)) + result = config_option_re.search(line) + if not result: + continue + word = result.groups()[1] + if word not in config_options: + config_options.append(word) return config_options def print_missing_config_options(file_list, config_options): - """Searches through all files in file_list for missing config options.""" + """Searches through all files in file_list for missing config options. + + TODO: make it search only added lines instead. + """ missing_config_option = False print_banner = True # Determine longest CONFIG_* length to be used for formatting. max_option_length = max(len(option) for option in config_options) config_option_re = re.compile(r'\s+(CONFIG_[a-zA-Z0-9_]*)\s*') for f in file_list: + if os.path.realpath(f) == os.path.realpath(CONFIG_FILE): + continue + extension = os.path.splitext(f)[1] + # Do not examine files which are not likely to actually use CONFIG_xxx. + # TODO: this list should be fine tuned. + if not extension in ('.c', '.h', '.mk', '.inc') and not 'Makefile' in f: + continue with open(f, 'r') as cur_file: line_num = 0 for line in cur_file: line_num += 1 + if extension == '.mk' and line.startswith('#'): + # Ignore pattern found in comments. TODO: this needs to be way more + # robust: different file extensions require different comment + # encapsulation logic, the comment could be not starting in the + # first column, etc. + continue match = re.search(config_option_re, line) if match: if match.group(1) not in config_options: missing_config_option = True # Print the banner once. if print_banner: - print('Please add all new config options to include/config.h' \ - ' along with a description of the option.\n\n' \ - 'The following config options were found to be missing ' \ - 'from include/config.h.\n') + print('The following config options were found to be missing ' + 'from %s.\n' + 'Please add new config options there along with ' + 'descriptions.\n\n' % CONFIG_FILE) print_banner = False # Print the misssing config option. print('> %-*s %s:%s' % (max_option_length, match.group(1), f, |