2012-11-26 13:58:06 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-09-16 06:58:20 +00:00
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
2011-09-16 08:20:21 +00:00
|
|
|
import project_source_info
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
2021-10-04 13:12:36 +11:00
|
|
|
import tempfile
|
2011-09-16 08:20:21 +00:00
|
|
|
|
2021-04-13 21:12:17 +10:00
|
|
|
from typing import (
|
|
|
|
Any,
|
|
|
|
List,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-11-07 01:00:27 +00:00
|
|
|
USE_QUIET = (os.environ.get("QUIET", None) is not None)
|
|
|
|
|
2011-09-16 06:58:20 +00:00
|
|
|
CHECKER_IGNORE_PREFIX = [
|
|
|
|
"extern",
|
2016-07-30 18:15:16 +10:00
|
|
|
]
|
2011-09-16 06:58:20 +00:00
|
|
|
|
|
|
|
CHECKER_BIN = "cppcheck"
|
|
|
|
|
|
|
|
CHECKER_ARGS = [
|
2011-09-16 14:02:44 +00:00
|
|
|
# not sure why this is needed, but it is.
|
2011-09-22 04:41:12 +00:00
|
|
|
"-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"),
|
2012-02-04 11:10:41 +00:00
|
|
|
"--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
|
2013-04-01 07:57:33 +00:00
|
|
|
"--max-configs=1", # speeds up execution
|
2011-09-16 06:58:20 +00:00
|
|
|
# "--check-config", # when includes are missing
|
2013-04-01 07:57:33 +00:00
|
|
|
"--enable=all", # if you want sixty hundred pedantic suggestions
|
2021-10-04 13:12:36 +11:00
|
|
|
|
2021-10-04 13:12:37 +11:00
|
|
|
# Quiet output, otherwise all defines/includes are printed (overly verbose).
|
|
|
|
# Only enable this for troubleshooting (if defines are not set as expected for example).
|
|
|
|
"--quiet",
|
|
|
|
|
2021-10-04 13:12:36 +11:00
|
|
|
# NOTE: `--cppcheck-build-dir=<dir>` is added later as a temporary directory.
|
2016-07-30 18:15:16 +10:00
|
|
|
]
|
2011-09-16 06:58:20 +00:00
|
|
|
|
2012-12-09 14:17:33 +00:00
|
|
|
if USE_QUIET:
|
|
|
|
CHECKER_ARGS.append("--quiet")
|
|
|
|
|
2011-09-20 18:29:19 +00:00
|
|
|
|
2021-10-04 13:12:36 +11:00
|
|
|
def cppcheck() -> None:
|
2011-09-16 06:58:20 +00:00
|
|
|
source_info = project_source_info.build_info(ignore_prefix_list=CHECKER_IGNORE_PREFIX)
|
2013-08-10 23:27:42 +00:00
|
|
|
source_defines = project_source_info.build_defines_as_args()
|
2011-09-16 06:58:20 +00:00
|
|
|
|
|
|
|
check_commands = []
|
|
|
|
for c, inc_dirs, defs in source_info:
|
2021-04-13 21:12:17 +10:00
|
|
|
cmd = (
|
|
|
|
[CHECKER_BIN] +
|
|
|
|
CHECKER_ARGS +
|
|
|
|
[c] +
|
|
|
|
[("-I%s" % i) for i in inc_dirs] +
|
|
|
|
[("-D%s" % d) for d in defs] +
|
|
|
|
source_defines
|
|
|
|
)
|
2011-09-16 06:58:20 +00:00
|
|
|
|
|
|
|
check_commands.append((c, cmd))
|
|
|
|
|
2011-09-22 04:41:12 +00:00
|
|
|
process_functions = []
|
2011-09-26 15:39:15 +00:00
|
|
|
|
2021-04-13 21:12:17 +10:00
|
|
|
def my_process(i: int, c: str, cmd: List[str]) -> subprocess.Popen[Any]:
|
2012-11-07 01:00:27 +00:00
|
|
|
if not USE_QUIET:
|
2014-03-29 11:25:44 +11:00
|
|
|
percent = 100.0 * (i / len(check_commands))
|
2012-11-07 01:00:27 +00:00
|
|
|
percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
|
2011-09-20 18:29:19 +00:00
|
|
|
|
2012-11-07 01:00:27 +00:00
|
|
|
sys.stdout.flush()
|
2021-10-04 13:12:37 +11:00
|
|
|
sys.stdout.write("%s %s\n" % (
|
|
|
|
percent_str,
|
|
|
|
os.path.relpath(c, project_source_info.SOURCE_DIR)
|
|
|
|
))
|
2011-09-16 06:58:20 +00:00
|
|
|
|
2011-09-22 04:41:12 +00:00
|
|
|
return subprocess.Popen(cmd)
|
|
|
|
|
|
|
|
for i, (c, cmd) in enumerate(check_commands):
|
|
|
|
process_functions.append((my_process, (i, c, cmd)))
|
|
|
|
|
|
|
|
project_source_info.queue_processes(process_functions)
|
2011-09-16 06:58:20 +00:00
|
|
|
|
2012-12-09 14:17:33 +00:00
|
|
|
print("Finished!")
|
|
|
|
|
2011-09-16 06:58:20 +00:00
|
|
|
|
2021-10-04 13:12:36 +11:00
|
|
|
def main() -> None:
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
|
CHECKER_ARGS.append("--cppcheck-build-dir=" + temp_dir)
|
|
|
|
cppcheck()
|
|
|
|
|
|
|
|
|
2011-09-16 06:58:20 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|