1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 #-------------------------------------------------------------------------
27 import multiprocessing
29 from common import which, DEQP_DIR
37 def __init__ (self, buildDir, buildType, args, srcPath = DEQP_DIR):
38 self.srcPath = srcPath
39 self.buildDir = buildDir
40 self.buildType = buildType
41 self.args = copy.copy(args)
43 def getSrcPath (self):
46 def getBuildDir (self):
49 def getBuildType (self):
56 def __init__ (self, name, isMultiConfig = False, extraBuildArgs = []):
58 self.isMultiConfig = isMultiConfig
59 self.extraBuildArgs = copy.copy(extraBuildArgs)
64 def getGenerateArgs (self, buildType):
65 args = ['-G', self.name]
66 if not self.isMultiConfig:
67 args.append('-DCMAKE_BUILD_TYPE=%s' % buildType)
70 def getBuildArgs (self, buildType):
72 if self.isMultiConfig:
73 args += ['--config', buildType]
74 if len(self.extraBuildArgs) > 0:
75 args += ['--'] + self.extraBuildArgs
78 def getBinaryPath (self, buildType, basePath):
81 class UnixMakefileGenerator(CMakeGenerator):
83 CMakeGenerator.__init__(self, "Unix Makefiles", extraBuildArgs = ["-j%d" % multiprocessing.cpu_count()])
85 def isAvailable (self):
86 return which('make') != None
88 class NinjaGenerator(CMakeGenerator):
90 CMakeGenerator.__init__(self, "Ninja")
92 def isAvailable (self):
93 return which('ninja') != None
95 class VSProjectGenerator(CMakeGenerator):
99 def __init__(self, version, arch):
100 name = "Visual Studio %d" % version
101 if arch == self.ARCH_64BIT:
104 CMakeGenerator.__init__(self, name, isMultiConfig = True, extraBuildArgs = ['/m'])
105 self.version = version
108 def getBinaryPath (self, buildType, basePath):
109 return os.path.join(os.path.dirname(basePath), buildType, os.path.basename(basePath) + ".exe")
112 def getNativeArch ():
113 arch = platform.machine().lower()
116 return VSProjectGenerator.ARCH_32BIT
117 elif arch == 'amd64':
118 return VSProjectGenerator.ARCH_64BIT
120 raise Exception("Unhandled arch '%s'" % arch)
123 def registryKeyAvailable (root, arch, name):
125 key = _winreg.OpenKey(root, name, 0, _winreg.KEY_READ | arch)
126 _winreg.CloseKey(key)
131 def isAvailable (self):
132 if sys.platform == 'win32' and _winreg != None:
133 nativeArch = VSProjectGenerator.getNativeArch()
134 if nativeArch == self.ARCH_32BIT and self.arch == self.ARCH_64BIT:
137 arch = _winreg.KEY_WOW64_32KEY if nativeArch == self.ARCH_64BIT else 0
139 10: [(_winreg.HKEY_CLASSES_ROOT, "VisualStudio.DTE.10.0"), (_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\VCExpress\\10.0")],
140 11: [(_winreg.HKEY_CLASSES_ROOT, "VisualStudio.DTE.11.0"), (_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\VCExpress\\11.0")],
141 12: [(_winreg.HKEY_CLASSES_ROOT, "VisualStudio.DTE.12.0"), (_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\VCExpress\\12.0")],
142 14: [(_winreg.HKEY_CLASSES_ROOT, "VisualStudio.DTE.14.0"), (_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\VCExpress\\14.0")],
145 if not self.version in keyMap:
146 raise Exception("Unsupported VS version %d" % self.version)
148 keys = keyMap[self.version]
149 for root, name in keys:
150 if VSProjectGenerator.registryKeyAvailable(root, arch, name):
156 # Pre-defined generators
158 MAKEFILE_GENERATOR = UnixMakefileGenerator()
159 NINJA_GENERATOR = NinjaGenerator()
160 VS2010_X32_GENERATOR = VSProjectGenerator(10, VSProjectGenerator.ARCH_32BIT)
161 VS2010_X64_GENERATOR = VSProjectGenerator(10, VSProjectGenerator.ARCH_64BIT)
162 VS2012_X32_GENERATOR = VSProjectGenerator(11, VSProjectGenerator.ARCH_32BIT)
163 VS2012_X64_GENERATOR = VSProjectGenerator(11, VSProjectGenerator.ARCH_64BIT)
164 VS2013_X32_GENERATOR = VSProjectGenerator(12, VSProjectGenerator.ARCH_32BIT)
165 VS2013_X64_GENERATOR = VSProjectGenerator(12, VSProjectGenerator.ARCH_64BIT)
166 VS2015_X32_GENERATOR = VSProjectGenerator(14, VSProjectGenerator.ARCH_32BIT)
167 VS2015_X64_GENERATOR = VSProjectGenerator(14, VSProjectGenerator.ARCH_64BIT)
169 def selectFirstAvailableGenerator (generators):
170 for generator in generators:
171 if generator.isAvailable():
175 ANY_VS_X32_GENERATOR = selectFirstAvailableGenerator([
176 VS2015_X32_GENERATOR,
177 VS2013_X32_GENERATOR,
178 VS2012_X32_GENERATOR,
179 VS2010_X32_GENERATOR,
181 ANY_VS_X64_GENERATOR = selectFirstAvailableGenerator([
182 VS2015_X64_GENERATOR,
183 VS2013_X64_GENERATOR,
184 VS2012_X64_GENERATOR,
185 VS2010_X64_GENERATOR,
187 ANY_UNIX_GENERATOR = selectFirstAvailableGenerator([
191 ANY_GENERATOR = selectFirstAvailableGenerator([
192 VS2015_X64_GENERATOR,
193 VS2015_X32_GENERATOR,
194 VS2013_X64_GENERATOR,
195 VS2012_X64_GENERATOR,
196 VS2010_X64_GENERATOR,
197 VS2013_X32_GENERATOR,
198 VS2012_X32_GENERATOR,
199 VS2010_X32_GENERATOR,