Changeset View
Changeset View
Standalone View
Standalone View
test/lint/check-doc.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2019 The Bitcoin Core developers | # Copyright (c) 2015-2019 The Bitcoin Core developers | ||||
# Copyright (c) 2019 The Bitcoin developers | # Copyright (c) 2019 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
''' | """ | ||||
This checks if all command line args are documented. | This checks if all command line args are documented. | ||||
Return value is 0 to indicate no error. | Return value is 0 to indicate no error. | ||||
Author: @MarcoFalke | Author: @MarcoFalke | ||||
''' | """ | ||||
import glob | import glob | ||||
import re | import re | ||||
from pprint import PrettyPrinter | from pprint import PrettyPrinter | ||||
from subprocess import check_output | from subprocess import check_output | ||||
TOP_LEVEL = 'git rev-parse --show-toplevel' | TOP_LEVEL = "git rev-parse --show-toplevel" | ||||
FOLDERS_SRC = ['/src/**/', '/chronik/**/'] | FOLDERS_SRC = ["/src/**/", "/chronik/**/"] | ||||
FOLDERS_TEST = ['/src/**/test/', '/chronik/test/**/'] | FOLDERS_TEST = ["/src/**/test/", "/chronik/test/**/"] | ||||
EXTENSIONS = ["*.c", "*.h", "*.cpp", "*.cc", "*.hpp"] | EXTENSIONS = ["*.c", "*.h", "*.cpp", "*.cc", "*.hpp"] | ||||
REGEX_ARG = r'(?:ForceSet|SoftSet|Get|Is)(?:Bool|Int)?Args?(?:Set)?\(\s*"(-[^"]+)"' | REGEX_ARG = r'(?:ForceSet|SoftSet|Get|Is)(?:Bool|Int)?Args?(?:Set)?\(\s*"(-[^"]+)"' | ||||
REGEX_DOC = r'AddArg\(\s*"(-[^"=]+?)(?:=|")' | REGEX_DOC = r'AddArg\(\s*"(-[^"=]+?)(?:=|")' | ||||
# list false positive unknows arguments | # list false positive unknows arguments | ||||
SET_FALSE_POSITIVE_UNKNOWNS = { | SET_FALSE_POSITIVE_UNKNOWNS = { | ||||
'-includeconf', | "-includeconf", | ||||
'-regtest', | "-regtest", | ||||
'-testnet', | "-testnet", | ||||
'-zmqpubhashblock', | "-zmqpubhashblock", | ||||
'-zmqpubhashtx', | "-zmqpubhashtx", | ||||
'-zmqpubrawblock', | "-zmqpubrawblock", | ||||
'-zmqpubrawtx', | "-zmqpubrawtx", | ||||
'-zmqpubhashblockhwm', | "-zmqpubhashblockhwm", | ||||
'-zmqpubhashtxhwm', | "-zmqpubhashtxhwm", | ||||
'-zmqpubrawblockhwm', | "-zmqpubrawblockhwm", | ||||
'-zmqpubrawtxhwm', | "-zmqpubrawtxhwm", | ||||
'-zmqpubsequence', | "-zmqpubsequence", | ||||
'-zmqpubsequencehwm', | "-zmqpubsequencehwm", | ||||
} | } | ||||
# list false positive undocumented arguments | # list false positive undocumented arguments | ||||
SET_FALSE_POSITIVE_UNDOCUMENTED = { | SET_FALSE_POSITIVE_UNDOCUMENTED = { | ||||
'-help', | "-help", | ||||
'-h', | "-h", | ||||
'-avalanchepreconsensus', | "-avalanchepreconsensus", | ||||
'-dbcrashratio', | "-dbcrashratio", | ||||
'-enableminerfund', | "-enableminerfund", | ||||
'-forcecompactdb', | "-forcecompactdb", | ||||
'-maxaddrtosend', | "-maxaddrtosend", | ||||
'-parkdeepreorg', | "-parkdeepreorg", | ||||
'-automaticunparking', | "-automaticunparking", | ||||
# Removed arguments that now just print a helpful error message | # Removed arguments that now just print a helpful error message | ||||
'-zapwallettxes', | "-zapwallettxes", | ||||
'-replayprotectionactivationtime', | "-replayprotectionactivationtime", | ||||
# Remove after May 2023 upgrade | # Remove after May 2023 upgrade | ||||
'-wellingtonactivationtime', | "-wellingtonactivationtime", | ||||
} | } | ||||
def main(): | def main(): | ||||
top_level = check_output(TOP_LEVEL, shell=True, | top_level = check_output( | ||||
universal_newlines=True, encoding='utf8').strip() | TOP_LEVEL, shell=True, universal_newlines=True, encoding="utf8" | ||||
).strip() | |||||
source_files = [] | source_files = [] | ||||
test_files = [] | test_files = [] | ||||
for extension in EXTENSIONS: | for extension in EXTENSIONS: | ||||
for folder_src in FOLDERS_SRC: | for folder_src in FOLDERS_SRC: | ||||
source_files += glob.glob(top_level + | source_files += glob.glob( | ||||
folder_src + extension, recursive=True) | top_level + folder_src + extension, recursive=True | ||||
) | |||||
for folder_test in FOLDERS_TEST: | for folder_test in FOLDERS_TEST: | ||||
test_files += glob.glob(top_level + | test_files += glob.glob(top_level + folder_test + extension, recursive=True) | ||||
folder_test + | |||||
extension, recursive=True) | |||||
files = set(source_files) - set(test_files) | files = set(source_files) - set(test_files) | ||||
args_used = set() | args_used = set() | ||||
args_docd = set() | args_docd = set() | ||||
for file in files: | for file in files: | ||||
with open(file, 'r', encoding='utf-8') as f: | with open(file, "r", encoding="utf-8") as f: | ||||
content = f.read() | content = f.read() | ||||
args_used |= set(re.findall(re.compile(REGEX_ARG), content)) | args_used |= set(re.findall(re.compile(REGEX_ARG), content)) | ||||
args_docd |= set(re.findall(re.compile(REGEX_DOC), content)) | args_docd |= set(re.findall(re.compile(REGEX_DOC), content)) | ||||
args_used |= SET_FALSE_POSITIVE_UNKNOWNS | args_used |= SET_FALSE_POSITIVE_UNKNOWNS | ||||
args_docd |= SET_FALSE_POSITIVE_UNDOCUMENTED | args_docd |= SET_FALSE_POSITIVE_UNDOCUMENTED | ||||
args_need_doc = args_used - args_docd | args_need_doc = args_used - args_docd | ||||
args_unknown = args_docd - args_used | args_unknown = args_docd - args_used | ||||
Show All 12 Lines |