merging back to a version that works...
[blender.git] / build_files / cmake / cmake_static_check_splint.py
1 #!/usr/bin/env python
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 CHECKER_IGNORE_PREFIX = [
26     "extern",
27     "intern/moto",
28     ]
29
30 CHECKER_BIN = "splint"
31
32 CHECKER_ARGS = [
33     "-weak",
34     "-posix-lib",
35     "-linelen", "10000",
36     "+ignorequals",
37     "+relaxtypes",
38     "-retvalother",
39     "+matchanyintegral",
40     "+longintegral",
41     "+ignoresigns",
42     "-nestcomment",
43     "-predboolothers",
44     "-ifempty",
45     "-unrecogcomments",
46
47     # we may want to remove these later
48     "-type",
49     "-fixedformalarray",
50     "-fullinitblock",
51     "-fcnuse",
52     "-initallelements",
53     "-castfcnptr",
54     # -forcehints,
55     "-bufferoverflowhigh",  # warns a lot about sprintf()
56
57     # re-definitions, rna causes most of these
58     "-redef",
59     "-syntax",
60
61     # dummy, witjout this splint complains with:
62     #  /usr/include/bits/confname.h:31:27: *** Internal Bug at cscannerHelp.c:2428: Unexpanded macro not function or constant: int _PC_MAX_CANON
63     "-D_PC_MAX_CANON=0",
64     ]
65
66
67 import project_source_info
68 import subprocess
69 import sys
70
71
72 def main():
73     source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX)
74
75     check_commands = []
76     for c, inc_dirs, defs in source_info:
77         cmd = ([CHECKER_BIN] +
78                 CHECKER_ARGS +
79                [c] +
80                [("-I%s" % i) for i in inc_dirs] +
81                [("-D%s" % d) for d in defs]
82               )
83
84         check_commands.append((c, cmd))
85
86     def my_process(i, c, cmd):
87         percent = 100.0 * (i / (len(check_commands) - 1))
88         percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:"
89
90         sys.stdout.write("%s %s\n" % (percent_str, c))
91         sys.stdout.flush()
92
93         return subprocess.Popen(cmd)
94
95     process_functions = []
96     for i, (c, cmd) in enumerate(check_commands):
97         process_functions.append((my_process, (i, c, cmd)))
98
99     project_source_info.queue_processes(process_functions)
100
101
102 if __name__ == "__main__":
103     main()