merge bitcoin#24849: Convert lint-logs.sh to Python

This commit is contained in:
Kittywhiskers Van Gogh 2022-04-14 02:43:31 +02:00
parent dbfd0b04e1
commit fe165168ba
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 35 additions and 30 deletions

View File

@ -14,7 +14,7 @@
#include <compat.h> // for Windows API #include <compat.h> // for Windows API
#include <wincrypt.h> #include <wincrypt.h>
#endif #endif
#include <logging.h> // for LogPrintf() #include <logging.h>
#include <randomenv.h> #include <randomenv.h>
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
#include <span.h> #include <span.h>

34
test/lint/lint-logs.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Check that all logs are terminated with '\n'
#
# Some logs are continued over multiple lines. They should be explicitly
# commented with /* Continued */
import re
import sys
from subprocess import check_output
def main():
logs_list = check_output(["git", "grep", "--extended-regexp", r"(LogPrintLevel|LogPrintf?)\(", "--", "*.cpp"], universal_newlines=True, encoding="utf8").splitlines()
unterminated_logs = [line for line in logs_list if not re.search(r'(\\n"|/\* Continued \*/)', line)]
if unterminated_logs != []:
print("All calls to LogPrintf(), LogPrint(), LogPrintLevel(), and WalletLogPrintf() should be terminated with \"\\n\".")
print("")
for line in unterminated_logs:
print(line)
sys.exit(1)
if __name__ == "__main__":
main()

View File

@ -1,29 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) 2018-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Check that all logs are terminated with '\n'
#
# Some logs are continued over multiple lines. They should be explicitly
# commented with /* Continued */
#
# There are some instances of LogPrintf() in comments. Those can be
# ignored
export LC_ALL=C
UNTERMINATED_LOGS=$(git grep --extended-regexp "(LogPrintLevel|LogPrintf?)\(" -- "*.cpp" | \
grep -v '\\n"' | \
grep -v '\.\.\.' | \
grep -v "/\* Continued \*/" | \
grep -v "LogPrint()" | \
grep -v "LogPrintf()")
if [[ ${UNTERMINATED_LOGS} != "" ]]; then
# shellcheck disable=SC2028
echo "All calls to LogPrintf(), LogPrint(), LogPrintLevel(), and WalletLogPrintf() should be terminated with \\n"
echo
echo "${UNTERMINATED_LOGS}"
exit 1
fi