Build info: Ensure hash length is same across all platforms and has no conflicts
[blender.git] / build_files / cmake / cmake_static_check_cppcheck.py
1 #!/usr/bin/env python3
2
3 # ***** BEGIN GPL LICENSE BLOCK *****
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # Contributor(s): Campbell Barton
20 #
21 # ***** END GPL LICENSE BLOCK *****
22
23 # <pep8 compliant>
24
25 import project_source_info
26 import subprocess
27 import sys
28 import os
29
30 USE_QUIET = (os.environ.get("QUIET", None) is not None)
31
32 CHECKER_IGNORE_PREFIX = [
33     "extern",
34     "intern/moto",
35 ]
36
37 CHECKER_BIN = "cppcheck"
38
39 CHECKER_ARGS = [
40     # not sure why this is needed, but it is.
41     "-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"),
42     "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
43     "--max-configs=1",  # speeds up execution
44     #  "--check-config", # when includes are missing
45     "--enable=all",  # if you want sixty hundred pedantic suggestions
46 ]
47
48 if USE_QUIET:
49     CHECKER_ARGS.append("--quiet")
50
51
52 def main():
53     source_info = project_source_info.build_info(ignore_prefix_list=CHECKER_IGNORE_PREFIX)
54     source_defines = project_source_info.build_defines_as_args()
55
56     check_commands = []
57     for c, inc_dirs, defs in source_info:
58         cmd = ([CHECKER_BIN] +
59                CHECKER_ARGS +
60                [c] +
61                [("-I%s" % i) for i in inc_dirs] +
62                [("-D%s" % d) for d in defs] +
63                source_defines
64                )
65
66         check_commands.append((c, cmd))
67
68     process_functions = []
69
70     def my_process(i, c, cmd):
71         if not USE_QUIET:
72             percent = 100.0 * (i / len(check_commands))
73             percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
74
75             sys.stdout.flush()
76             sys.stdout.write("%s " % percent_str)
77
78         return subprocess.Popen(cmd)
79
80     for i, (c, cmd) in enumerate(check_commands):
81         process_functions.append((my_process, (i, c, cmd)))
82
83     project_source_info.queue_processes(process_functions)
84
85     print("Finished!")
86
87
88 if __name__ == "__main__":
89     main()