mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
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>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
79ff743aaa
commit
53a2bbace3
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user