3 # Copyright (c) 2016 The Khronos Group Inc.
4 # Copyright (c) 2016 Valve Corporation
5 # Copyright (c) 2016 LunarG, Inc.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # Author: Mark Young <marky@lunarg.com>
24 # Following function code snippet was found on StackOverflow (with a change to lower
25 # camel-case on the variable names):
26 # http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
27 def find_executable(program):
29 return os.path.isfile(fPath) and os.access(fPath, os.X_OK)
31 fPath, fName = os.path.split(program)
36 for path in os.environ["PATH"].split(os.pathsep):
37 path = path.strip('"')
38 exe_file = os.path.join(path, program)
44 def determine_year(version):
60 # Determine if msbuild is in the path, then call it to determine the version and parse
61 # it into a format we can use, which is "<version_num> <version_year>".
62 if __name__ == '__main__':
63 exeName = 'msbuild.exe'
64 versionCall = exeName + ' /ver'
66 # Determine if the executable exists in the path, this is critical.
68 foundExeName = find_executable(exeName)
70 # If not found, return an invalid number but in the appropriate format so it will
71 # fail if the program above tries to use it.
72 if foundExeName == None:
74 print('Executable ' + exeName + ' not found in PATH!')
76 sysCallOut = os.popen(versionCall).read()
80 # Split around any spaces first
81 spaceList = sysCallOut.split(' ')
82 for spaceString in spaceList:
84 # If we've already found it, bail.
88 # Now split around line feeds
89 lineList = spaceString.split('\n')
90 for curLine in lineList:
92 # If we've already found it, bail.
96 # We only want to continue if there's a period in the list
97 if '.' not in curLine:
100 # Get the first element and determine if it is a number, if so, we've
102 splitAroundPeriod = curLine.split('.')
103 if splitAroundPeriod[0].isdigit():
104 version = int (splitAroundPeriod[0])
107 # Failsafe to return a number in the proper format, but one that will fail.
111 # Determine the year associated with that version
112 year = determine_year(version)
114 # Output the string we need for Cmake to properly build for this version
115 print(str(version) + ' ' + str(year))