Merge "Add copyright banner to scripts."
[platform/upstream/VK-GL-CTS.git] / scripts / cppcheck.py
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
23 import os
24 import sys
25 import shlex
26 import subprocess
27
28 SRC_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
62 INCLUDE_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
104 ARGS = [
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_SUPPORT_GLES2=1",
120         "-DDEQP_SUPPORT_GLES3=1",
121         "-DDEQP_SUPPORT_OPENCL=1",
122         "-DDEQP_SUPPORT_OPENGL=1",
123         "-DDEQP_TARGET_NAME=\"Cppcheck\"",
124         "-D_XOPEN_SOURCE=600",
125         "--suppress=arrayIndexOutOfBounds:deqp/framework/common/tcuVector.hpp",
126         "--suppress=invalidPointerCast:deqp/framework/common/tcuTexture.cpp",
127         "--suppress=*:deqp/framework/opencl/cl.hpp",
128         "--suppress=invalidPointerCast:deqp/modules/opencl/tclSIRLogger.cpp",
129         "--suppress=preprocessorErrorDirective:deqp/framework/platform/android/tcuAndroidMain.cpp",
130         "--suppress=invalidPointerCast:deqp/modules/gles3/functional/es3fTransformFeedbackTests.cpp",
131         "--suppress=invalidPointerCast:deqp/modules/gles3/functional/es3fUniformBlockCase.cpp",
132         "--suppress=unusedStructMember",
133         "--suppress=postfixOperator",
134         "--suppress=unusedFunction",
135         "--suppress=unusedPrivateFunction",
136         "--rule-file=deqp/scripts/no_empty_fail.rule"
137 ]
138
139 def runCppCheck (srcBaseDir, dstFile):
140         fullDstFile     = os.path.realpath(dstFile)
141         command         = '"C:\\Program Files (x86)\\Cppcheck\\cppcheck.exe"'
142
143         for arg in ARGS + ["--xml"]:
144                 command += " %s" % arg
145
146         for path in INCLUDE_DIRS:
147                 command += " -I %s" % path
148
149         for path in SRC_DIRS:
150                 command += " %s" % path
151
152         command += ' 2> "%s"' % fullDstFile
153
154         os.chdir(srcBaseDir)
155         os.system('"%s"' % command) # Double-quotes needed for some reason
156
157 if __name__ == "__main__":
158         if len(sys.argv) != 2:
159                 print "%s: [reportfile]" % sys.argv[0]
160                 sys.exit(-1)
161
162         dstFile = sys.argv[1]
163         srcDir  = os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
164         runCppCheck(srcDir, dstFile)