1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import sys
25import shlex
26import subprocess
27
28SRC_DIRS = [
29	"delibs/debase",
30	"delibs/deimage",
31	"delibs/depool",
32	"delibs/dethread",
33	"delibs/deutil",
34	"delibs/decpp",
35
36	"deqp/execserver",
37	"deqp/executor",
38	"deqp/modules/candytest",
39	"deqp/modules/egl",
40	"deqp/modules/gles2",
41	"deqp/modules/gles3",
42	"deqp/modules/gles31",
43	"deqp/modules/gl3",
44	"deqp/modules/glshared",
45	"deqp/modules/glusecases",
46	"deqp/modules/opencl",
47	"deqp/modules/internal",
48	"deqp/framework/qphelper",
49	"deqp/framework/common",
50	"deqp/framework/egl",
51	"deqp/framework/opengl",
52	"deqp/framework/opencl",
53	"deqp/framework/platform",
54	"deqp/framework/randomshaders",
55	"deqp/framework/referencerenderer",
56	"deqp/wrappers/dynlib",
57	"deqp/wrappers/gles3",
58
59	"gapir",
60]
61
62INCLUDE_DIRS = [
63	"delibs/libpng",
64	"delibs/libzip",
65	"delibs/zlib",
66
67	"deqp/wrappers/dynlib/inc",
68	"deqp/wrappers/gles3/inc",
69	"deqp/modules/gles2/accuracy",
70	"deqp/modules/gles2/functional",
71	"deqp/modules/gles2/performance",
72	"deqp/modules/gles2/stress",
73	"deqp/modules/gles2/usecases",
74	"deqp/modules/gles3/accuracy",
75	"deqp/modules/gles3/functional",
76	"deqp/modules/gles3/stress",
77	"deqp/modules/gles3/usecases",
78	"deqp/modules/gles3/performance",
79	"deqp/modules/gles31/functional",
80	"deqp/modules/gles31/stress",
81	"deqp/modules/gl3/functional",
82	"deqp/modules/gl3/performance",
83	"deqp/modules/gl3/stress",
84	"deqp/framework/opengl/simplereference",
85	"deqp/framework/opencl/inc",
86	"deqp/framework/opengl/wrapper",
87	"deqp/framework/opengl/simplereference",
88
89	"gapir/base",
90	"gapir/egl",
91	"gapir/gles2",
92	"gapir/util",
93
94	"domeni/eigen2",
95	"domeni/base",
96	"domeni/engine",
97	"domeni/m3g",
98	"domeni/m3g_adapter",
99	"domeni/renderer",
100	"domeni/resource",
101	"domeni/tools"
102] + SRC_DIRS
103
104ARGS = [
105	"--enable=all,style",
106	"--xml-version=2",
107	"--platform=win64",
108	"-D__cplusplus",
109	"-D_M_X64",
110	"-D_WIN32",
111	"-D_MSC_VER=1600",
112	"-DDE_DEBUG=1",
113	"-DDE_COMPILER=1", # Is preprocessor buggy in recent cppcheck?
114	"-DDE_OS=1",
115	"-DDE_CPU=1",
116	"-DDE_PTR_SIZE=4",
117	"-DAB_COMPILER=1",
118	"-DAB_OS=1",
119	"-DDEQP_TARGET_NAME=\"Cppcheck\"",
120	"-D_XOPEN_SOURCE=600",
121	"--suppress=arrayIndexOutOfBounds:deqp/framework/common/tcuVector.hpp",
122	"--suppress=invalidPointerCast:deqp/framework/common/tcuTexture.cpp",
123	"--suppress=*:deqp/framework/opencl/cl.hpp",
124	"--suppress=invalidPointerCast:deqp/modules/opencl/tclSIRLogger.cpp",
125	"--suppress=preprocessorErrorDirective:deqp/framework/platform/android/tcuAndroidMain.cpp",
126	"--suppress=invalidPointerCast:deqp/modules/gles3/functional/es3fTransformFeedbackTests.cpp",
127	"--suppress=invalidPointerCast:deqp/modules/gles3/functional/es3fUniformBlockCase.cpp",
128	"--suppress=unusedStructMember",
129	"--suppress=postfixOperator",
130	"--suppress=unusedFunction",
131	"--suppress=unusedPrivateFunction",
132	"--rule-file=deqp/scripts/no_empty_fail.rule"
133]
134
135def runCppCheck (srcBaseDir, dstFile):
136	fullDstFile	= os.path.realpath(dstFile)
137	command		= '"C:\\Program Files (x86)\\Cppcheck\\cppcheck.exe"'
138
139	for arg in ARGS + ["--xml"]:
140		command += " %s" % arg
141
142	for path in INCLUDE_DIRS:
143		command += " -I %s" % path
144
145	for path in SRC_DIRS:
146		command += " %s" % path
147
148	command += ' 2> "%s"' % fullDstFile
149
150	os.chdir(srcBaseDir)
151	os.system('"%s"' % command) # Double-quotes needed for some reason
152
153if __name__ == "__main__":
154	if len(sys.argv) != 2:
155		print "%s: [reportfile]" % sys.argv[0]
156		sys.exit(-1)
157
158	dstFile	= sys.argv[1]
159	srcDir	= os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
160	runCppCheck(srcDir, dstFile)
161