partial revert dash#4807: enable more multi-threading and caching in linters

reverts:
- 3e6385eaa8 (only `run-lint-format-strings.py`)
This commit is contained in:
Kittywhiskers Van Gogh 2024-11-23 15:02:36 +00:00
parent 7864c21645
commit a0b051b4ef
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD

View File

@ -11,8 +11,6 @@
import argparse import argparse
import re import re
import sys import sys
from functools import partial
from multiprocessing import Pool
FALSE_POSITIVES = [ FALSE_POSITIVES = [
("src/batchedlogger.h", "strprintf(fmt, args...)"), ("src/batchedlogger.h", "strprintf(fmt, args...)"),
@ -265,8 +263,17 @@ def count_format_specifiers(format_string):
return n return n
def handle_filename(filename, args): def main():
parser = argparse.ArgumentParser(description="This program checks that the number of arguments passed "
"to a variadic format string function matches the number of format "
"specifiers in the format string.")
parser.add_argument("--skip-arguments", type=int, help="number of arguments before the format string "
"argument (e.g. 1 in the case of fprintf)", default=0)
parser.add_argument("function_name", help="function name (e.g. fprintf)", default=None)
parser.add_argument("file", nargs="*", help="C++ source code file (e.g. foo.cpp)")
args = parser.parse_args()
exit_code = 0 exit_code = 0
for filename in args.file:
with open(filename, "r", encoding="utf-8") as f: with open(filename, "r", encoding="utf-8") as f:
for function_call_str in parse_function_calls(args.function_name, f.read()): for function_call_str in parse_function_calls(args.function_name, f.read()):
parts = parse_function_call_and_arguments(args.function_name, function_call_str) parts = parse_function_call_and_arguments(args.function_name, function_call_str)
@ -284,24 +291,7 @@ def handle_filename(filename, args):
exit_code = 1 exit_code = 1
print("{}: Expected {} argument(s) after format string but found {} argument(s): {}".format(f.name, format_specifier_count, argument_count, relevant_function_call_str)) print("{}: Expected {} argument(s) after format string but found {} argument(s): {}".format(f.name, format_specifier_count, argument_count, relevant_function_call_str))
continue continue
return exit_code sys.exit(exit_code)
def main():
parser = argparse.ArgumentParser(description="This program checks that the number of arguments passed "
"to a variadic format string function matches the number of format "
"specifiers in the format string.")
parser.add_argument("--skip-arguments", type=int, help="number of arguments before the format string "
"argument (e.g. 1 in the case of fprintf)", default=0)
parser.add_argument("function_name", help="function name (e.g. fprintf)", default=None)
parser.add_argument("file", nargs="*", help="C++ source code file (e.g. foo.cpp)")
args = parser.parse_args()
exit_codes = []
with Pool(8) as pool:
exit_codes = pool.map(partial(handle_filename, args=args), args.file)
sys.exit(max(exit_codes))
if __name__ == "__main__": if __name__ == "__main__":