x11: Fix deadlock am: 5e863331b2 am: f49e8bfc0e am: 1eb4f43dc4 am: c1c16c73e6
[platform/upstream/VK-GL-CTS.git] / scripts / check_build_sanity.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2016 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 argparse
25 import tempfile
26
27 from build.common import *
28 from build.build import *
29
30 class Environment:
31         def __init__ (self, srcDir, tmpDir):
32                 self.srcDir     = srcDir
33                 self.tmpDir     = tmpDir
34
35 class BuildTestStep:
36         def getName (self):
37                 return "<unknown>"
38
39         def isAvailable (self, env):
40                 return True
41
42         def run (self, env):
43                 raise Exception("Not implemented")
44
45 class RunScript(BuildTestStep):
46         def __init__ (self, scriptPath):
47                 self.scriptPath = scriptPath
48
49         def getName (self):
50                 return self.scriptPath
51
52         def run (self, env):
53                 execute(["python", os.path.join(env.srcDir, self.scriptPath)])
54
55 def makeCflagsArgs (cflags):
56         cflagsStr = " ".join(cflags)
57         return ["-DCMAKE_C_FLAGS=%s" % cflagsStr, "-DCMAKE_CXX_FLAGS=%s" % cflagsStr]
58
59 def makeBuildArgs (target, cc, cpp, cflags):
60         return ["-DDEQP_TARGET=%s" % target, "-DCMAKE_C_COMPILER=%s" % cc, "-DCMAKE_CXX_COMPILER=%s" % cpp] + makeCflagsArgs(cflags)
61
62 class BuildConfigGen:
63         def isAvailable (self, env):
64                 return True
65
66 class UnixConfig(BuildConfigGen):
67         def __init__ (self, target, buildType, cc, cpp, cflags):
68                 self.target             = target
69                 self.buildType  = buildType
70                 self.cc                 = cc
71                 self.cpp                = cpp
72                 self.cflags             = cflags
73
74         def isAvailable (self, env):
75                 return which(self.cc) != None and which(self.cpp) != None
76
77         def getBuildConfig (self, env, buildDir):
78                 args = makeBuildArgs(self.target, self.cc, self.cpp, self.cflags)
79                 return BuildConfig(buildDir, self.buildType, args, env.srcDir)
80
81 class VSConfig(BuildConfigGen):
82         def __init__ (self, buildType):
83                 self.buildType = buildType
84
85         def getBuildConfig (self, env, buildDir):
86                 args = ["-DCMAKE_C_FLAGS=/WX -DCMAKE_CXX_FLAGS=/WX"]
87                 return BuildConfig(buildDir, self.buildType, args, env.srcDir)
88
89 class Build(BuildTestStep):
90         def __init__ (self, buildDir, configGen, generator):
91                 self.buildDir   = buildDir
92                 self.configGen  = configGen
93                 self.generator  = generator
94
95         def getName (self):
96                 return self.buildDir
97
98         def isAvailable (self, env):
99                 return self.configGen.isAvailable(env) and self.generator != None and self.generator.isAvailable()
100
101         def run (self, env):
102                 # specialize config for env
103                 buildDir        = os.path.join(env.tmpDir, self.buildDir)
104                 curConfig       = self.configGen.getBuildConfig(env, buildDir)
105
106                 build(curConfig, self.generator)
107
108 class CheckSrcChanges(BuildTestStep):
109         def getName (self):
110                 return "check for changes"
111
112         def run (self, env):
113                 pushWorkingDir(env.srcDir)
114                 execute(["git", "diff", "--exit-code"])
115                 popWorkingDir()
116
117 def getClangVersion ():
118         knownVersions = ["4.0", "3.9", "3.8", "3.7", "3.6", "3.5"]
119         for version in knownVersions:
120                 if which("clang-" + version) != None:
121                         return "-" + version
122         return ""
123
124 COMMON_GCC_CFLAGS       = ["-Werror"]
125 COMMON_CLANG_CFLAGS     = COMMON_GCC_CFLAGS + ["-Wno-error=unused-command-line-argument"]
126 GCC_32BIT_CFLAGS        = COMMON_GCC_CFLAGS + ["-m32"]
127 CLANG_32BIT_CFLAGS      = COMMON_CLANG_CFLAGS + ["-m32"]
128 GCC_64BIT_CFLAGS        = COMMON_GCC_CFLAGS + ["-m64"]
129 CLANG_64BIT_CFLAGS      = COMMON_CLANG_CFLAGS + ["-m64"]
130 CLANG_VERSION           = getClangVersion()
131
132 STEPS = [
133         RunScript(os.path.join("external", "fetch_sources.py")),
134         Build("clang-64-debug",
135                   UnixConfig("null",
136                                          "Debug",
137                                          "clang" + CLANG_VERSION,
138                                          "clang++" + CLANG_VERSION,
139                                          CLANG_64BIT_CFLAGS),
140                   ANY_UNIX_GENERATOR),
141         Build("gcc-32-debug",
142                   UnixConfig("null",
143                                          "Debug",
144                                          "gcc",
145                                          "g++",
146                                          GCC_32BIT_CFLAGS),
147                   ANY_UNIX_GENERATOR),
148         Build("gcc-64-release",
149                   UnixConfig("null",
150                                          "Release",
151                                          "gcc",
152                                          "g++",
153                                          GCC_64BIT_CFLAGS),
154                   ANY_UNIX_GENERATOR),
155         Build("vs-64-debug",
156                   VSConfig("Debug"),
157                   ANY_VS_X64_GENERATOR),
158         RunScript(os.path.join("scripts", "build_android_mustpass.py")),
159         RunScript(os.path.join("external", "vulkancts", "scripts", "build_mustpass.py")),
160         RunScript(os.path.join("scripts", "gen_egl.py")),
161         RunScript(os.path.join("scripts", "opengl", "gen_all.py")),
162         RunScript(os.path.join("scripts", "src_util", "check_all.py")),
163         RunScript(os.path.join("external", "vulkancts", "scripts", "gen_framework.py")),
164         CheckSrcChanges(),
165 ]
166
167 def parseArgs ():
168         parser = argparse.ArgumentParser(description = "Build and test source",
169                                                                          formatter_class=argparse.ArgumentDefaultsHelpFormatter)
170
171         parser.add_argument("-s",
172                                                 "--src-dir",
173                                                 dest="srcDir",
174                                                 default=DEQP_DIR,
175                                                 help="Source directory")
176         parser.add_argument("-t",
177                                                 "--tmp-dir",
178                                                 dest="tmpDir",
179                                                 default=os.path.join(tempfile.gettempdir(), "deqp-build-test"),
180                                                 help="Temporary directory")
181         return parser.parse_args()
182
183 if __name__ == "__main__":
184         args    = parseArgs()
185         env             = Environment(args.srcDir, args.tmpDir)
186
187         for step in STEPS:
188                 if step.isAvailable(env):
189                         print "Run: %s" % step.getName()
190                         step.run(env)
191                 else:
192                         print "Skip: %s" % step.getName()
193
194         print "All steps completed successfully"